wpf 播放视频以及循环播放

url:

<MediaElement Source="{Binding url}" />
public Uri url
            {
                get
                {
                    return  new Uri("http://vjs.zencdn.net/v/oceans.mp4", UriKind.Absolute) ;
                }
            }

 文件路径:

mediaElement.Source = new Uri(new System.Uri(@"X:\视频\trailer.mp4").AbsoluteUri, UriKind.Absolute);
                    mediaElement.LoadedBehavior = MediaState.Manual;
                    mediaElement.UnloadedBehavior = MediaState.Manual;
                    mediaElement.Play();

 循环播放:

<MediaElement Name="myMediaElement" >
      <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 Source="media\tada.wav" Storyboard.TargetName="myMediaElement"  
                 RepeatBehavior="Forever" />

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

 

posted on 2022-06-28 16:34  空明流光  阅读(642)  评论(0编辑  收藏  举报

导航