Avatar of svetoslavm
svetoslavm
Flag for Canada asked on

android mediaplayer get progress info

Hi,

I am working on a media player for android.
I know that a thread should constantly run in order to take the current position of the audio.

String file = audioFile.getAbsolutePath();
 
 mp.reset(); 
 mp.setDataSource(file); 
 mp.prepare();
 
 if (last_pos > 0) {
	 mp.seekTo(last_pos);
 }

 // the media could be just prepared.
 if (media.isAutoPlay()) {
	 mp.start();
 }
 
 mp.setOnPreparedListener(new OnPreparedListener() {
	@Override
	public void onPrepared(final MediaPlayer mp) {
		mHandler.post(new Runnable() {
			@Override
			public void run() {
				int position;
				int duration = mp.getDuration();
				
				do {
					try {
						info.setText(app.getInfo());
						position = mp.getCurrentPosition();
						
						Thread.sleep(1000);
					} catch (Exception ex) { 
						break; 
					}
				} while (mp.isPlaying() && position <= duration); 
			}
		});
	}
});

Open in new window


any ideas?
AndroidSmartphonesSmartphone Programming

Avatar of undefined
Last Comment
Santhana

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Santhana

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23