Now playing "play/pause" button image - ios

In the multimedia controls (in the multitasking UI) the "play" button always show the pause image even when the music is paused, everything works fine except this
this problem don't happen if the background audio comes from the Music App (i.e. the button image switch from play to pause and vice-versa as expected)
how to fix?
thanks

In my case, I had to pause all the AV-related items which were "playing":
[myAVAudioPlayer pause];
[myAVAudioRecorder pause];
[[MPMusicPlayerController applicationMusicPlayer] pause];
After which, the play/pause button on the lock screen switches, and the playhead also freezes. Inverse for play.

Change MPNowPlayingInfo dictionary, set new parameter
MPNowPlayingInfoPropertyPlaybackRate to 1.0f to show pause button
MPNowPlayingInfoPropertyPlaybackRate to 0.0f to show play button
see my answer how to use this code.

Related

Disabled play, next track, previous track buttons on now playing info on notification screen

Play, next track, previous track buttons gets disabled when I start play a music track after AVPlayerViewController finished showing video.
Reproduction steps:
start music track on AVPlayer
pause music track on AVPlayer
start showing video on AVPlayerViewController with different AVPlayer
close AVPlayerViewController
start (unpause) music track on AVPlayer
show notification screen
And I see that button are disabled.
I want to have enabled buttons rather than disabled. What do I do wrong?
After video is finished you should update nowPlayingInfo in MPNowPlayingInfoCenter

Resuming Spotify after pause on iOS

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).

How do I add a "Mute Sound" button in SpriteKit / Objective C?

I'm programming a little SpriteKit game and I want to add a mute button, so that you can hear your own music while playing my game. Currently I'm just stopping the audio playback for the scene the mute button is in (main menu). However my game still automatically stops the user music even if the audio playback is stopped. How can I prevent that?
Also, I'd like to pass the information that the mute button is pressed (located in the main menu) to my game scene, so that I can also mute the music there, how do I do that?
Basically how do I pass a variable value from one scene to another?
What I did a while ago is check if the iPod Player is working and give it priority over the game music. (ie. Check if iPod is playing to actually start game music, as ipod music player will usually overwrite you game's music if you are using AVAudioPlayer.
+ (bool) IsIpodPlaying{
if ([[MPMusicPlayerController iPodMusicPlayer] playbackState] == MPMusicPlaybackStatePlaying
|| [[MPMusicPlayerController applicationMusicPlayer] playbackState] == MPMusicPlaybackStatePlaying){
NSLog(#"iPod IS playing");
return true;
}else{
NSLog(#"iPod NOT playing");
return false;
}
}
Obviously you can do the same for your mute button. Ignore any action if iPod is playing, otherwise stop your game music.
To pass the information when the Mute button is pressed you can (in order of personal preference):
Set your Menu scene as a delegate of your Game scene and create a method to enable or disable sounds (ie. userDidEnableSound: )
Create a SoundControl singleton class that has the enable and disable sound methods and access them wherever you want.
Send a notification using the NSNotificationCenter and wait for it in the menu.

Sometimes Play icon on status bar disappear while using AVQueueplayer

I want to show the play icon on status bar in iOS while app is playing audio. I use AVQueuePlayer to play audio items. All works well but problem I am facing is play icon doesn't show on status bar sometimes.
The app has to support play/pause. When user taps on pause, I pause the queue player and tapping on play button will start playing the queue again. When user taps on play again, I do seeking of the player item so that it will be in sync with what it is supposed to be played at that time. But some times after tapping on play again, the queue seeks to proper time and plays but play icon doesn't show up in the status bar.
I tried by commenting out the seek code and just did play/pause. The play icon shows/hides correctly, but I am not sure what is happening with seekTime API. If I use this to seek, sometimes the icon doesn't show time.
Is this something issue happening in seekTime: API? I am using the following code for seek
[self.player.currentItem seekToTime:seekTime];
Please help me on this issue.
Thanks
I don't use AVQueuePlayer but I had a similar problem. I'm using AVAudioPlayer only and when the application starts I play an audio which is then repeated constantly. For some reason, at different times, the play icon disappears but the audio is still playing.
My solution was to apply the response of "One Man Crew" in How to display playing indication icon on status bar?
But, in addition, every time I play again, I use the following:
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
I don't know if it is correct, I am new in ios development, but currently is working to me.
Please let me know if there is a better solution.
Diego.

MPMoviePlayerController replay video

I want to display a button that gives the option to the user to restart a video in a MPMoviePlayerController at any time, even while the video is playing. I tried this but it has no effect:
-(IBAction)ReloadVideo:(id)sender{
[moviePlayer play];
}
Why doesn't this work?
You should call first [moviePlayer stop] this will:
stops playback of the current item and resets the playhead to the
start of the item. Calling the play method again initiates playback
from the beginning of the item.
(From apple docs)

Resources