Quick building of Windows 8 style apps 20-MediaElement

Source: Internet
Author: User

This blog post mainly introduces MediaElement overview, MediaElement object introduction, common attributes of MediaElement, and how to control media playback.

MediaElementOverviewThe MediaElement class is usually used to play audio or video files in Windows 8 style applications. The MediaElement object provides attributes and methods for playing a video or audio. For details about MediaElement development examples, refer To the links: XAML media playback sample and Media Play To sample. MediaElementObject IntroductionIt is easier to use MediaElement to construct the function of playing video files in the application. For example, in the XAML code, declare the MediaElement control and set the Source attribute value to the video Uri.
 <MediaElement x:Name="media" Source="Video/Azure_Tmobile_500k.wmv" Width="400" />
C # declare the MediaElement control in the Code. The Code is as follows:
MediaElement mediaElement = new MediaElement();
mediaElement.Name = "mediaElement1";
mediaElement.Width = 400;
mediaElement.Source = new Uri("ms-appx:///Video/Azure_Tmobile_500k.wmv");
this.grid1.Children.Add(mediaElement);
Allow: 650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1F355G58-0.png "/> MediaElement plays automatically when the page is loaded. To prevent automatic video playback, you can set the AutoPlay attribute value of the MediaElement control to false. MediaElementCommon attributesCommon attributes of the MediaElement object include: 1) AutoPlay attribute: Specifies whether the MediaElement starts playing automatically. The default value is True; 2) IsMuted attribute: Specifies whether the MediaElement is set to mute. The default value is False. True indicates mute. 3) Stretch attribute: how to Stretch the video to fill the MediaElement object. The default value is Fill. Other values include None, Uniform, and UniformToFill;

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1F3553042-1.png "/>

4) Volume attribute: sets the Volume value of the MediaElement object. The default value is 0.5 and the maximum value is 0. For other attributes of the MediaElement object, see MediaElement Class. How to control media playbackWe can use Play,Pause andThe Stop method controls media playback. For example, declare the MediaElement control in the XAML code and add three buttons to control media playback. <MediaElement x: Name = "media" Source = "Video/Azure_Tmobile_500k.wmv" Width = "300" Height = "300" Grid. column = "0" Grid. row = "0" Margin = "518,42, 548,426"/> <Button Click = "StopMedia" Grid. column = "0" Content = "Stop" Margin = "444,365, 0,365"/> <Button Click = "PauseMedia" Content = "Pause" Margin = "615,365, 0,365 "/> <Button Click =" PlayMedia "Content =" Play "Margin =" 828,365, 0,365 "/> C # code: private void StopMedia (object sender, RoutedEventArgs e) {media. stop ();} private void PauseMedia (object sender, RoutedEventArgs e) {media. pause ();} private void PlayMedia (object sender, RoutedEventArgs e) {media. play ();} In addition, we can also set the MediaElement object Position attribute to specify a media location.

This article is from the "Wang Zukang" blog, please be sure to keep this source http://wzk89.blog.51cto.com/1660752/1030360

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.