简体   繁体   English

WPF MediaElement应用程序的播放列表

[英]Playlist for WPF MediaElement app

I'm learning C# and WPF by building a WMP-type app. 我正在通过构建一个WMP类型的应用程序来学习C#和WPF。 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文件:

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

Bear c:\\movies\\Bear.wmv Butterfly c:\\movies\\Butterfly.wmv Lake c:\\movies\\Lake.wmv 熊c:\\ movies \\ Bear.wmv蝴蝶c:\\ movies \\ Butterfly.wmv Lake c:\\ movies \\ Lake.wmv

xaml 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>

MediaElement has a MediaEnded event that should fire when this happens. MediaElement有一个MediaEnded事件,应该在发生这种情况时触发。 Then you can programmably select the next item in the list, and play that file. 然后,您可以可编程地选择列表中的下一个项目,然后播放该文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM