MediaElement
is currently experimental, I cannot found this feature play the music when lock screen, but you can use CrossMediaManager, It is support the play the music when lock screen by default.
Just Used a Button to invoke the play method.
<Button Text="play" Clicked="Button_Clicked"></Button>
private async void Button_Clicked(object sender, EventArgs e)
{
await CrossMediaManager.Current.Play("https://ia800806.us.archive.org/15/items/Mp3Playlist_555/AaronNeville-CrazyLove.mp3");
}
Note:when add CrossMediaManager.Current.Init(this);
in your OnCreate
method of MainActivity.cs
. Please do not forget the set the Target Framework to Android 9.0 or later.