Share via


Media in Silverlight for Windows Phone

Microsoft Silverlight will reach end of support after October 2021. Learn more.

This topic describes differences in support for media in Silverlight for the desktop and Silverlight for Windows Phone.

Silverlight media support on Windows Phone is based on the native media stack used on Windows Phone. Supported frame rates are typically lower than those available on desktop computers.

The following media features are not supported in Silverlight for Windows Phone:

  • Client-side and server-side playlists

  • Streaming from a Windows Media server that is running Windows Media Services.

Silverlight for Windows Phone supports PlayReady Digital Rights Management (DRM) and provides DRM support equivalent to Silverlight. However, unlike Silverlight, Silverlight for Windows Phone also supports playing downloaded PlayReady protected media in offline mode. Windows Phone supports persistent licenses; if a license issuer issues a persistent license, the license is automatically stored locally on the device and is then available for playback. For additional information, see Digital Rights Management (Silverlight 3) and Digital Rights Management (DRM).

For additional information on media in Silverlight and supported codecs on Windows Phone, see Audio and Video and Supported Codecs on Windows Phone.

Displaying Lists of Media

In Windows Phone OS 7.1, scrolling performance was improved. However, if you display several images and media in a list, you might notice issues with scrolling. In some cases, the list may scroll faster than the images or media files can load, causing flickering in the UI. If this occurs consider loading the images or media on a background thread. Make sure that you test the scrolling behavior on a Windows Phone device.

WriteableBitmap

In, Windows Phone OS 7.1, when you specify a BitmapImage as the parameter for the WriteableBitmap constructor, you must set the CreateOptions property of the BitmapImage before you use it to construct the WriteableBitmap; otherwise, an exception will occur.

MediaElement Support

MediaElement renders video at the original encoded resolution of the video, but you can override that by explicitly setting the Height, Width, and Stretch properties. Full screen mode is not supported on Windows Phone, but you can use the full screen to display video by setting the height and width of the MediaElement to the size of the application.

While playing, a MediaElement stops all other media playback on the phone.

If you attempt to play an unsupported format on a device, a MediaFailed event occurs.

NoteNote:

A media file with the incorrect file extension, or a missing file extension, will not play back. The file extension must match the encoded source.

Important noteImportant Note:

When you add MediaElement in XAML code, always name the MediaElement. Otherwise, the Media Library security capability is not granted during submission to Windows Marketplace. For more information, see Security for Windows Phone.

Because MediaElement is rendered entirely in hardware, it does not appear in WriteableBitmap captures.

The following features of MediaElement are not supported in Silverlight for Windows Phone:

Using MediaStreamSource

When using MediaStreamSource, the following programming practices are recommended:

  • When using GetSampleAsync(MediaStreamType), either report the next sample immediately or report the next sample from a background thread when it becomes available.

  • Implement read-ahead sample buffering. Use ReportGetSampleProgress(Double) to inform MediaElement when buffering is in progress.

  • Set the MediaElement source to null before setting a new source.

  • When you implement a MediaStreamSource to contain both audio and video, but the media source is missing one of the streams, playback from all streams will stop. In this case, you may need to provide mock frames for the missing stream to continue playback.

It may also be necessary to set CodecPrivateData for some codecs when calling ReportOpenMediaCompleted(IDictionary<MediaSourceAttributesKeys, String>, IEnumerable<MediaStreamDescription>). For an audio stream, CodecPrivateData is a WAVEFORMATEX structure expressed in hexadecimal format, and it may include codec-specific data at the end. For a video stream, CodecPrivateData is the codec-specific initialization data which is normally present after the BITMAPINFOHEADER structure in a Windows program. Windows Phone supports some values for CodecPrivateData that are not supported on other platforms. When setting CodecPrivateData, try to use settings that work on both Windows Phone and on other platforms. Additional information may be available here. A few examples of settings that work on both Windows Phone and other platforms include:

  • For HE-AAC, CodecPrivateData should be a WAVEFORMATEX expressed as a little-endian byte array in hexadecimal format. WAVEFORMATEX::wFormatTag should be 0xFF. WAVEFORMATEX::nSamplesPerSecond should be pre-SBR (Spectral Band Replication) and WAVEFORMATEX::nChannels should be pre-PS (Parametric Stereo).

    NoteNote:

    WAVEFORMATEX::wFormatTag set to 0x1610 may work on Windows Phone but does not work on some platforms.

    For example, for HE-AAC v2 and 48kHz stereo content (SBR and PS enabled), the value is CodecPrivateData=“FF000100C05D0000E02E0000040010000500130856E598”

  • For WMA, CodecPrivateData should be a WMAUDIO3WAVEFORMAT expressed as a little-endian byte array in hexadecimal format. For example, WMAv3 with 44.1kHz stereo output, the value is: CodecPrivateData=“6201020044AC0000451F0000CF05100012001000030000000000000000000000E00042C0”

  • For VC-1, CodecPrivateData should be a byte array in hexadecimal format and uses the following format:

    [start code][ Sequence Header][ start code][ EntryPointHeader]
    

    where [start code] consists of the following three bytes: 0x00, 0x00, 0x01. An example of VC-1 at 1280x720 resolution and 2436000 bps is CodecPrivateData="250000010FD3BE27F1678A27F859E80450824A56DCECC00000010E5A67F840"

  • For H.264, CodecPrivateData is a byte array in hexadecimal format and uses the following format:

    [start code][ Sequence Parameter Set][ start code][ Picture Parameter Set]
    

    where [start code] consists of the following four bytes: 0x00, 0x00, 0x00, 0x01. For example, H.264 at 1000000 bps and 640x360 resolution, the value is CodecPrivateData=”00000001674D401E965201405FF2E020100000000168EF3880”

The following table shows the maximum recommended resolution and FPS for video playback on Windows Phone. For the complete list of supported codecs on Windows Phone, see Supported Codecs on Windows Phone.

Decoder

Max Resolution

Max FPS

H.263

800x480

30

WMV - Simple Profile (VC-1)

800x600

30

WMV - Main Profile (VC-1)

800x600

30

WMV - Advanced Profile (VC-1)

800x600

30

MPEG-4 Part 2 - Simple Profile

800x600 (720p for HD capture devices)

30

MPEG-4 Part 10 (MPEG-4 AVC, H.264) Level 3.0 - Baseline Profile

720x480 @  30fps

720×576 @ 25fps

25/30

MPEG-4 Part 10 (MPEG-4 AVC, H.264) Level 3.0  - Main Profile

720x480 @  30fps

720×576 @ 25fps

25/30

MPEG-4 Part 10 (MPEG-4 AVC, H.264) Level 3.0  – High Profile

720x480 @  30fps

720×576 @ 25fps

25/30

See Also

Other Resources