Can you programmatically detect a change in MPMoviePlayerController currentPlaybackTime - ios

I've written custom control which allows the user to change the currentPlaybackTime of a MPMoviePlayerController by clicking or dragging on a custom UIButton that displays an image of some musical notation. The code uses the x position of the touch event to update currentPlaybackTime and it all works fine. I also have a CALayer (a vertical red line) that shows the user where they have touched on the control.
What I'd like to do now is have the red line's (CALayer object) position update if the user changes the currentPlaybackTime property of the movie player using the scrubber (slider) control.
Obviously currentPlaybackTime is always updating as the movie plays, but is there a way to detect if the user interferes with this by skipping forward or backwards?
Many thanks.

You could use Key-Value-Observing to track changes of currentPlaybackTime in your MPMoviePlayerController, but that might generate a lot of events and thus negatively affect your performance. Maybe you can also use KVO with the playbackState property of your MPMoviePlayerController, I believe it changes when the user starts seeking.
Another alternative is that you just setup a repeating timer that updates quite frequently, and everytime it fires you check the new value of currentPlaybackTime. But that might look choppy and it could also affect performance.

Related

AVPlayer smooth seekToTime

Is where a way to smoothly seek playback to some position?
In other words, imagine that some track playing at 0:53 and I need it to play at 0:58 after 2 seconds. So I need it to smoothly increase rate (like using easing functions in animation) and smoothly decrease rate when playback time almost equal 0:58. (it should sound like rewind effect)
Simple seekToTime method is not an option since it just jumps to position.
Here is an illustration:
two________________________seconds_________________________to_seek
0:53__________________________________________________________0:58
|____________↑_________|__________=_________|__________↓__________|
rate=1______smoothly_rate=2.0_______________smoothly_rate=1_____rate=1
I've already tried to use easing methods to smoothly increase rate but looks like it's impossible - rate value changes right away to desired value without easing.
At least I know that it is actually possible. You can try Ampme app from Appstore. They're playing music synchronously on different devices and if there is some lag (buffering, etc) on one of the devices, it's playback smoothly corrects to right value without jumping.
Currently I'm using setRate:time:atHostTime: method and I think it's the right way, but I'm not able to make it work seeking smoothly.

iOS control Animation or Video via swiping

Is it possible to control an animation or better a video via swiping over it?
I have:
an animation as video (~2sec playtime, can be converted to other file types if needed, but shouldn't be too big)
iOS >= 6.0
I want:
show the first frame of the animation
play the animation back and forward if the user moves his finger tip over the control with a speed, corresponding to the speed of the finger tip.
I'm experimenting with MPMoviePlayerController currently. Are there better Controls? Do you have any suggestions to solve this problem?

Dim volume of iPodMusicPlayer to 50% in iOS

I know that you can easily set the volume property of the music player, but I want to do it smoothly like Google Maps does when they use the voiceover for navigation instructions.
I was wondering what the best way to do this is.
Thanks!
I would try using a repeating NSTimer. Every time the timer fires you lower the volume a bit. When it reaches the target value you invalidate the timer.
Other ways of getting a repeated event (so that you can do something in stages gradually over time) are DISPATCH_SOURCE_TYPE_TIMER and CADisplayLink. But I think a timer is probably the simplest way to get started.
If you have a pre-existing sound that you're playing, a completely different solution is to apply a fadeout to it before you start playing it (and then just play it all at the same volume, because the sound itself fades out, do you see). AVFoundation gives you the tools to do that (e.g. setVolumeRampFromStartVolume:toEndVolume:timeRange:).

issue with seeking forward/backward using MPMoviePlayerController in iOS4

I have a weird issue with the MPMoviePlayerController in iOS.
I have a MPMoviePlayerController with control style none.
Added my own UISlider to seek forward/backward in the movie.
Set up notifications to see a change in the playback state.
After setting player.currentPlaybackTime to a new value the playbackstate goes to MPMoviePlaybackStateSeekingForward or MPMoviePlaybackStateSeekingBackward and stays in that state.
I would expect that when the seeking stops (new position found), and the player continues to play normally the playbackstate would go back to MPMoviePlaybachStatePlaying but it doesn't.
Is this normal behaviour or am I missing something?
The problem is with UISlider's property continuous. Set it to no and you will be notified when the state will change from Forward/Backward to Playing.
self.playerControlsView.slider.continuous = NO;
The issue i guess is that when the continuous property is set to YES. The slider will continue the action of sliding the user is providing it and not trigger the state change. And hence the state remains forward/backward. I am not very sure about this but the answer is somewhere on these lines.
Hope this helps someone :)

MPMoviePlayerController, disallow fullscreen but allow navigation through clip?

I have a video in my iPad app, but I dont want it to be able to go to fullscreen. However I do potentially want the user to be able to navigate to the part of the video that they want to see.
As far as I can tell there are only three options for the controls that you give the user:
None, Embedded, or Fullscreen.
None gives the user no control.
Embedded and Fullscreen basically give the use the same amount of control but just start in different states.
Basically what I want is Embedded with the switch to Fullscreen option taken out.
Anybody know if its possible? Thanks
You can set the controls style to "None", and then add your own custom view to navigate using a UISlider (I've done this in the past).
MPMoviePlayerController adheres to the MPMediaPlayback protocol, so you take the total playback time of the movie, multiply it by the UISlider value (when it changes), and then adjust the movie's playback head position.
You'll also need an NSTimer or KVO to monitor the playback time so it can update the slider UI element in realtime.

Resources