Expand Minimize

MediaElement.SetSource method

Applies to Windows and Windows Phone

Sets the Source property using the specified stream and MIME type.

Syntax


public void SetSource(
  IRandomAccessStream stream, 
  string mimeType
)

Parameters

stream

Type: IRandomAccessStream

The stream that contains the media to load.

mimeType

Type: System.String [.NET] | Platform::String [C++]

The MIME type of the media resource, expressed as the string form typically seen in HTTP headers and requests. The empty string "" can be passed in as the mimeType value if the MIME type is unknown.

Remarks

You can use the FileOpenPicker control to get the file stream for a media file on the local system.

Examples

Here is some code that creates MediaElement object and sets the media source using a FileOpenPicker control.


<MediaElement Name="mediaControl" Height="400" />



async private void SetLocalMedia()
{
    var openPicker = new Windows.Storage.Pickers.FileOpenPicker();

    openPicker.FileTypeFilter.Add(".wmv");
    openPicker.FileTypeFilter.Add(".mp4");
    openPicker.FileTypeFilter.Add(".wma");
    openPicker.FileTypeFilter.Add(".mp3");

    var file = await openPicker.PickSingleFileAsync();

    var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

    // mediaControl is a MediaElement defined in XAML
    if (null != file)
    {
        mediaControl.SetSource(stream, file.ContentType);

        mediaControl.Play();
    }
}


Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.UI.Xaml.Controls
Windows::UI::Xaml::Controls [C++]

Metadata

Windows.winmd

See also

MediaElement
Tasks
Quickstart: video and audio
Quickstart: create custom transport controls
How to open local media files using the FileOpenPicker control
How to play media files from the network
Other resources
Supported audio and video formats

 

 

Show:
© 2014 Microsoft