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>
桂棹兮兰桨,击空明兮溯流光。