MediaPlayer change DataSource Error when MediaPlayer complets Playing First Audio

余生长醉 提交于 2019-12-02 20:04:21

问题


Any one Help for MediaPlayer Error. when aim is to Change DataSource and Play second Audio when First Audio is Compliting its Playing.

My Code is below :- mMediaPlayer.setOnCompletionListener(new OnCompletionListener() {

        @Override
        public void onCompletion(MediaPlayer arg0) 
        {

           String fileName = Environment.getExternalStorageDirectory().getAbsolutePath() + FILENAME+arrListSize+".wav";
           mMediaPlayer.release();
           mMediaPlayer = null;
           mMediaPlayer = new MediaPlayer();
           Uri uri  = Uri.parse("file://"+fileName);                                    mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
            try 
            {
              mMediaPlayer.setDataSource(getApplicationContext(), uri);
              mMediaPlayer.prepare();
            } 
            catch (Exception e) 
            {                       
                e.printStackTrace();
            }

Error :- setDataSource called in state 32

Thanks.


回答1:


From the error, it looks like the previous instance of the MediaPlayer is not released completely. When the playback has completed, the player is in Paused state when the onCompletionListener is invoked. Can you please stop the MediaPlayer before releasing the same?

mMediaPlayer.stop();
mMediaPlayer.release();
mMediaPlayer = NULL;
mMediaPlayer = new MediaPlayer();
...


来源:https://stackoverflow.com/questions/15152172/mediaplayer-change-datasource-error-when-mediaplayer-complets-playing-first-audi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!