Add audio controls to the lock screen and notification panel (Android and iOS).

Elizabeth James 1 Reputation point

I'm using AVAudioplayer for iOS and Media Player for android, for playing audio. How can I add audio controls to the lock screen and notification panel in the device?

A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,206 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 24,741 Reputation points Microsoft Vendor


    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(){  
               mediaplayer = new AVPlayer(your URI);  
       	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){  
       	if (theEvent.Subtype == UIEventSubtype.RemoteControlPreviousTrack){  
       		//Something you need to do.               
       	else if (theEvent.Subtype == UIEventSubtype.RemoteControlNextTrack){  
       		//Something you need to do.               
       		//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.