MediaStreamSource MediaStreamSource MediaStreamSource MediaStreamSource MediaStreamSource Class

Definition

Represents a media source that delivers media samples directly to the media pipeline.

public : sealed class MediaStreamSource : IMediaSource, IMediaStreamSource, IMediaStreamSource2, IMediaStreamSource3, IMediaStreamSource4
struct winrt::Windows::Media::Core::MediaStreamSource : IMediaSource, IMediaStreamSource, IMediaStreamSource2, IMediaStreamSource3, IMediaStreamSource4
public sealed class MediaStreamSource : IMediaSource, IMediaStreamSource, IMediaStreamSource2, IMediaStreamSource3, IMediaStreamSource4
Public NotInheritable Class MediaStreamSource Implements IMediaSource, IMediaStreamSource, IMediaStreamSource2, IMediaStreamSource3, IMediaStreamSource4
var mediaStreamSource = new mediaStreamSource(descriptor);
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

See the MediaStreamSource Sample for an example of using Media Stream Source in a UWP app.

MediaStreamSource is a new generic media source for UWP apps which is introduced in Windows 8.1. MediaStreamSource allows apps to send compressed or uncompressed audio and video samples to the media pipeline for playback, transcoding, and streaming. Media samples can be dynamically generated by the app, or de-multiplexed from a stream or files. This flexibility enables apps to more easily extend platform support for new media formats or solve complex problems, such as adaptive streaming.

The MediaStreamSource API are very similar to the Microsoft SilverlightAPI of the same name.

MediaStreamSource can be used with audio and video objects in Windows app using JavaScript, MediaElement objects in UWP apps using C++, C#, or Visual Basic, and the MediaTranscoder.

The MediaStreamSource Sample demonstrates how to use the MediaStreamSource. Here are some of the main MediaStreamSource API. The order outlines the basic flow of how MediaStreamSource functions. You'll notice that the MediaStreamSource sends request objects to the app through event arguments. These request objects enable the app to interact with the MediaStreamSource and pass data back to it.

APIDescription
MediaStreamSource Represents a media source that delivers media samples directly to the media pipeline. MediaStreamSource consumes MediaStreamSample objects that are provided by the application.
MediaStreamSample Represents a media sample used by the MediaStreamSource.
MediaStreamSource.Starting (event)The MediaStreamSource uses this event to notify the app that it is ready to start processing media data.
MediaStreamSourceStartingRequest Represents a request from the MediaStreamSource that it is ready to start processing media data. Apps should reply as soon as possible to this request by calling SetActualStartPosition on the request. If an app needs to delay the MediaStreamSource from processing data, it can get an asynchronous deferral from MediaStreamSourceStartingRequest.GetDeferral. When the app is ready for the MediaStreamSource to start, it calls Complete on the deferral object. The starting request is accessed through the MediaStreamSourceStartingEventArgs that are passed to the MediaStreamSource.Starting event handler.
MediaStreamSource.SampleRequested (event)The MediaStreamSource uses this event to notify the app that it is ready for a MediaStreamSample. Apps are required to register a handler for this event.
MediaStreamSourceSampleRequest Represents a request from the MediaStreamSource for a new media sample. Setting the Sample property to the new MediaStreamSample triggers the MediaStreamSource to retrieve the media sample and continue processing the media data. Apps should reply as soon as possible to this request. If an app needs time before sending the MediaStreamSample, it can get an asynchronous deferral from MediaStreamSourceSampleRequest.GetDeferral. When the app is finished with the deferral, it calls Complete on the deferral object. The sample request is accessed through the MediaStreamSourceSampleRequestedEventArgs that are passed to the MediaStreamSource.SampleRequest event handler. The app indicates it has reached the end of the stream by responding to a MediaStreamSourceSampleRequest without providing a MediaStreamSample, or by assigning the MediaStreamSourceSampleRequest.Sample property to null.
MediaStreamSource.Closed (event)The MediaStreamSource uses this event to notify the app that it has shut down.
MediaStreamSourceClosedRequest Represents a request from the MediaStreamSource that it has closed. The close request is accessed through the MediaStreamSourceClosedEventArgs that are passed to the MediaStreamSource.Closed event handler.
MediaElement.SetMediaStreamSource Sets the source of the MediaElement to a MediaStreamSource.

Constructors

MediaStreamSource(IMediaStreamDescriptor) MediaStreamSource(IMediaStreamDescriptor) MediaStreamSource(IMediaStreamDescriptor) MediaStreamSource(IMediaStreamDescriptor) MediaStreamSource(IMediaStreamDescriptor)

Creates an instance of MediaStreamSource from the specified IMediaStreamDescriptor.

