Note that there are some explanatory texts on larger screens.

plurals
  1. POListen for MediaEnded event in another window
    primarykey
    data
    text
    <p>I'm making a simple C# WPF video player app.</p> <p>I have 2 Windows: The MainWindow (Parent window) contains the MediaElement to display the video. The PlaylistWindow (Child window) is the window that contains a ListBox that displays all the .avi files in the appRoot path.</p> <p>Currently, when I double-click on a ListBox item, it plays that video in MainWindow. I would like to have an auto-play feature so the next item in the list is automatically played when the current video ends.</p> <p>I would like PlaylistWindow to listen for the MediaEnded event triggered by the MediaElement in MainWindow so I can perform some action on the ListBox in PlaylistWindow.</p> <p>How can I subscribe to the MediaEnded event from PlaylistWindow?</p> <p>Edit to Add: I ended up using a different approach as shown below. I don't think this is the best way to do it, but it works for me.</p> <pre><code>public partial class MainWindow : Window { PlaylistWindow PLWindow = new PlaylistWindow(); public MainWindow() { InitializeComponent(); } private void MainWindow_Loaded(object sender, RoutedEventArgs e) { PLWindow.Owner = this; PLWindow.Show(); } private void videoWindow_Ended(object sender, EventArgs e) { PLWindow.playNext(); } } public partial class PlaylistWindow : Window { public void playNext() { if (playListBox.SelectedIndex &lt; playListBox.Items.Count - 1) { playListBox.SelectedIndex = playListBox.SelectedIndex + 1; } else { playListBox.SelectedIndex = 0; } (Owner as MainWindow).playVideo(playListBox.SelectedValue.ToString()); } } </code></pre> <p>I'm still open to learning about how to listen for the MediaEnded event in PlaylistWindow if a code sample can be posted.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload