Preface
In the previous articleArticleThis article describes how to create a Silverlight for Windows Phone application.ProgramThis article describes how to develop multimedia applications on Windows Phone. This article also introduces the media file formats supported by the current Windows Phone beta version, as well as some restrictions and notes on Windows Phone multimedia development.
Use of the mediaelement Control
The mediaelement control is sufficient for developing general multimedia applications using Silverlight. The mediaelement control supports audio and video files, local and network files, and multi-media file Decoder (codec ), this greatly simplifies the difficulty of developing multimedia applications.
Added the mediaelement control.
Next we will continue to explain how to use the mediaelement control in the previous example.
To add a mediaelement control, you can drag the mediaelement control on the toolbox to the design page. Method 2: In the XAML file, click the location where you want to store the mediaelement control, double-click mediaelement in toolbox. Method 3 is directly Written In The XAML file.CodeAdded the mediaelement control. The three methods are equivalent.
In this example, I have added three buttons for conversion to radio station and playback. Subsequent articles in this series will introduce how to use expression blend to beautify the buttons, use text to describe. The effect is as follows:
Play network station files
After the mediaelement control is added to XAML, you can specify the file source for playback. Click the "play" button in the design view, or write the event processing function in the XAML directly. After the click event is compiled in the following figure, you can click the tab button to add an event handler function (the Code of the handler function is automatically generated ). Visual stadio 2010 provides many convenient functions for coding ..
Private voidButtonplay_click (ObjectSender,RoutedeventargsE) {mediaelementradio. Source =NewUri(Http://icecast.arn.com.au/1011.mp3",Urikind. Absolute); mediaelementradio. Play ();}
Using the mediaelement control to play a network station is very simple. You only need to specify the source attribute of the control. Source is a URI object, which can be the address of a network file or a local file. After specifying the source, call the play () function to start the playing process of the Network Station.
Supported file formats
According to msdn documentation supported media codecs, the current version of Windows Phone 7 supports the following media file formats: WAV, MP3, WMA standard V9, AAC-LC (low complexity) and so on, detailed can refer to the above documentation. The simulator supports fewer Decoder (codecs), just supports WAV, MP3, WMA standard V9 and WMV (VC-1 ). However, after my experiment, the network station only supports the MP3 format, which may be a simulator problem. I want to fix this problem on a real device. If the file format not supported by the simulator is met, the mediafailed event is triggered. The processing of the mediafailed event is described in detail later in this article.
Note: A media file must have an extension, and the extension must be the same as the file encoding format. For example, if the file is in MP3 format, the extension must be *. MP3; otherwise, the file cannot be played.
I think Windows Phone supports more and more decoders, so don't worry.
Restrictions of mediaelement controls in Silverlight for Windows
Note the following limitations when developing and porting A Silverlight program to a Windows Phone.
1. VCR controls are not supported. If you use the Windows Media Player Control for development on Windows Mobile, you can display controls such as play, pause, stop, and progress bar (play, pause, stop, seek, however, Windows Phone does not directly support these controls.
2. Multiple mediaelement controls are not supported. If one mediaelement starts playing, the video or audio being played by other mediaelement controls is automatically stopped.
3. attributes such as attributes, attributesproperty, markerreached, markers, and renderedframespersecond are not supported.
4. The entry parameter of the setsource (Stream) function only supports isolatedstoragefilestream. To use the setsource (Stream) function, you must copy the stream to the isolated storage.
5. The canpause and canseek attributes cannot be assigned values.
6. The audiostreamcount and balance attributes always return 1.
7. audiostreamindex returns 0 forever.
For more information, see media for Windows Phone.
The full text cannot be published as it is published in programmer magazine. For the full text, see Silverlight for Windows Phone 7 Development Series (3): multimedia development.