Windows Phone 實用開發技巧(21):自動迴圈播放視頻

來源:互聯網
上載者:User

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文,只好疼下去了,因為我堅信:疼著疼著就不疼了! 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.