0

I am using Plugin.MediaManager.Forms for playing a list of audios. I am also showing the same list of items (text data) in a listview. When playing audio I need to change the background color of the item.

My Code:

List<string> songsUrlList = new List<string>();
for (int i = 0; i < chaptersList.Count; i++)
{
    songsUrlList.Add(aduioFormat+ chaptersList[i].audioUrl);
}
var mediaItem = await CrossMediaManager.Current.Play(songsUrlList);

First I created an audio list, then I play that list like above. I am able to change the background color of the first item. When the remaining audio starts playing I don't know how to change the background color.

If I tap an item, I clear the songsUrlList first, then create a new list and play that list like below. Is it a correct implementation?

private async void ChapterTapped(object sender, ItemTappedEventArgs e)
{
    var selectedItem = (ListVerses)e.Item;
    if (selectedItem != null)
    {
        await CrossMediaManager.Current.Pause();
        songsUrlList.Clear();
        for (int i = Int32.Parse(selectedItem.slno) - 1; i < chaptersList.Count; i++)
        {
            songsUrlList.Add(aduioFormat+ chaptersList[i].audioUrl);
        }
        await CrossMediaManager.Current.Play(songsUrlList);
        audioOrder = Int32.Parse(selectedItem.slno) - 1;
        selectedItem.BGColor = Color.FromHex("#f2ee71");
    }
    ChapterList.SelectedItem = null;
}

I need to change the background color of the list item when audio plays that item. I have added an expected feature video here.

I have added a sample project here for reference.

Sreejith Sree
  • 3,055
  • 4
  • 36
  • 105

1 Answers1

1

You could implement the event MediaItemFinished

 CrossMediaManager.Current.MediaItemFinished += Current_MediaItemFinished;
private void Current_MediaItemFinished(object sender, MediaManager.Media.MediaItemEventArgs e)
    {
        audioOrder = audioOrder + 1;
        if (audioOrder < chaptersList.Count)
        {
            MyVidem.Source = aduioFormat + chaptersList[audioOrder].audioUrl;
            ChapterList.ItemsSource = chaptersList;
            chaptersList[audioOrder].BGColor = Color.FromHex("#f2ee71");
            ChapterList.ScrollTo(((IList)ChapterList.ItemsSource)[audioOrder - 1], ScrollToPosition.Start, true);
        }
    }
Lucas Zhang
  • 18,630
  • 3
  • 12
  • 22