Intereting Posts

Android MediaPlayer Error (1, -38) и (-38, 0)

Я работаю с компонентом MediaPlayer, и получаю ошибки (1, -38) и (-38, 0). Я использую player.prepareAsync (), и я вызываю player.start () в методе onPrepared (). Любопытно, что я получаю ошибку, когда я воспроизвожу видео в четвертый раз. Я понятия не имею, что происходит. Кто-нибудь может мне помочь?

Это мой код:

public class VideoPlayerActivity extends Activity implements SurfaceHolder.Callback, MediaPlayer.OnPreparedListener, VideoControllerView.MediaPlayerControl, OnCompletionListener, OnErrorListener { SurfaceView videoSurface; MediaPlayer player; VideoControllerView controller; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.video_player); getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); if(player != null) { player.release(); player = null; } player = new MediaPlayer(); controller= new VideoControllerView(this); try { player.setAudioStreamType(AudioManager.STREAM_MUSIC); String path = getIntent().getStringExtra(Constants.PATH); player.setDataSource(path); player.setOnPreparedListener(this); player.setOnCompletionListener(this); player.setOnErrorListener(this); } catch(Exception e) { e.printStackTrace(); } videoSurface = (SurfaceView) findViewById(R.id.videoSurface); SurfaceHolder videoHolder = videoSurface.getHolder(); videoHolder.addCallback(this); player.prepareAsync(); } @Override protected void onStop() { super.onStop(); if(player != null) { player.stop(); } } @Override public boolean onMenuItemSelected(int featureId, MenuItem item) { switch (item.getItemId()) { case android.R.id.home: if(player != null) { player.stop(); } finish(); break; default: break; } return true; } @Override public boolean onTouchEvent(MotionEvent event) { controller.show(); return false; } @Override public void onPrepared(MediaPlayer mp) { controller.setMediaPlayer(this); controller.setAnchorView((FrameLayout) findViewById(R.id.videoSurfaceContainer)); player.start(); } } @Override public void surfaceCreated(SurfaceHolder holder) { player.setDisplay(holder); } @Override public void surfaceDestroyed(SurfaceHolder holder) { } @Override public void onCompletion(MediaPlayer mp) { if(!controller.isStopped()) { finish(); Intent intent = new Intent(getBaseContext(), MediaListActivity.class); String path = getIntent().getStringExtra(Constants.PATH); intent.putExtra(Constants.PATH, path.substring(0, path.lastIndexOf(Constants.SLASH))); startActivity(intent); } } @Override public boolean onError(MediaPlayer mp, int what, int extra) { if(what == 100 || what == 1 || what == -38) { player.stop(); player.release(); player = null; finish(); } return false; } 

И LogCat:

 02-23 12:00:39.184: E/MediaPlayer(31647): error (1, -38) 02-23 12:00:39.184: E/MediaPlayer(31647): Error (1,-38) 02-23 12:00:39.184: E/MediaPlayer(31647): stop called in state 0 02-23 12:00:39.184: E/MediaPlayer(31647): error (-38, 0) 

Solutions Collecting From Web of "Android MediaPlayer Error (1, -38) и (-38, 0)"