SetSource method
TOC
Collapse the table of content
Expand the table of content

MediaElement.SetSource method

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 x: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();

    // mediaControl is a MediaElement defined in XAML
    if (null != file)
    {
        var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
        mediaControl.SetSource(stream, file.ContentType);
        mediaControl.Play();
    }
}


Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

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

Metadata

Windows.Foundation.UniversalApiContract.winmd

Requirements (Windows 8.x and Windows Phone 8.x)

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
Audio, video, and camera
Create custom transport controls
MediaElement
Other resources
Supported audio and video formats

 

 

Show:
© 2017 Microsoft