Class MediaStream
Represents a stream of media content.
Implements
Inherited Members
Namespace: Unity.WebRTC
Assembly: Unity.WebRTC.dll
Syntax
public class MediaStream : RefCountedObject, IDisposable
Remarks
MediaStream
represents a stream of media content.
A stream consists of several tracks, such as video or audio tracks.
Each track is specified as an instance of MediaStreamTrack
.
Examples
MediaStream mediaStream = new MediaStream();
Constructors
MediaStream()
Creates a MediaStream instance.
Declaration
public MediaStream()
Remarks
MediaStream
constructor creates an instance of MediaStream
,
which serves as a collection of media tracks,
each represented by a MediaStreamTrack
object.
Examples
MediaStream mediaStream = new MediaStream();
See Also
Properties
Id
String containing 36 characters denoting a unique identifier for the object.
Declaration
public string Id { get; }
Property Value
Type | Description |
---|---|
string |
See Also
OnAddTrack
Delegate to be called when a new MediaStreamTrack object has been added.
Declaration
public DelegateOnAddTrack OnAddTrack { get; set; }
Property Value
Type | Description |
---|---|
DelegateOnAddTrack |
See Also
OnRemoveTrack
Delegate to be called when a new MediaStreamTrack object has been removed.
Declaration
public DelegateOnRemoveTrack OnRemoveTrack { get; set; }
Property Value
Type | Description |
---|---|
DelegateOnRemoveTrack |
See Also
Methods
AddTrack(MediaStreamTrack)
Add a new track to the stream.
Declaration
public bool AddTrack(MediaStreamTrack track)
Parameters
Type | Name | Description |
---|---|---|
MediaStreamTrack | track |
|
Returns
Type | Description |
---|---|
bool |
|
Remarks
AddTrack
method adds a new track to the stream.
This class keeps references of MediaStreamTrack to avoid GC.
Please call the RemoveTrack(MediaStreamTrack) method when it's no longer needed.
Examples
MediaStream receiveStream = new MediaStream();
peerConnection.OnTrack = e =>
{
bool result = receiveStream.AddTrack(e.Track);
}
See Also
Dispose()
Disposes of MediaStream.
Declaration
public override void Dispose()
Overrides
Remarks
Dispose
method disposes of the MediaStream and releases the associated resources.
Examples
mediaStream.Dispose();
See Also
~MediaStream()
Finalizer for MediaStream.
Declaration
protected ~MediaStream()
Remarks
Ensures that resources are released by calling the Dispose
method.
See Also
GetAudioTracks()
Returns a list of AudioStreamTrack objects in the stream.
Declaration
public IEnumerable<AudioStreamTrack> GetAudioTracks()
Returns
Type | Description |
---|---|
IEnumerable<AudioStreamTrack> | List of |
Remarks
GetAudioTracks
method returns a sequence that represents all the AudioStreamTrack
objects in this stream's track set.
Examples
IEnumerable<AudioStreamTrack> audioTracks = mediaStream.GetAudioTracks();
See Also
GetTracks()
Returns a list of MediaStreamTrack objects in the stream.
Declaration
public IEnumerable<MediaStreamTrack> GetTracks()
Returns
Type | Description |
---|---|
IEnumerable<MediaStreamTrack> | List of |
Remarks
GetTracks
method returns a sequence that represents all the MediaStreamTrack
objects in this stream's track set.
Examples
IEnumerable<MediaStreamTrack> tracks = mediaStream.GetTracks();
See Also
GetVideoTracks()
Returns a list of VideoStreamTrack objects in the stream.
Declaration
public IEnumerable<VideoStreamTrack> GetVideoTracks()
Returns
Type | Description |
---|---|
IEnumerable<VideoStreamTrack> | List of |
Remarks
GetVideoTracks
method returns a sequence that represents all the VideoStreamTrack
objects in this stream's track set.
Examples
IEnumerable<VideoStreamTrack> videoTracks = mediaStream.GetVideoTracks();
See Also
RemoveTrack(MediaStreamTrack)
Remove a track from the stream.
Declaration
public bool RemoveTrack(MediaStreamTrack track)
Parameters
Type | Name | Description |
---|---|---|
MediaStreamTrack | track |
|
Returns
Type | Description |
---|---|
bool |
|
Remarks
RemoveTrack
method removes a track from the stream.
Examples
bool result = mediaStream.RemoveTrack(track);