zoukankan      html  css  js  c++  java
  • 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文,只好疼下去了,因为我坚信:疼着疼着就不疼了! 

    如果您喜欢我的文章,您可以通过支付宝对我进行捐助,您的支持是我最大的动力https://me.alipay.com/alexis


    作者:Alexis
    出处:http://www.cnblogs.com/alexis/
    关于作者:专注于Windows Phone 7、Silverlight、Web前端(jQuery)。
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,如有问题,可以通过shuifengxuATgmail.com  联系我,非常感谢。

  • 相关阅读:
    深入浅出理解基于 Kafka 和 ZooKeeper 的分布式消息队列
    消息队列使用的四种场景介绍
    《深入理解Java函数式编程》系列文章
    搭建微服务框架(Spring Boot + Dubbo + Docker + Jenkins)
    spring boot 整合dubbo
    IDEA中使用springBoot+gradle构建多模块项目
    Mac上zookeeper的安装与启动
    redis常用客户端命令
    mac下安装、配置redies
    轻松看懂机器学习常用算法
  • 原文地址:https://www.cnblogs.com/alexis/p/2173023.html
Copyright © 2011-2022 走看看