Practical development tips for Windows Phone (21): Automatic loop video playback

Source: Internet
Author: User

In Windows Phone mango update, we can use videobrush since we cocould 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 m EDIA 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: I wrote a technical blog in English for the first time. It really hurts D. But to learn e well, it only hurts because I firmly believe that it will not hurt if it hurts!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.