Jaa


MediaStreamSource Class

Definition

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

public ref class MediaStreamSource sealed
/// [Windows.Foundation.Metadata.Activatable(Windows.Media.Core.IMediaStreamSourceFactory, 65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class MediaStreamSource final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.Activatable(Windows.Media.Core.IMediaStreamSourceFactory, 65536, "Windows.Foundation.UniversalApiContract")]
class MediaStreamSource final
[Windows.Foundation.Metadata.Activatable(typeof(Windows.Media.Core.IMediaStreamSourceFactory), 65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class MediaStreamSource
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.Activatable(typeof(Windows.Media.Core.IMediaStreamSourceFactory), 65536, "Windows.Foundation.UniversalApiContract")]
public sealed class MediaStreamSource
function MediaStreamSource(descriptor, descriptor2)
Public NotInheritable Class MediaStreamSource
Inheritance
Object Platform::Object IInspectable MediaStreamSource
Attributes
Implements

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

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 MediaStreamSourceAPI 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.

API Description
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.

Version history

Windows version SDK version Value added
1607 14393 SampleRendered
1703 15063 MaxSupportedPlaybackRate
1709 16299 IsLive

Constructors

MediaStreamSource(IMediaStreamDescriptor, IMediaStreamDescriptor)

Creates an instance of MediaStreamSource from two IMediaStreamDescriptor objects.

MediaStreamSource(IMediaStreamDescriptor)

Creates an instance of MediaStreamSource from the specified IMediaStreamDescriptor.

Properties

BufferTime

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

CanSeek

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

Duration

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

IsLive

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

MaxSupportedPlaybackRate

Gets the maxiumum supported playback rate for the MediaStreamSource.

MediaProtectionManager

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

MusicProperties

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

Thumbnail

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

VideoProperties

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

Methods

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)

Adds a new stream descriptor to the MediaStreamSource.

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)

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

Events

Closed

Occurs when the MediaStreamSource is shutting down.

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

Occurs when a sample from the MediaStreamSource is rendered.

SampleRequested

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

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

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

Applies to

See also