Hello,
For Android, you can refer to Lock Screen Music Controls in Xamarin.Android and Background Audio Streaming with Xamarin.Android, written by James.
For IOS, you can refer to the following steps:
Step1. Set the background mode for your player App.
Step2. Setting your player in your ViewDidLoad
method:
public override void ViewDidLoad(){
base.ViewDidLoad();
UIApplication.SharedApplication.BeginReceivingRemoteControlEvents();
mediaplayer = new AVPlayer(your URI);
AVAudioSession.SharedInstance().SetActive(true);
AVAudioSession.SharedInstance().SetCategory(AVAudioSessionCategory.Playback);
MPNowPlayingInfo nowPlayingInfo;
nowPlayingInfo = new MPNowPlayingInfo();
nowPlayingInfo.Artist = "An OK Band";
nowPlayingInfo.Title = "Our First Single!";
MPNowPlayingInfoCenter.DefaultCenter.NowPlaying = nowPlayingInfo;
}
Step 3. Listen to changes in that media player notification as the user taps on next, play/pause, or previous.
public override void RemoteControlReceived(UIEvent theEvent){
base.RemoteControlReceived(theEvent);
if (theEvent.Subtype == UIEventSubtype.RemoteControlPreviousTrack){
//Something you need to do.
}
else if (theEvent.Subtype == UIEventSubtype.RemoteControlNextTrack){
//Something you need to do.
}
else{
//Something you need to do.
}
}
In fact, Xamarin has a more simple way to implement this function.
You can refer to Play Audio and Video with the MediaManager Plugin for Xamarin which was written by Xamarin MVP, Martijn van Dijk.
Best Regards,
Alec Liu.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.