欢迎访问移动开发之家(rcyd.net),关注移动开发教程。移动开发之家  移动开发问答|  每日更新
页面位置 : > > 内容正文

Windows Phone 实用开发技巧(21):自动循环播放视频

来源: 开发者 投稿于  被查看 47282 次 评论:237

Windows Phone 实用开发技巧(21):自动循环播放视频


In Windows Phone Mango update, we can use VideoBrush since we could not do that in windows phone 7 . So there is something interesting to do. We can develop more fantasitic apps.  For example, we can play a video as background in our application. We want to play video in a loop also. But here comes the problem. Since there is no MediaTimeline in Silverlight for Windows Phone API. How can we repeat media playback ?

In WPF or Silverlight, we can use following code to repeat media playback.


<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
  <StackPanel>
 
    <!-- The MediaElement control plays the sound. -->
    <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>
 
  </StackPanel></Page>

 In windows phone , I find simple solution to play video in a loop. Since we can catch Media_End event, we can play again in ended event.

 \

Another suggestion : do not play large video in your windows phone app since it will cause a little bit performance damage.

Source code can be found here :

相关文章

    暂无相关文章
相关频道:

用户评论