I have an app that I want to be able to pause and resume the current playing song. The only way I've found so far is this:
[[MPMusicPlayerController systemMusicPlayer] pause];
// some time passes
[[MPMusicPlayerController systemMusicPlayer] play];
The problem is that if it's a 3rd party app that is playing, like Spotify, it seems to lose focus to the iOS Music.app when I do this. So when I try to resume with [ play], the last played song in Music.app starts playing.
Is there a way to pause and resume Spotify (or whatever app was playing) without losing focus to the Music.app? Aka, the exact same behaviour as pressing play/pause in iOS Action Center
There's sadly no way to do this (with public API that is, there are private API's but if you want to go in the AppStore you can't use them).
Related
So I have an app built with a player that plays a video, I have a [player pause] and [player play] in the didBecomeActive and willResignActive methods. Most of the time works fine, but when I open the app, and press the home button and repeat again that process, around the 8th time the video will not play even though I see the play method getting called.
Does anyone have any idea what might be going on?
The app can be in several states that are not foreground. Before playing, check to see if you still have a player, that it still has a player.currentItem, and if it's status is AVPlayerStatusReadyToPlay.
If any of those conditions are not met, then the player and the item must be reinitialized using the code that you used to create it in the first place.
This is a good candidate for a lazy initializer for your player property.
I'm making an app that will play audiobooks synced with iTunes. Is there a way my player can remember the playback position? Or do I need to implement this myself with some sort of database?
I'm testing on iOS 8.4
The key is to set the current playback time to the bookmark time of the mpmediaitem before playing.
Here's an example:
[self.player setQueueWithItemCollection:self.collection];
self.player.currentPlaybackTime = [self.collection.items[0] bookmarkTime];
[self.player play];
An audiobook file will automatically remember its playback position, and when asked to play again later, will resume from that position - that is a built-in feature of the Music app (now iBooks) and therefore of the MPMusicPlayerController.
However, you will notice that the Music app can lose track of the currently playing item (if the user restarts the device). And of course the user might change the currently playing item manually.
Thus, if you want your app to return to what it was playing previously, you will have to save that currently playing item information yourself. And so you might as well save the current playback position too, thus making yourself even more reliable than the Music app.
I have added music to my app so the music plays as soon as the app starts through the app delegate.
Now I have a switch in my app that I would like to rig up to where when it is switched off, the music stops playing, and when its switched back on, it resumes playing. Only problem is I don't know how to do this.
I know that I would need to make an IBAction and rig it to my switch but I am new to iOS Development and I learn best by being told how to do something and then applying it and seeing how it works in real time.
It would be great if someone could provide the code so I can throw it into my project and see how it works and learn from this.
Thanks.
When you pressing Mute button first check audioplayer is playing or not for exa.
if([avAudio isPlaying])
{
[avAudio pause];//OR[avAudio stop];
}
else
{
[avAudio play];
}
I think what I'm looking for is the combination of existing settings that I can't quite put together in the right order. I have an app that plays sound clips using AVAudioPlayer. There is a start/stop button.
I would like any other apps' audio to continue until my app actually needs to play something.
When my app is launched with some iTunes music playing, that music continues correctly. When I press play in my app, the other audio correctly stops, and my app plays. I stop my player, switch back to the music app, and press play again. But now when I switch back to my own app, the music stops immediately.
I would like it to again wait until it needs to play something before killing the music app.
My best guess is that once I've used the player, it is in some kind of 'I need audio' state, and remains in that state. How do I resign this state?
I am working on an app that needs to pause and unpause the audio stream coming from the ipod app. Is there any way to do that? I want to make a button that once you press it, it pauses the currently playing song on the ipod app. Pressing it again unpauses where the music left off. I am also working on a way to change the volume of the ipod app, is there anyway to do this that does not rely on the user manually moving a slider?
Any help at all would be great. Thanks!
you could use this framework if you want: Media Player Framework
Specially the MPMusicPlayerController Class
You have this:
Controlling Playback
– play
– pause
– stop
Managing Playback Mode and State
volume ( property )