MediaStreamSource(IMediaStreamDescriptor, IMediaStreamDescriptor) MediaStreamSource(IMediaStreamDescriptor, IMediaStreamDescriptor) MediaStreamSource(IMediaStreamDescriptor, IMediaStreamDescriptor) MediaStreamSource(IMediaStreamDescriptor, IMediaStreamDescriptor) MediaStreamSource(IMediaStreamDescriptor, IMediaStreamDescriptor)

Creates an instance of MediaStreamSource from two IMediaStreamDescriptor objects.

Properties

BufferTime BufferTime BufferTime BufferTime BufferTime

Gets or sets the amount of data that is buffered by the MediaStreamSource.

CanSeek CanSeek CanSeek CanSeek CanSeek

Gets or sets whether or not the application supports changing its position in the media time-line.

Duration Duration Duration Duration Duration

Gets or sets the duration of the media time-line.

IsLive IsLive IsLive IsLive IsLive

Gets or sets a value indicating whether the media content being processed is live.

MaxSupportedPlaybackRate MaxSupportedPlaybackRate MaxSupportedPlaybackRate MaxSupportedPlaybackRate MaxSupportedPlaybackRate

Gets the maxiumum supported playback rate for the MediaStreamSource.

MediaProtectionManager MediaProtectionManager MediaProtectionManager MediaProtectionManager MediaProtectionManager

Gets or sets the Digital Rights Management (DRM)MediaProtectionManager used to protect the media.

MusicProperties MusicProperties MusicProperties MusicProperties MusicProperties

Gets the music properties which are used for music-related metadata.

Thumbnail Thumbnail Thumbnail Thumbnail Thumbnail

Gets or sets the thumbnail which is a reference to a stream for a video thumbnail image or music album art.

VideoProperties VideoProperties VideoProperties VideoProperties VideoProperties

Gets the video properties which are used for video related metadata.

Methods

AddProtectionKey(IMediaStreamDescriptor, Byte[], Byte[]) AddProtectionKey(IMediaStreamDescriptor, Byte[], Byte[]) AddProtectionKey(IMediaStreamDescriptor, Byte[], Byte[]) AddProtectionKey(IMediaStreamDescriptor, Byte[], Byte[]) AddProtectionKey(IMediaStreamDescriptor, Byte[], Byte[])

Adds a Digital Rights Management (DRM) protection key which is used by the MediaProtectionManager to encrypt and decrypt the specified stream.

AddStreamDescriptor(IMediaStreamDescriptor) AddStreamDescriptor(IMediaStreamDescriptor) AddStreamDescriptor(IMediaStreamDescriptor) AddStreamDescriptor(IMediaStreamDescriptor) AddStreamDescriptor(IMediaStreamDescriptor)

Adds a new stream descriptor to the MediaStreamSource.

NotifyError(MediaStreamSourceErrorStatus) NotifyError(MediaStreamSourceErrorStatus) NotifyError(MediaStreamSourceErrorStatus) NotifyError(MediaStreamSourceErrorStatus) NotifyError(MediaStreamSourceErrorStatus)

Notifies the MediaStreamSource that an error has occurred which is preventing the application from continuing to deliver data to the MediaStreamSource.

SetBufferedRange(TimeSpan, TimeSpan) SetBufferedRange(TimeSpan, TimeSpan) SetBufferedRange(TimeSpan, TimeSpan) SetBufferedRange(TimeSpan, TimeSpan) SetBufferedRange(TimeSpan, TimeSpan)

Sets the range of data that the application is currently buffering.

Events

Closed Closed Closed Closed Closed

Occurs when the MediaStreamSource is shutting down.

Paused Paused Paused Paused Paused

Occurs when the MediaStreamSource is paused and stops requesting MediaStreamSample objects for an unspecified period of time, but is expected to resume requesting MediaStreamSample objects from the current position.

SampleRendered SampleRendered SampleRendered SampleRendered SampleRendered

Occurs when a sample from the MediaStreamSource is rendered.

SampleRequested SampleRequested SampleRequested SampleRequested SampleRequested

Occurs when the MediaStreamSource request a MediaStreamSample for a specified stream.

Starting Starting Starting Starting Starting

Occurs when the MediaStreamSource is ready to start requesting MediaStreamSample objects. The event can specify a position in the media time-line from which the first MediaStreamSample should be delivered.

SwitchStreamsRequested SwitchStreamsRequested SwitchStreamsRequested SwitchStreamsRequested SwitchStreamsRequested

Occurs when the MediaStreamSource will stop requesting MediaStreamSample objects for a certain stream and will start requesting MediaStreamSample objects from a different stream instead.

See Also