Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPMoviePlayer setCurrentPlaybackTime iOS

I use MPMoviePlayer to play my video, the problem I have is when the user press the home button of the device, I save the current position of the video, than when he lunch the application again I would like him to start from where he left, so I use setCurrentPlaybackTime function, it works perfectly in iOS 5 but not in iOS 5.1 where the video starts from the beginning.

Does any body have a solution for this kind of problem ?

like image 544
Abu Romaïssae Avatar asked May 14 '26 01:05

Abu Romaïssae


2 Answers

My problem is solved and I will explain what I've done so far.

When I couldn't find a solution/explanation of that behavior (which I find it strange) I start making lot and lot of logging, so what I noticed is when I log the current position I get always (in iOS 5.1)

  currentPlaybackTime = nan

but in iOS 5 I got a normal value as 0.00000

so I made a timer (which repeats itself) to log every time the current time, so I noticed that its changing from nan to 0.00000 after a while

The conclusion I made is that I need to wait a bit (don't understand why) before setting the PlaybackTime, and so it is, after waiting 1 ms (1/1000 s) and it works.

like image 104
Abu Romaïssae Avatar answered May 16 '26 22:05

Abu Romaïssae


Did you try using seekToTime (AvPlayer only) instead of setCurrentPlaybackTime?

as suggested here:
Why does MPMoviePlayerController setCurrentPlaybackTime goes to the wrong time?

Note: This solution is for AvPlayer rather than MPMoviePlayer (even tough it is not indicated in the listed link). But I would wait for additional answers before switching to AvPlayer.

like image 38
Bo. Avatar answered May 16 '26 22:05

Bo.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!