Play Ended Event
jbh630 opened this issue · comments
I have a UWP app that I am refactoring into a ,Net Maui app and I don't see an event to support the Plugin.Naui.Audio audio player file (sound) has completed or ended. In my UWP app this was a MediaEnded event. Is there something in the plugiun that I am not just seeing?
You want the PlaybackEnded
event in the AudioPlayer
class
I see that the IAudioPlauer interface supports the event but it doesn't fire when the sound completes. Is there something required to make the event fire?
Looks like it should be triggered: https://github.com/jfversluis/Plugin.Maui.Audio/blob/main/src/Plugin.Maui.Audio/AudioPlayer.windows.cs#L93
Could you maybe put together a small reproduction project on how you're trying to use this to demonstrate the issue?
Thanks!
Hi,
I think the problem is that you are setting player.PlaybackEnded
with the method PlaybackEnded
instead of an EventHandler
.
See below, I added a member playbackEndedEventHandler
to your class (see the lines with a comment). This is what you should use for the PlaybackEnded
event. I did not test the below code, but I successfully use something similar in my project.
public partial class ChordsPage : ContentPage
{
private readonly IAudioManager audioManager;
IAudioPlayer player;
private readonly EventHandler playbackEndedEventHandler; // <= event handler
public ChordsPage(IAudioManager audioManager)
{
InitializeComponent();
this.audioManager = audioManager;
playbackEndedEventHandler = new EventHandler(PlaybackEnded); // <= instantiate the event handler
}
private void PlaybackEnded(object sender, EventArgs e)
{
PauseButton.Background = new SolidColorBrush(Colors.LightGray);
StopButton.Background = new SolidColorBrush(Colors.LightGray);
}
private async void ChordList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Sound item = (Sound)ChordList.SelectedItem;
player = audioManager.CreatePlayer(await FileSystem.OpenAppPackageFileAsync(item.AudioFile));
player.PlaybackEnded += playbackEndedEventHandler; // <= add the event handler instead of the method
player.Play();
}
}
That latest code sample is referring to the MediaElement which comes from the .NET MAUI Community Toolkit and not this project. Which are you using?
@jbh630 This is a close and unrelated issue so I won't go into detail here but please feel free to reach out to me and I can offer assistance
Twitter(X)
https://twitter.com/Bijington