Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android MediaPlayer.getCurrentPosition not updating

I have followed Igor Khrupin's tutorial on streaming mp3 files in Android using the MediaPlayer class: http://www.hrupin.com/2011/02/example-of-streaming-mp3-mediafile-with-android-mediaplayer-class

This is all working fine except that the primary progress of the seek bar is not updating correctly. It stops just after the beginning. On debugging this, I can see that the MediaPlayer.getCurrentPosition() method is always returning 261 (milliseconds) even though the mp3 song is playing fine.

Has anyone come across this issue before or got any ideas on how to fix it?

Many thanks

like image 534
winstar Avatar asked Nov 13 '22 18:11

winstar


1 Answers

I also had the same problem. I solved the problem by determining the type of stream using the setAudioStreamType(int) method:

Uri myUri = ....; // initialize Uri here
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(getApplicationContext(), myUri);
mediaPlayer.prepare();
mediaPlayer.start();
like image 173
mohammad salari Avatar answered Dec 18 '22 13:12

mohammad salari