Media​Source Media​Source Media​Source Class

Definition

Some information relates to pre-released product which may be substantially modified before it’s commercially released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Prerelease APIs are identified by a Prerelease label.

Prerelease. 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, IMediaPlaybackSourcepublic sealed class MediaSource : IDisposable, IMediaSource2, IMediaSource3, IMediaSource4, IMediaPlaybackSourcePublic NotInheritable Class MediaSource Implements IDisposable, IMediaSource2, IMediaSource3, IMediaSource4, IMediaPlaybackSource
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

Gets the AdaptiveMediaSource associated with the MediaSource.

public : AdaptiveMediaSource AdaptiveMediaSource { get; }public AdaptiveMediaSource AdaptiveMediaSource { get; }Public ReadOnly Property AdaptiveMediaSource As AdaptiveMediaSource
Attributes
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

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
Value
ValueSet ValueSet ValueSet

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

Attributes

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>
Value
IReference<TimeSpan> Nullable<TimeSpan> Nullable<TimeSpan>

The duration of the content in the MediaSource.

Attributes

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

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>
Attributes

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

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>
Attributes

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

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
Value
PlatForm::Boolean bool bool

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

Attributes

MediaStreamSource MediaStreamSource MediaStreamSource

Gets the MediaStreamSource associated with the MediaSource.

public : MediaStreamSource MediaStreamSource { get; }public MediaStreamSource MediaStreamSource { get; }Public ReadOnly Property MediaStreamSource As MediaStreamSource
Value
MediaStreamSource MediaStreamSource MediaStreamSource

The MediaStreamSource associated with the MediaSource.

Attributes
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

Gets the MseStreamSource associated with the MediaSource.

public : MseStreamSource MseStreamSource { get; }public MseStreamSource MseStreamSource { get; }Public ReadOnly Property MseStreamSource As MseStreamSource
Value
MseStreamSource MseStreamSource MseStreamSource

The MseStreamSource associated with the MediaSource.

Attributes
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

Gets the current state of the MediaSource.

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

Uri Uri Uri

Gets the URI associated with the MediaSource.

public : Uri Uri { get; }public Uri Uri { get; }Public ReadOnly Property Uri As Uri
Value
Uri Uri Uri

The URI associated with the MediaSource.

Attributes
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()

Closes the MediaSource.

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

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
Parameters
Returns

The new media source.

Attributes

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
Parameters
mediaSource
IMediaSource IMediaSource IMediaSource

The IMediaSource from which the MediaSource is created.

Returns

The new media source.

Attributes

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
Parameters
binder
MediaBinder MediaBinder MediaBinder

The MediaBinder with which the MediaSource is associated.

Returns

The new media source.

Attributes
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)

Prerelease. 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
Parameters
Returns

The new media source.

Attributes
Additional features and requirements
Device family
Windows 10 Insider Preview (introduced v10.0.16225.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)

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
Parameters
Returns

The new media source.

Attributes

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
Parameters
mediaSource
MseStreamSource MseStreamSource MseStreamSource

The MediaStreamSource from which the MediaSource is created.

Returns

The new media source.

Attributes

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
Parameters
file
IStorageFile IStorageFile IStorageFile

The IStorageFile from which the MediaSource is created.

Returns

The new media source.

Attributes

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
Parameters
stream
IRandomAccessStream IRandomAccessStream IRandomAccessStream

The stream from which the MediaSource is created.

contentType
PlatForm::String String String

The MIME type of the contents of the stream.

Returns

The new media source.

Attributes

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
Parameters
contentType
PlatForm::String String String

The MIME type of the contents of the stream.

Returns

The new media source.

Attributes

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
Parameters
uri
Uri Uri Uri

The URI from which the MediaSource is created.

Returns

The new media source.

Attributes

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
Attributes

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
Returns

An asynchronous action.

Attributes
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()

Resets the internal state of the MediaSource.

public : void Reset()public void Reset()Public Function Reset() As void
Attributes
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

Occurs when a MediaSource open operation completes.

public : event TypedEventHandler OpenOperationCompletedpublic event TypedEventHandler OpenOperationCompletedPublic Event OpenOperationCompleted
Attributes

StateChanged StateChanged StateChanged

Occurs when the current state of the MediaSource changes.

public : event TypedEventHandler StateChangedpublic event TypedEventHandler StateChangedPublic Event StateChanged
Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10586.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v2)

See Also