iPhone MPMusicPlayerController playback starting position - iphone

I'm using Media Player Framework to access the user's music library on iPhone. I would like to set the playback starting position so that I can start playing a song from 30 second mark, for example.
I have trouble finding out how to do this. The MPMediaPlayerController only offers beginSeekingForward but that's not quite what I'm looking for as it simply accelerates the playback speed.
There is probably something really simple that I'm missing.

MPMusicPlayerController's property currentPlaybackTime is a writeable property, so adjusting the playback starting point can be done with player.currentPlaybackTime = 30.0

You can use player.currentPlaybackTime to set the time, before you start playing and playback will start at your desired point.

UPDATE
2009 me had some real problems. He didn't really understand properties and missed the fact that MPMusicPlayerController.currentPlaybackTime is writable! And he was angry. Angry because iOS3.0 had promised iPod Library "Access" and instead delivered MPMusicPlayerController. He had been hoping for speedy access to the music packet data upon which he would have built many fascinating and magical audio applications. Luckily, iOS4.1's AVAssetReader came along 1 year later and he was finally able to stop hating.
WRONG 2009 ANSWER
Nope, this API is deliberately crippled, which is why you don't see any functions for
opening, or streaming from, the media file.
Your only hope is lowering the volume and calling beginSeekingForward until currentPlaybackTime returns >= 30s.
Enjoy!

Related

NStimer and Dispatchqueue starts a little late when using the airpot

My app provides voice to AVPlayer and gives a little term using Timer in the middle of playback so that users can read along.
It works well on simulators and real devices.
However, when you pair the air pot, the timer starts about 0.2 seconds late.
Why does this happen and how can I fix it?
I used 'Timer.scheduler' and 'Dispatchqueue.Main.asyncAfter', but both had the same symptoms.
I gather that you are starting playback and simultaneously starting a timer, but when you do this with Bluetooth earphones, that they don’t seem in sync. If that’s the case, I might suggest not using your own timer, but rather let the AVPlayer tell you where it is.
For example, you might use addPeriodicTimeObserver(forInterval:queue:using:). The AVPlayer tell you when it got to a particular point in the playback.

Is there a way of changing playback position using AudioKit / AKPlayer?

Been scratching my head with this one, to no avail.
Am just trying to find out how to instantly change the current playback position when using the AKAudioPlayer provided by AudioKit.
player.playhead is read-only, so cant be changed.
changing player.startTime whilst the player is already playing seems to change the playback position in terms of the reported .playhead position but the actual audio being played does not change position - am I missing something here?
Obviously I can stop audio and restart at new position but a several second expensive CPU gap is not desirable for a a simple mp3 / wav file player!
Any ideas?
We've added a new player called AKPlayer which will also allow scanning through the file. The player will stream from disk by default. This player is designed to fix some of the shortcomings in AKAudioPlayer.
OK Aurelius pointed me in the right direction of a new class introduced a couple weeks ago called AKClipPlayer
Like the standard Apple AV class you can now set the .currentTime property (in seconds) (the AKAudioPlayer class did not allow this) - it seems to stop playback doing this though so don't forget to .play() your node right after - there is no glitch or pause, is seamless on an old iPhone6S

Play just a part of the sound (both in and out) with OpenAL (iOS)?

I have a recording that has some unuseful voices at the beginning, and at the end.
How can I play just the middle part of the sound?
I have AL_SEC_OFFSET, that is suitable for the entry point, I already use it, but what about the endpoint?
Is there any smart OpenAL settings for this? Hopeso.
Thanks.
There could be a workaround that fires a timer that stops playing before end.
Any simplier?
OpenAL doesn't have built-in support for stopping playback at a specific sample point. A timer is your best bet in this case, even though it will be somewhat inaccurate.
If you want sample-perfect stopping, you could just load the middle part of the audio file into an ALBuffer rather than the entire thing. I have some code which does that here:
https://github.com/kstenerud/ObjectAL-for-iPhone/blob/master/ObjectAL/ObjectAL/Support/OALAudioFile.m#L188

AudioServices (Easy), AVAudioPlayer (Medium), OpenAL (Hard & Overkill?)

I need to play sounds (~5 seconds each) throughout my iphone application. When they're triggered, they need to play immediately.
For the moment I'm using AudioServices and (as you probably know) the first time you play a sound it lags, then every time there after it's perfect. Is there some code available that's clever enough to preload an AudioServices sound (by playing it silently maybe?). I've read adjusting the system volume programmatically will get your app rejected, so that's not an option. Seems AudioServices isn't made for volume correction from what I can see.
I've looked into OpenAL and while feasible seems a little over kill. AVAudioPlayer seems like a little bit of a better option, I'm using that for background music at present. Extending my music player to handle a 'sound board' might be my last resort.
On the topic of OpenAL, does anyone know of a place with a decent (app store friendly) OpenAL wrapper for the iPhone?
Thanks in advance
Finch could be perfect for you. It’s a tiny wrapper around OpenAL with very low latency and simple API. See also all SO questions tagged ‘Finch’.
If you use an AVAudioPlayer, you can call prepareToPlay when you initialize the object to reduce the delay between calling play and having the audio start.

MPMovie player how to get the amount of time played?

I was trying to go through the iPhone's sample code for mediaplayer.
I want to be able to capture the amount of time the media player has played the video. The duration at which the media player has stopped. Is there a method or property that will tell me the duration of play of the media??
Unfortunately the current API for MPMoviePlayerController allows basically no control. You can tell it to play and stop... otherwise where's a delegate method so you can be notified when the movie finishes playing and that's it, there's no additional controls. (a real bummer)
However, while we cant discuss the new 3.2 SDK yet, I'll give you a tip and say go look at the documentation of MPMoviePlayer in 3.2 and I think you'll be happy.
http://developer.apple.com/iphone/prerelease/library/documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/MPMoviePlayerController/MPMoviePlayerController.html
moviePlayer.currentPlaybackTime
It's not possible to do KVO on it but you could do like me and create an scheduledTimer which updates every second to check what the current playbacktime is and update your graphics accordingly :)
Yes, You can use the property "duration" defined by MPMediaPlayerController. Plese try it out and check the output. U can refer the here duration property