欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

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

程序员文章站 2022-04-26 12:37:43
in windows phone mango update, we can use videobrush since we could not do that in windows phone 7...

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 x" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: rgb(255, 102, 0); text-decoration: none; ">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.

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

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 :