In my UWP app for Raspberry pi3 I have a music player that plays songs from a ListView. You can select any song in the ListView and then it will automatically play the next song. The problem I am facing is that when it reaches the last song and finishes it plays it again and doesn't stop. Like it goes in a loop on the last song instead of stopping after playing it.
Can someone direct me on how to stop the loop?
This is my code:
private async void SongClicked(object sender, ItemClickEventArgs e)
{
var file = await KnownFolders.MusicLibrary.GetFileAsync(e.ClickedItem.ToString());
if (file != null)
{
var stream = await file.OpenReadAsync();
mediaElement.SetSource(stream, file.ContentType);
mediaElement.Play();
}
}
private void mediaItemList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
private void objMediaPlayer_MediaOpened(object sender, RoutedEventArgs e)
{
mediaElement.Play();
}
private async void objMediaPlayer_MediaEnded(object sender, RoutedEventArgs e)
{
if (AudioFilesLV.SelectedIndex <= AudioFilesLV.Items.Count)
{
AudioFilesLV.SelectedIndex = AudioFilesLV.SelectedIndex = 1;
var file = await KnownFolders.MusicLibrary.GetFileAsync(AudioFilesLV.SelectedItem.ToString());
if (file != null)
{
var stream = await file.OpenReadAsync();
mediaElement.SetSource(stream, file.ContentType);
mediaElement.Play();
}
}
else
{
mediaElement.Stop();
}
}
Any help will be appreciated.
Thanks.