Getting started with multimedia audio and video in 6-Silverlight 1.0
Next we will introduce Silverlight 1.0 multimedia audio and video. Currently, Silverlight 1.0 only supports the WMA, WP3, and WMV formats. With the release of the new Silverlight version, we believe more audio and video formats will be supported. The following is an Application diagram:
========================================================== ==========
| MP3 |
| Audio | --
| Mediaelement | -- | WMA |
| Video | -- | WMV |
Silverlight audio and video --
| Videobrush |
========================================================== ==========
In Silverlight, audio and video playback are implemented through <mediaelement.../> declaration. Its usage is as follows:
========================================================== ==========
<Mediaelement
Source = "file name"
Volume = "volume size"
Balance = "left-right channel balance"
Autoplay = "automatic playback"
Bufferingtime = "buffer time"
Position = "time position of media playback"
Ismuted = "mute">
</Mediaelement>
========================================================== ==========
Important attributes:
Volume ranges from 0 ~ Value Range: 1. The default value is 0.5. 0 is the minimum value, and 1 is the maximum value;
Balance ranges from-1 ~ Value Range: 1. The default value is 0.-1 indicates that 100% is sent from the left-side channel, 1 indicates that 100% is sent from the right-side channel, and 0 indicates that both channels are voiced.
And the sound is the same;
The autoplay value is true or false. The default value is true. True indicates automatic playback. False indicates automatic playback;
Bufferingtime
The default position is 00:00:00;
The ismuted value is true or false. The default value is false. True indicates mute, and false indicates non-mute;
Use <mediaelement to play audio as follows:
<Mediaelement source = "file name"/mediaelement>
See the following sample code --
Code 1:
============================================
<Canvas xmlns = "http://schemas.microsoft.com/client/2007"
Xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml">
<Canvas>
<Textblock fontfamily = "Arial black" fontsize = "30" foreground = "pink"> audio playing... </textblock>
<Mediaelement source = "myaudio.wma"/>
</Canvas>
</Canvas>
============================================
Paste code 1 to the myxaml.xaml file in step 1 and save it. Then, double-click the samplehtmlpage.html file in step 1 to hear the music. You can set
Attribute Value.
Note: The audio file myaudio.wma must be put in the same folder as the four files in Entry 1. Of course, you can also leave them empty, but you need to set the relative path;
The usage of playing video with <mediaelement is the same as that of audio. See the following sample code --
Code 2:
============================================
<Canvas xmlns = "http://schemas.microsoft.com/client/2007"
Xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml">
<Canvas X: Name = "blank">
<Mediaelement source = "myvideo. wmv" volume = "0.7" balance = "-0.5"/>
</Canvas>
</Canvas>
============================================
You can also set attribute values to familiarize yourself with the usage of attributes.
Note: Similarly, the myvideo. WMV Video file must be placed in the same folder as the four files in Entry 1. Of course, you can also leave them empty, but you need to set the relative path;
This also needs to be emphasized that the help document in the microsft Silverlight 1.0 SDK contains the following:
============================================
You can specify the height and width of the video display surface using the uielement-defined properties height and width. however, for best performance, avoid explicitly setting the width and height of a mediaelement. INSEAD, leave the values unset. once you specify a source, the media will display at its natural size, and layout will recalculate the size.
============================================
For the best performance, do not set the width and height attribute values in the <mediaelement.../> element object. When the source file is referenced, media will be displayed in a normal position.
Forge ahead, boldly innovate
Montgomery Zhu