MediaPlayer错误(-38,0)

时间:2012-07-31 05:40:26

标签: android android-mediaplayer

每当我试图在另一个活动中停止媒体播放器而不是我获得无效状态异常时“尝试在错误状态下执行seekTo,错误(-38,0)”。请说明解决方案是什么?

媒体播放器活动:

@Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            setContentView(R.layout.media);

    Thread t = new Thread()
            {
                public void run() 
                {
                    while (isDownloading) 
                    {
                        if (Data.filenames != null && Data.filenames.size() >= (getIntent() .getExtras().getInt("index") + 1) && Data.filenames.get(getIntent().getExtras() .getInt("index")) != null) 
                        {
                            try 
                            {
                                mediaPlayer.setDataSource(Data.filenames.get(getIntent().getExtras().getInt("index")));
                                mediaPlayer.prepare();
                                mediaPlayer.start();
                                isplayed++;

                                new Thread(onEverySecond).start();
                                mediaPlayer.setOnCompletionListener(new OnCompletionListener() 
                                {
                                    @Override
                                    public void onCompletion(MediaPlayer mp) {
                                        mediaPlayer.seekTo(0);
                                        btnplay.setImageResource(R.drawable.play);
                                        index = 0;
                                    }
                                });
                                boolean isPlaying = mediaPlayer.isPlaying();
                                if(!isPlaying)
                                {
                                mediaPlayer.pause();
                                }                           
                            } catch (IllegalArgumentException e) {
                                e.printStackTrace();
                            } catch (IllegalStateException e) {
                                e.printStackTrace();
                            } catch (IOException e) {
                                e.printStackTrace();
                            } catch (Exception e) {
                                e.printStackTrace();
                            } finally {
                                isDownloading = false;
                            }
    }
    }t.start;

    }


Second Activity From where I am trying to stop media player:

    if (!(MediaPlay1.mediaPlayer == null)) {
      MediaPlay1.mediaPlayer.seekTo(MediaPlay1.mediaPlayer.getCurrentPosition());
      try {
        Thread.sleep(200);
      } catch (InterruptedException e) {
          e.printStackTrace();
       }
      MediaPlay1.mediaPlayer.stop();
      MediaPlay1.mediaPlayer.release();
      } else {
        Log.e("------", "------");
      }

      if (!(MediaPlay.mediaPlayer == null)) {
        MediaPlay.mediaPlayer.stop();
        MediaPlay.mediaPlayer.release();
       } else {
         Log.e("------", "------");
       }


Logcat:

MediaPlayer(11694):尝试在错误状态下执行seekTo:mPlayer = 0x2b8270,mCu​​rrentState = 0     MediaPlayer(11694):错误(-38,0)     MediaPlayer(11694):错误(-38,0)

0 个答案:

没有答案