Playlist for WPF MediaElement

I am learning C # and WPF, creating an application like WMP. The code below works fine, selecting a movie from the list allows you to run it in a multimedia element. The problem I am facing is finding a way to automatically start the next movie after completion. Thank.

XML file containing a list of movies:

<?xml version="1.0" encoding="ISO-8859-1"?>

  Bear C: \ films \ Bear.wmv butterfly C: \ films \ Butterfly.wmv Lake C: \ films \ Lake.wmv

Xaml

<Window x:Class="WpfAppPlaylistTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="425">

<Window.Resources>
    <XmlDataProvider x:Key="myMoviesXML"

                         Source="c:\Movies\media1.xml"
                         XPath="media"
        />
</Window.Resources>

<Grid DataContext="{Binding ElementName=movieList, Path=SelectedItem}">
    <ListBox ItemsSource="{Binding Source={StaticResource myMoviesXML}, XPath=//media//movie}" IsSynchronizedWithCurrentItem="True" 
     Name="movieList" HorizontalAlignment="Right" Width="114" Margin="0,48,12,32">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding XPath=title}"/>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
    <MediaElement Source="{Binding XPath=filename}" LoadedBehavior="Play" Name="mediaElement1" Margin="12,26,136,12"  />
</Grid>

+3
source share
1 answer

MediaElement has a MediaEnded event that should fire when that happens. Then you can program the next item in the list and play this file.

+1

Source: https://habr.com/ru/post/1731919/


All Articles