Playlist for WPF MediaElement app

假装没事ソ 提交于 2019-12-10 18:13:45

问题


I'm learning C# and WPF by building a WMP-type app. The code below runs fine, selecting a movie from the listbox runs it in the media element. The problem I'm having is finding a way to automatically start the next movie after one ends. Thank You.

The xml file that provides a list of movies:

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

Bear c:\movies\Bear.wmv Butterfly c:\movies\Butterfly.wmv Lake c:\movies\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>


回答1:


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



来源:https://stackoverflow.com/questions/2224435/playlist-for-wpf-mediaelement-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!