Xamarin Forms: Issue with MediaElement audio playing

Sreejith Sree 1,251 Reputation points

I am using MediaElement for playing audio. I have a list of items and I need to play audio one after another. When playing audio I will change the background color of that list item. Also If I tap an item, the audio of that selected item starts playing, also the color of that item is modifying. These features are working fine in android. I have added a video of the android here.

Because of Native Crash Reporting of MediaElement, I have added a custom renderer in the ios platform. After adding the custom renderer, there are some issues while playing audio in ios. After playing the first audio, the second and third items background color is modifying. After that, the next 2 items color is modifying. I need to play items one by one.

My code:

<OnIdiom x:TypeArguments="x:Double">

//Initial audio source set up
audio_mediaelement.Source = aduiourl

//When audio end
public void AudioEnded(object sender, EventArgs args)
audioOrder = audioOrder + 1;
if(audioOrder < listVerses.Count)
audio_mediaelement.Source = aduioFormat + listVerses[audioOrder].audioUrl;
ChapterList.ItemsSource = listVerses;
listVerses[audioOrder].BGColor = Color.FromHex("#f2ee71");
ChapterList.ScrollTo(((IList)ChapterList.ItemsSource)[audioOrder-1], ScrollToPosition.Start, true);

I have uploaded a sample project here for reference since it is very difficult to understand the issue without a sample. If I didn't add the MediaElement custom renderer, the app will hang after playing audio.

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

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 67,631 Reputation points Microsoft Vendor


    Welcome to our Microsoft Q&A platform!

    If you want to have an UI and play next audio automatically. You can use install Plugin.MediaManager.Forms as well.

    First of all, here running UI.


    Here is UI in the notification task.


    Here is xaml code.

       <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"  
               <mm:VideoView VerticalOptions="FillAndExpand" AutoPlay="True" ShowControls="True" x:Name="MyVidem" />  

    Here is background code for list music

       public partial class MainPage : ContentPage  
               public MainPage()  
               public IList<string> Mp3UrlList => new[]{  
               private async void playmusic()  
                   // throw new NotImplementedException();  
                   await CrossMediaManager.Current.Play(Mp3UrlList);  

    Best Regards,

    Leon Lu

    If the response is helpful, please click "Accept Answer" and upvote it.

    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.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful