MediaSource MediaSource MediaSource MediaSource Class

Definition

Represents a media source. Provides a common way to reference media from different sources and exposes a common model for accessing media data regardless of the underlying media format.

public : sealed class MediaSource : IClosable, IMediaSource2, IMediaSource3, IMediaSource4, IMediaPlaybackSource
public sealed class MediaSource : IDisposable, IMediaSource2, IMediaSource3, IMediaSource4, IMediaPlaybackSource
Public NotInheritable Class MediaSource Implements IDisposable, IMediaSource2, IMediaSource3, IMediaSource4, IMediaPlaybackSource
// This class does not provide a public constructor.
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

Using one of the factory methods, you can create an instance of MediaSource from many different media source representations, including:

After getting a MediaSource instance, create a new MediaPlaybackItem wrapping the media source and pass the MediaPlaybackItem to one of the media playback objects, such as MediaPlayer or MediaElement.

For how-to guidance for using MediaSource to play back media, see Media items, playlists, and tracks.

Properties

AdaptiveMediaSource AdaptiveMediaSource AdaptiveMediaSource AdaptiveMediaSource

Gets the AdaptiveMediaSource associated with the MediaSource.

public : AdaptiveMediaSource AdaptiveMediaSource { get; }
public AdaptiveMediaSource AdaptiveMediaSource { get; }
Public ReadOnly Property AdaptiveMediaSource As AdaptiveMediaSource
var adaptiveMediaSource = mediaSource.adaptiveMediaSource;
Additional features and requirements
Device family
Windows 10 Creators Update (introduced v10.0.15063.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v4)

Remarks

If the MediaSource does not have an associated AdaptiveMediaSource, this property value is null.

CustomProperties CustomProperties CustomProperties CustomProperties

Gets a set of properties that can be used to associate app-specific data with a MediaSource.

public : ValueSet CustomProperties { get; }
public ValueSet CustomProperties { get; }
Public ReadOnly Property CustomProperties As ValueSet
var valueSet = mediaSource.customProperties;
Value
ValueSet ValueSet ValueSet ValueSet

A set of properties that can be used to associate app-specific data with a MediaSource.

Duration Duration Duration Duration

Gets the duration of the content in the MediaSource.

public : IReference<TimeSpan> Duration { get; }
public Nullable<TimeSpan> Duration { get; }
Public ReadOnly Property Duration As Nullable<TimeSpan>
var nullable = mediaSource.duration;
Value
IReference<TimeSpan> Nullable<TimeSpan> Nullable<TimeSpan> Nullable<TimeSpan>

The duration of the content in the MediaSource.

Remarks

Adaptive sources can support multiple periods or discontinuities that contribute to the overall presentation timeline. The Duration property represents this complete presentation timeline.

ExternalTimedMetadataTracks ExternalTimedMetadataTracks ExternalTimedMetadataTracks ExternalTimedMetadataTracks

A collection of external timed metadata tracks associated with the MediaSource.

public : IObservableVector<TimedMetadataTrack> ExternalTimedMetadataTracks { get; }
public IObservableVector<TimedMetadataTrack> ExternalTimedMetadataTracks { get; }
Public ReadOnly Property ExternalTimedMetadataTracks As IObservableVector<TimedMetadataTrack>
var iObservableVector = mediaSource.externalTimedMetadataTracks;

Remarks

You can generate TimedMetadataTrack objects in code and add them to this collection directly, or you can create a TimedTextSource from a URL or stream and use the ExternalTimedTextSources property to populate the collection.

ExternalTimedTextSources ExternalTimedTextSources ExternalTimedTextSources ExternalTimedTextSources

A collection of external timed text sources associated with the MediaSource.

public : IObservableVector<TimedTextSource> ExternalTimedTextSources { get; }
public IObservableVector<TimedTextSource> ExternalTimedTextSources { get; }
Public ReadOnly Property ExternalTimedTextSources As IObservableVector<TimedTextSource>
var iObservableVector = mediaSource.externalTimedTextSources;

Remarks

You can create a TimedTextSource from a URL or stream and then set this property to populate the ExternalTimedMetadataTracks collection, or you can generate TimedMetadataTrack objects in code and add them to tthe ExternalTimedMetadataTracks collection directly.

IsOpen IsOpen IsOpen IsOpen

Gets a value indicating whether the media source is currently open.

public : Platform::Boolean IsOpen { get; }
public bool IsOpen { get; }
Public ReadOnly Property IsOpen As bool
var bool = mediaSource.isOpen;
Value
Platform::Boolean bool bool bool

True if the media source is open; otherwise, false.

MediaStreamSource MediaStreamSource MediaStreamSource MediaStreamSource

Gets the MediaStreamSource associated with the MediaSource.

public : MediaStreamSource MediaStreamSource { get; }
public MediaStreamSource MediaStreamSource { get; }
Public ReadOnly Property MediaStreamSource As MediaStreamSource
var mediaStreamSource = mediaSource.mediaStreamSource;
Additional features and requirements
Device family
Windows 10 Creators Update (introduced v10.0.15063.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v4)

Remarks

If the MediaSource does not have an associated MediaStreamSource, this property value is null.

MseStreamSource MseStreamSource MseStreamSource MseStreamSource

Gets the MseStreamSource associated with the MediaSource.

public : MseStreamSource MseStreamSource { get; }
public MseStreamSource MseStreamSource { get; }
Public ReadOnly Property MseStreamSource As MseStreamSource
var mseStreamSource = mediaSource.mseStreamSource;
Additional features and requirements
Device family
Windows 10 Creators Update (introduced v10.0.15063.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v4)

Remarks

If the MediaSource does not have an associated MseStreamSource, this property value is null.

State State State State

Gets the current state of the MediaSource.

public : MediaSourceState State { get; }
public MediaSourceState State { get; }
Public ReadOnly Property State As MediaSourceState
var mediaSourceState = mediaSource.state;
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10586.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v2)

Uri Uri Uri Uri

Gets the URI associated with the MediaSource.

public : Uri Uri { get; }
public Uri Uri { get; }
Public ReadOnly Property Uri As Uri
var uri = mediaSource.uri;
Value
Uri Uri Uri Uri

The URI associated with the MediaSource.

Additional features and requirements
Device family
Windows 10 Creators Update (introduced v10.0.15063.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v4)

Methods

Close() Close() Close() Close()

Closes the MediaSource.

public : void Close()
This member is not implemented in C#
This member is not implemented in VB.Net
// This member is not implemented in JavaScript

CreateFromAdaptiveMediaSource(AdaptiveMediaSource) CreateFromAdaptiveMediaSource(AdaptiveMediaSource) CreateFromAdaptiveMediaSource(AdaptiveMediaSource) CreateFromAdaptiveMediaSource(AdaptiveMediaSource)

Creates an instance of MediaSource from the provided AdaptiveMediaSource.

public : static MediaSource CreateFromAdaptiveMediaSource(AdaptiveMediaSource mediaSource)
public static MediaSource CreateFromAdaptiveMediaSource(AdaptiveMediaSource mediaSource)
Public Static Function CreateFromAdaptiveMediaSource(mediaSource As AdaptiveMediaSource) As MediaSource
var mediaSource = Windows.Media.Core.MediaSource.createFromAdaptiveMediaSource(mediaSource);
Parameters
Returns

CreateFromIMediaSource(IMediaSource) CreateFromIMediaSource(IMediaSource) CreateFromIMediaSource(IMediaSource) CreateFromIMediaSource(IMediaSource)

Creates an instance of MediaSource from the provided IMediaSource.

public : static MediaSource CreateFromIMediaSource(IMediaSource mediaSource)
public static MediaSource CreateFromIMediaSource(IMediaSource mediaSource)
Public Static Function CreateFromIMediaSource(mediaSource As IMediaSource) As MediaSource
var mediaSource = Windows.Media.Core.MediaSource.createFromIMediaSource(mediaSource);
Parameters
mediaSource
IMediaSource IMediaSource IMediaSource IMediaSource

The IMediaSource from which the MediaSource is created.

Returns

CreateFromMediaBinder(MediaBinder) CreateFromMediaBinder(MediaBinder) CreateFromMediaBinder(MediaBinder) CreateFromMediaBinder(MediaBinder)

Creates an instance of MediaSource from the provided MediaBinder.

public : static MediaSource CreateFromMediaBinder(MediaBinder binder)
public static MediaSource CreateFromMediaBinder(MediaBinder binder)
Public Static Function CreateFromMediaBinder(binder As MediaBinder) As MediaSource
var mediaSource = Windows.Media.Core.MediaSource.createFromMediaBinder(binder);
Parameters
binder
MediaBinder MediaBinder MediaBinder MediaBinder

The MediaBinder with which the MediaSource is associated.

Returns
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10586.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v2)

CreateFromMediaFrameSource(MediaFrameSource) CreateFromMediaFrameSource(MediaFrameSource) CreateFromMediaFrameSource(MediaFrameSource) CreateFromMediaFrameSource(MediaFrameSource)

Creates an instance of MediaSource from the provided AdaptiveMediaSource.

public : static MediaSource CreateFromMediaFrameSource(MediaFrameSource frameSource)
public static MediaSource CreateFromMediaFrameSource(MediaFrameSource frameSource)
Public Static Function CreateFromMediaFrameSource(frameSource As MediaFrameSource) As MediaSource
var mediaSource = Windows.Media.Core.MediaSource.createFromMediaFrameSource(frameSource);
Parameters
Returns
Additional features and requirements
Device family
Windows 10 Fall Creators Update (introduced v10.0.16299.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v5)

Remarks

For more information on using media frame sources, see Process media frames with MediaFrameReader.

CreateFromMediaStreamSource(MediaStreamSource) CreateFromMediaStreamSource(MediaStreamSource) CreateFromMediaStreamSource(MediaStreamSource) CreateFromMediaStreamSource(MediaStreamSource)

Creates an instance of MediaSource from the provided MediaStreamSource.

public : static MediaSource CreateFromMediaStreamSource(MediaStreamSource mediaSource)
public static MediaSource CreateFromMediaStreamSource(MediaStreamSource mediaSource)
Public Static Function CreateFromMediaStreamSource(mediaSource As MediaStreamSource) As MediaSource
var mediaSource = Windows.Media.Core.MediaSource.createFromMediaStreamSource(mediaSource);
Parameters
Returns

CreateFromMseStreamSource(MseStreamSource) CreateFromMseStreamSource(MseStreamSource) CreateFromMseStreamSource(MseStreamSource) CreateFromMseStreamSource(MseStreamSource)

Creates an instance of MediaSource from the provided MseStreamSource.

public : static MediaSource CreateFromMseStreamSource(MseStreamSource mediaSource)
public static MediaSource CreateFromMseStreamSource(MseStreamSource mediaSource)
Public Static Function CreateFromMseStreamSource(mediaSource As MseStreamSource) As MediaSource
var mediaSource = Windows.Media.Core.MediaSource.createFromMseStreamSource(mediaSource);
Parameters
Returns

CreateFromStorageFile(IStorageFile) CreateFromStorageFile(IStorageFile) CreateFromStorageFile(IStorageFile) CreateFromStorageFile(IStorageFile)

Creates an instance of MediaSource from the provided IStorageFile.

public : static MediaSource CreateFromStorageFile(IStorageFile file)
public static MediaSource CreateFromStorageFile(IStorageFile file)
Public Static Function CreateFromStorageFile(file As IStorageFile) As MediaSource
var mediaSource = Windows.Media.Core.MediaSource.createFromStorageFile(file);
Parameters
Returns

CreateFromStream(IRandomAccessStream, String) CreateFromStream(IRandomAccessStream, String) CreateFromStream(IRandomAccessStream, String) CreateFromStream(IRandomAccessStream, String)

Creates an instance of MediaSource from the provided IRandomAccessStream.

public : static MediaSource CreateFromStream(IRandomAccessStream stream, Platform::String contentType)
public static MediaSource CreateFromStream(IRandomAccessStream stream, String contentType)
Public Static Function CreateFromStream(stream As IRandomAccessStream, contentType As String) As MediaSource
var mediaSource = Windows.Media.Core.MediaSource.createFromStream(stream, contentType);
Parameters
contentType
Platform::String String String String

The MIME type of the contents of the stream.

Returns

CreateFromStreamReference(IRandomAccessStreamReference, String) CreateFromStreamReference(IRandomAccessStreamReference, String) CreateFromStreamReference(IRandomAccessStreamReference, String) CreateFromStreamReference(IRandomAccessStreamReference, String)

Creates an instance of MediaSource from the provided IRandomAccessStreamReference.

public : static MediaSource CreateFromStreamReference(IRandomAccessStreamReference stream, Platform::String contentType)
public static MediaSource CreateFromStreamReference(IRandomAccessStreamReference stream, String contentType)
Public Static Function CreateFromStreamReference(stream As IRandomAccessStreamReference, contentType As String) As MediaSource
var mediaSource = Windows.Media.Core.MediaSource.createFromStreamReference(stream, contentType);
Parameters
contentType
Platform::String String String String

The MIME type of the contents of the stream.

Returns

CreateFromUri(Uri) CreateFromUri(Uri) CreateFromUri(Uri) CreateFromUri(Uri)

Creates an instance of MediaSource from the provided Uri.

public : static MediaSource CreateFromUri(Uri uri)
public static MediaSource CreateFromUri(Uri uri)
Public Static Function CreateFromUri(uri As Uri) As MediaSource
var mediaSource = Windows.Media.Core.MediaSource.createFromUri(uri);
Parameters
uri
Uri Uri Uri Uri

The URI from which the MediaSource is created.

Returns

Dispose() Dispose() Dispose() Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

// This member is not implemented in C++
void Dispose()
Sub Dispose
// This member is not implemented in Javascript

OpenAsync() OpenAsync() OpenAsync() OpenAsync()

opens the backing data source for the MediaSource and reads the metadata and track information.

public : IAsyncAction OpenAsync()
public IAsyncAction OpenAsync()
Public Function OpenAsync() As IAsyncAction
Windows.Media.Core.MediaSource.openAsync().done( /* Your success and error handlers */ );
Returns
Additional features and requirements
Device family
Windows 10 Creators Update (introduced v10.0.15063.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v4)

Remarks

This method can be called to preload the associated media for performance reasons or to verify that the media loads successfully.

Reset() Reset() Reset() Reset()

Resets the internal state of the MediaSource.

public : void Reset()
public void Reset()
Public Function Reset() As void
mediaSource.reset();
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10586.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v2)

Remarks

After Reset is called, the MediaSource will be reopened the next time it is used.

Events

OpenOperationCompleted OpenOperationCompleted OpenOperationCompleted OpenOperationCompleted

Occurs when a MediaSource open operation completes.

public : event TypedEventHandler OpenOperationCompleted<MediaSource, MediaSourceOpenOperationCompletedEventArgs>
public event TypedEventHandler OpenOperationCompleted<MediaSource, MediaSourceOpenOperationCompletedEventArgs>
Public Event TypedEventHandler OpenOperationCompleted( Of ( Of MediaSource ), ( Of MediaSourceOpenOperationCompletedEventArgs ))
function onOpenOperationCompleted(eventArgs){/* Your code */}


mediaSource.addEventListener("openOperationCompleted", onOpenOperationCompleted);
mediaSource.removeEventListener("openOperationCompleted", onOpenOperationCompleted);

StateChanged StateChanged StateChanged StateChanged

Occurs when the current state of the MediaSource changes.

public : event TypedEventHandler StateChanged<MediaSource, MediaSourceStateChangedEventArgs>
public event TypedEventHandler StateChanged<MediaSource, MediaSourceStateChangedEventArgs>
Public Event TypedEventHandler StateChanged( Of ( Of MediaSource ), ( Of MediaSourceStateChangedEventArgs ))
function onStateChanged(eventArgs){/* Your code */}


mediaSource.addEventListener("stateChanged", onStateChanged);
mediaSource.removeEventListener("stateChanged", onStateChanged);
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10586.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v2)

See Also