I dont know how to toggle the play and pause button. I have tried TogglePlayPauseCommand. But it is not working.
Asked
Active
Viewed 1,941 times
1 Answers
2
Would you be able to post your code on how you have tried to implement the TogglePlayPauseCommand? I think it would be done like so:
public override void ViewDidLoad()
{
base.ViewDidLoad ();
var commandCenter = MPRemoteCommandCenter.Shared;
commandCenter.TogglePlayPauseCommand.AddTarget (ToggledPlayPauseButton);
}
public MPRemoteCommandHandlerStatus ToggledPlayPauseButton(MPRemoteCommandEvent commandEvent)
{
Console.WriteLine ("Toggled");
return MPRemoteCommandHandlerStatus.Success;
}

Iain Smith
- 9,230
- 4
- 50
- 61
-
Thanks. It worked for me. I was creating object like this: MPRemoteCommandCenter obj = new MPRemoteCommandCenter(); What is the purpose of Shared? – Neha Gupta Aug 27 '15 at 12:47
-
Ah no worries, glad I could help! – Iain Smith Aug 27 '15 at 12:48
-
Can you plz tell me What is the purpose of shared in this var commandCenter = MPRemoteCommandCenter.Shared; – Neha Gupta Aug 27 '15 at 12:50
-
Ah sorry didnt see that bit. The purpose of Shared is to access the singleton object MPRemoteCommandCenter. In other words there is only one MPRemoteCommandCenter might be used in other apps or the OS but its is created by calling Shared or it returns the one already created. more info in this link https://developer.apple.com/library/ios/documentation/MediaPlayer/Reference/MPRemoteCommandCenter_Ref/ – Iain Smith Aug 27 '15 at 12:54
-
The first time you try to access the shared property, the property instance isn’t yet created, so it will create a new instance of the MPRemoteCommandCenter and return it. The next time you call shared, the instance is immediately returned without having to be created. This logic promises that only one instance exists at all times. – Iain Smith Aug 27 '15 at 13:01