3

WMP系のアプリを作ってC#とWPFを学んでいます。以下のコードは問題なく実行されます。リスト ボックスからムービーを選択すると、メディア要素で実行されます。私が抱えている問題は、映画が終わった後に次の映画を自動的に開始する方法を見つけることです。ありがとうございました。

映画のリストを提供する xml ファイル:

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

くま c:\movies\Bear.wmv 蝶 c:\movies\Butterfly.wmv 湖 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>

4

1 に答える 1

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.

于 2010-02-08T20:04:13.483 に答える