Quickly build Windows 8 style apps 20-mediaelement

Source: Internet
Author: User

Original: Quickly build Windows 8 style apps 20-mediaelement

This post mainly introduces MediaElement overview, MediaElement object Introduction, MediaElement Common Properties, how to control media playback.

MediaElement Overview

You typically use the MediaElement class to build when you play audio or video files in a Windows 8-style app.

The MediaElement object provides properties and methods for playing video or audio.

Examples of the development of related MediaElement can be found in the link: XAML media playback Sample and media Play to sample.

MediaElement Object Introduction

It is easier to use MediaElement to build the ability to play video files in the application surface.

For example:

The XAML code declares the MediaElement control, and the Source property value is set to the video URI.

< MediaElement x:name = "Media" Source = "video/azure_tmobile_500k.wmv"  Width = "The " />

The MediaElement control is declared in C # code, with the following code:

New MediaElement ();
"MediaElement1";
Mediaelement.width = 400;
New Uri ("ms-appx:///video/azure_tmobile_500k.wmv");
this. Grid1. Children.add (mediaElement);

Allowed as follows:

When the page loads, the MediaElement is automatically played. In general, to prevent the video from playing automatically, you can set the AutoPlay property value of the MediaElement control to false.

MediaElement Common Properties

Common properties for MediaElement objects include:

1) AutoPlay Property: Specifies whether MediaElement starts playback automatically. The default value is true;

2) ismuted Property: Specifies whether MediaElement is set to mute. The default value is false,true for mute;

3) Stretch properties: How to stretch the video to fill the MediaElement object. The default value is fill, and the other values are none, Uniform, UniformToFill;

4) Volume property: Sets the MediaElement object volume value. The default value is 0.5 and the maximum value is 0;

MediaElement object Other properties can refer to this link: MediaElement Class.

how to control media playback

We can use the play,Pause , and Stop methods of the MediaElement object to control media playback.

For example:

The XAML code declares the MediaElement control, adding three buttons to control the playback of the media.

< MediaElement x:name = "Media" Source = "Video/azure_tmobile_500k.wmv" Width = "+" Height = "+" 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" />

In 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 set the MediaElement object Position property to specify the media-specific location.

Quickly build Windows 8 style apps 20-mediaelement

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.