Chapter 19. Playing Music and Videos

Windows Phone 7 provides the Music + Videos hub for playing videos, songs, and playlists. For video you can use the MediaElement control to imbed video within your application. Windows Phone 7 also comes with a built-in FM radio receiver, which enables you to listen to radio stations.

PLAYING VIDEOS

In Lesson 14 you learned how to use the MediaPlayerLauncher to play videos using the Windows Media Player. When you use the Windows Media Player to play a video, you are launching the player and deactivating your application while the player plays the video. To play the video without deactivating your application, you can add a MediaElement control to your page and play the video within the MediaElement control. MediaElement supports playing videos from a remote server as well as playing videos located on the phone.

Adding and Configuring the MediaElement Control

To add a MediaElement control to a page, drag the MediaElement icon from the Toolbox onto the page:

<MediaElement Height="120" HorizontalAlignment="Left" Margin="309,532,0,0"
 Name="mediaElement1" VerticalAlignment="Top" Width="160" />

By default, when a MediaElement control is added to a page the Height property is set to 120 pixels and the Width property to 160 as shown in Figure 19-1.

While you could set the height and width to static values, if the size of the video played in the MediaElement is less than the size of the control, the video will experience some pixilation when played. To ensure ...

Get Windows® Phone 7 Application Development 24-Hour Trainer now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.