locked
Playing a movie inside a media element RRS feed

  • Question

  • Hi.

     

    The code below doesn't work for me.  The window displays fine but the movie file does not play inside the media element.  I'm new to WPF and found the snippet of code in the help files, but can't get it to work.

    Any help would be greatly appreciated. 

    <Window x:Class="PhotoTool.UploadStatus"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="Upload Progress" Height="397" Width="596" Name="uploadStatus" WindowStyle="SingleBorderWindow" WindowStartupLocation="CenterOwner" Icon="pack://application:,,,/Resources/PhotoToolIcon.ico" ResizeMode="NoResize">
      <Grid>
        <GroupBox Header="Summary" Height="171" Margin="6,6,6,0" Name="groupBoxSummary" VerticalAlignment="Top">
          <Grid></Grid>
        </GroupBox>
        <MediaElement Height="171" Margin="6,0,264,5" Name="mediaElement" VerticalAlignment="Bottom" LoadedBehavior="Play" UnloadedBehavior="Stop" Source="pack://application:,,,/Resources/zen apple.mov">
          <MediaElement.Triggers>
            <EventTrigger RoutedEvent="MediaElement.Loaded">
              <EventTrigger.Actions>
                <BeginStoryboard>
                  <Storyboard>
                    <MediaTimeline Source="pack://application:,,,/Resources/zenapple.mp4" Storyboard.TargetName="mediaElement" RepeatBehavior="Forever" />
                  </Storyboard>
                </BeginStoryboard>
              </EventTrigger.Actions>
            </EventTrigger>
          </MediaElement.Triggers>
        </MediaElement>
      </Grid>
    </Window>

    Sebastian
    Thursday, October 7, 2010 4:22 PM

Answers

  • Try this: http://windowsclient.net/learn/video.aspx?v=73040. It is a nice short video (15 minutes) by Tod Miranda . Also pasting code below

    <Window x:Class="VideoPlayback.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
      <Grid>
        <Grid.RowDefinitions>
          <RowDefinition Height="2*" />
          <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <MediaElement x:Name="myMedia" />
        <StackPanel Grid.Row="1" Name="stackPanel1" Orientation="Horizontal">
          <StackPanel.Triggers>
            <EventTrigger RoutedEvent="Button.Click" SourceName="btnPlay">
              <EventTrigger.Actions>
                <BeginStoryboard x:Name="beginVideo">
                  <Storyboard>
                    <MediaTimeline Source="wildlife.wmv" Storyboard.TargetName="myMedia"/>
                  </Storyboard>
                </BeginStoryboard>
              </EventTrigger.Actions>
            </EventTrigger>
            <EventTrigger RoutedEvent="Button.Click" SourceName="btnPause">
              <EventTrigger.Actions>
                <PauseStoryboard BeginStoryboardName="beginVideo"/>
              </EventTrigger.Actions>
            </EventTrigger>
            <EventTrigger RoutedEvent="Button.Click" SourceName="btnResume">
              <EventTrigger.Actions>
                <ResumeStoryboard BeginStoryboardName="beginVideo"/>
              </EventTrigger.Actions>
            </EventTrigger>
            <EventTrigger RoutedEvent="Button.Click" SourceName="btnStop">
              <EventTrigger.Actions>
                <StopStoryboard BeginStoryboardName="beginVideo"/>
              </EventTrigger.Actions>
            </EventTrigger>
    
          </StackPanel.Triggers>
          <Button Content="Play" Height="23" x:Name="btnPlay" Width="75" />
          <Button Content="Pause" Height="23" x:Name="btnPause" Width="75" />
          <Button Content="Resume" Height="23" x:Name="btnResume" Width="75" />
          <Button Content="Stop" Height="23" x:Name="btnStop" Width="75" />
        </StackPanel>
      </Grid>
    </Window>
    
    

    WPF Rocks :)!
    • Marked as answer by SebDaddy Tuesday, October 12, 2010 2:32 PM
    Thursday, October 7, 2010 11:03 PM

All replies

  • Try this: http://windowsclient.net/learn/video.aspx?v=73040. It is a nice short video (15 minutes) by Tod Miranda . Also pasting code below

    <Window x:Class="VideoPlayback.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
      <Grid>
        <Grid.RowDefinitions>
          <RowDefinition Height="2*" />
          <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <MediaElement x:Name="myMedia" />
        <StackPanel Grid.Row="1" Name="stackPanel1" Orientation="Horizontal">
          <StackPanel.Triggers>
            <EventTrigger RoutedEvent="Button.Click" SourceName="btnPlay">
              <EventTrigger.Actions>
                <BeginStoryboard x:Name="beginVideo">
                  <Storyboard>
                    <MediaTimeline Source="wildlife.wmv" Storyboard.TargetName="myMedia"/>
                  </Storyboard>
                </BeginStoryboard>
              </EventTrigger.Actions>
            </EventTrigger>
            <EventTrigger RoutedEvent="Button.Click" SourceName="btnPause">
              <EventTrigger.Actions>
                <PauseStoryboard BeginStoryboardName="beginVideo"/>
              </EventTrigger.Actions>
            </EventTrigger>
            <EventTrigger RoutedEvent="Button.Click" SourceName="btnResume">
              <EventTrigger.Actions>
                <ResumeStoryboard BeginStoryboardName="beginVideo"/>
              </EventTrigger.Actions>
            </EventTrigger>
            <EventTrigger RoutedEvent="Button.Click" SourceName="btnStop">
              <EventTrigger.Actions>
                <StopStoryboard BeginStoryboardName="beginVideo"/>
              </EventTrigger.Actions>
            </EventTrigger>
    
          </StackPanel.Triggers>
          <Button Content="Play" Height="23" x:Name="btnPlay" Width="75" />
          <Button Content="Pause" Height="23" x:Name="btnPause" Width="75" />
          <Button Content="Resume" Height="23" x:Name="btnResume" Width="75" />
          <Button Content="Stop" Height="23" x:Name="btnStop" Width="75" />
        </StackPanel>
      </Grid>
    </Window>
    
    

    WPF Rocks :)!
    • Marked as answer by SebDaddy Tuesday, October 12, 2010 2:32 PM
    Thursday, October 7, 2010 11:03 PM
  • Hi Sauurabhmadan.  Thanks for the link.  After some digging I realized that the probem wasn't with my code, but rather that I was using a .MOV file.  When I converted the .MOV to a .WMV it worked.

    Thanks for pointing me in the right direction.

     

    Sebastian


    Sebastian
    Tuesday, October 12, 2010 2:32 PM