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 :  

 

 PS:第一次用英文写技术博客,真D疼,奈何为了学好E文,只好疼下去了,因为我坚信:疼着疼着就不疼了!



    本文转自xshf12345 51CTO博客,原文链接:http://blog.51cto.com/alexis/672031,如需转载请自行联系原作者





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值