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文,只好疼下去了,因为我坚信:疼着疼着就不疼了! 

posted @   Alexis  阅读(2016)  评论(6编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
点击右上角即可分享
微信分享提示