MediaPlayer setOnPreparedListener doesn't get called for second time

China☆狼群 提交于 2019-12-13 04:08:10

问题


I am using listview adapter to displays list of tracks.Each list item has play and stop icons to play and stop track.The issue I am having is that track gets played only once when i first click on play button.After that if i stop it by clicking on stop button and the try to play any track it doesn't get played.Through toast message i found out that holder.img1.setOnClickListener() method does get called but onPrepared() method doesn't get called on clicking on play button for second time or after that..If i replace mMediaPlayer.pause(); by mMediaPlayer.release();still i get same result..If i put mMediaPlayer=new MediaPlayer();inside onClick() method of holder.img1.setOnClickListenerabove issue does get resolved but then clicking on multiple play buttons will start playing multiple tracks at same time which i don't want..


回答1:


Trying to help you is going to be a nightmare due to your naming conventions and lack of commenting. I would recommend that you change your naming convention so that people looking at your code have some idea as to what each of the variables are doing. Also small comments on can be very helpful when in understanding what it is you are trying to do.




回答2:


@Override
public void onPrepared(MediaPlayer mp)
{
    Toast.makeText(context,"prepatre",Toast.LENGTH_LONG).show();
    mMediaPlayer.start();

 }


来源:https://stackoverflow.com/questions/26947105/mediaplayer-setonpreparedlistener-doesnt-get-called-for-second-time

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