MediaPlayer getCurrentPosition

All your problems with Audio, Video and Images.

MediaPlayer getCurrentPosition

Postby glenandroid » Wed Sep 22, 2010 11:37 pm

Hi,

I need to know the duration for which a user watched a video. In other words, I need know what the currentPosition was immediately before onCompletion() was invoked.

Is there any easy way to figure this out through the media APIs?

Cheers,
Glen
--> Yes. No. Maybe. I don't know. Can you repeat the question? <--
glenandroid
Junior Developer
Junior Developer
 
Posts: 16
Joined: Mon Mar 01, 2010 3:40 am
Location: Manchester England

Top

Re: MediaPlayer getCurrentPosition

Postby mrco » Thu Sep 23, 2010 10:27 am

glenandroid wrote:Hi,

I need to know the duration for which a user watched a video. In other words, I need know what the currentPosition was immediately before onCompletion() was invoked.

Is there any easy way to figure this out through the media APIs?

Cheers,
Glen

May be MediaPlayer.getDuration helps you.
mrco
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Fri Jan 15, 2010 11:31 am
Location: 2V Software

Re: MediaPlayer getCurrentPosition

Postby glenandroid » Thu Sep 23, 2010 11:01 am

Thanks for the response but It doesn't help in this case: getCurrentPosition () tells us the current playback position, getDuration() the duration of the file. But once onCompletion() is called I no longer get the values that I need.

I think to solve the problem we need a thread that is running at the same time as the MediaPlayer to periodically check the current position with getCurrentPosition().

But I was hoping for a much simpler solution such as the MediaPlayer reporting the final position of the playback.
--> Yes. No. Maybe. I don't know. Can you repeat the question? <--
glenandroid
Junior Developer
Junior Developer
 
Posts: 16
Joined: Mon Mar 01, 2010 3:40 am
Location: Manchester England

Re: MediaPlayer getCurrentPosition

Postby glenandroid » Thu Sep 23, 2010 3:25 pm

Scratch that I've decided to re-implement this code using a streaming solution Cheers.
--> Yes. No. Maybe. I don't know. Can you repeat the question? <--
glenandroid
Junior Developer
Junior Developer
 
Posts: 16
Joined: Mon Mar 01, 2010 3:40 am
Location: Manchester England

Re: MediaPlayer getCurrentPosition

Postby glenandroid » Sat Sep 25, 2010 5:39 pm

I did solve this in the end. The code was using a VideoView. It was possible to call getCurrentPosition from the activity's onPause method.
--> Yes. No. Maybe. I don't know. Can you repeat the question? <--
glenandroid
Junior Developer
Junior Developer
 
Posts: 16
Joined: Mon Mar 01, 2010 3:40 am
Location: Manchester England

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 9 guests