[WPF 筆記] MediaElement & MediaTimeline

  • 1427
  • 0

摘要:[WPF 筆記] MediaElement & MediaTimeline

WPF 嵌入影片

xaml


        <MediaElement Name="redangVideo" Grid.Row="0" LoadedBehavior="Manual" UnloadedBehavior="Stop">
            <MediaElement.Triggers>
                <EventTrigger RoutedEvent="MediaElement.Loaded">
                    <EventTrigger.Actions>
                        <BeginStoryboard>
                            <Storyboard>

                                <!-- The MediaTimeline has a RepeatBehavior="Forever" which makes the media play
                     over and over indefinitely.-->
                                <MediaTimeline Name="redangVideoLoop" Source="" Storyboard.TargetName="redangVideo"  
                 RepeatBehavior="Forever" />

                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger.Actions>
                </EventTrigger>
            </MediaElement.Triggers>
        </MediaElement>

c#


string FilePath = "";      
public MainWindow()
      {
         InitializeComponent();
         FilePath = System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName) + "/MyVideo.avi";
         redangVideoLoop.Source = new Uri(FilePath); //loop 
      }