Skip to content

Commit e32007f

Browse files
committed
docs v1
1 parent 62ce497 commit e32007f

26 files changed

+1428
-97
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"label": "API Docs",
3+
"position": 1
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
sidebar_position: 3
3+
---
4+
5+
# GetDisplayMedia
6+
7+
The `getDisplayMedia` method of the `MediaDevices` interface prompts the user to select and grant permission to capture the contents of a display or portion thereof (such as a window or screen) as a `MediaStream`.
8+
9+
The corresponding JS API docs is here [MediaDevices.getDisplayMedia()](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getDisplayMedia).
10+
11+
## Usage
12+
13+
```dart
14+
MediaStream stream = await navigator.mediaDevices.getDisplayMedia({
15+
'video': true,
16+
'audio': true,
17+
});
18+
```
19+
20+
## Parameters
21+
22+
- `audio`: A Boolean value that indicates whether the `MediaStream` should include an audio track.
23+
audio is optional, default is false. only chrome tabs can support audio caputure.
24+
25+
- `video`: A Boolean value that indicates whether the `MediaStream` should include a video track.
26+
video is optional, default is true.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
sidebar_position: 2
3+
---
4+
5+
# GetUserMedia
6+
7+
The corresponding JS API docs is here
8+
[MediaDevices.getUserMedia()](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia).
9+
10+
## Usage
11+
12+
basic usage:
13+
14+
```dart
15+
await navigator.mediaDevices.getUserMedia({'audio': true, 'video': true});
16+
```
17+
18+
advanced usage:
19+
20+
```dart
21+
await navigator.mediaDevices.getUserMedia({
22+
'audio': true,
23+
'video': {
24+
'facingMode': 'user', // or 'environment' for mobile devices
25+
'width': 1280,
26+
'height': 720,
27+
'frameRate': 30,
28+
}
29+
});
30+
```
31+
32+
## Parameters
33+
34+
- mediaConstraints: A dictionary object that specifies the media constraints for the requested media types.
35+
refer to the [MediaStreamConstraints](https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamConstraints) for more details.
36+
37+
sub options:
38+
39+
- `audio`: A Boolean value that indicates whether the MediaStream should include an audio track.
40+
41+
or a dictionary object that specifies the audio track's media constraints.
42+
43+
```json
44+
{
45+
'deviceId': 'audio_device_id',
46+
}
47+
```
48+
49+
- `video`: A Boolean value that indicates whether the MediaStream should include a video track.
50+
51+
or a dictionary object that specifies the video track's media constraints.
52+
53+
```json
54+
{
55+
'deviceId': 'video_device_id',
56+
'facingMode': 'user', // or 'environment' for mobile devices
57+
'width': 1280,
58+
'height': 720,
59+
'frameRate': 30,
60+
}
61+
```
62+
63+
## Return value
64+
65+
A Promise that resolves to a MediaStream object.
66+
67+
Note: The `deviceId` parameter is used to specify the device to use. If you want to use the default device, you can omit this parameter. If you want to use a specific device, you can get the device ID by calling `navigator.mediaDevices.enumerateDevices` [here](./media-devices) and then pass it to the `deviceId` parameter.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
sidebar_position: 1
3+
---
4+
5+
# MediaDevices
6+
7+
The corresponding JS API docs is here [MediaDevices](https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices).
8+
9+
## Usage
10+
11+
```dart
12+
MediaDevices mediaDevices = await navigator.mediaDevices;
13+
14+
MediaStream stream = await mediaDevices.getUserMedia({
15+
'audio': true,
16+
'video': true,
17+
});
18+
19+
MediaStream displayStream = await mediaDevices.getDisplayMedia({
20+
'video': true,
21+
'audio': true,
22+
});
23+
24+
List<MediaDeviceInfo> devices = await mediaDevices.enumerateDevices();
25+
26+
```
27+
28+
## Methods
29+
30+
- `getUserMedia`: Returns a Promise that resolves to a `MediaStream` object. The `MediaStream` object represents a stream of media content, typically (but not necessarily) including both audio and video.
31+
32+
```dart
33+
MediaStream stream = await mediaDevices.getUserMedia({
34+
'audio': true,
35+
'video': true,
36+
});
37+
```
38+
39+
- `getDisplayMedia`: Returns a Promise that resolves to a `MediaStream` object. The `MediaStream` object represents a stream of media content, typically (but not necessarily) including both audio and video.
40+
41+
```dart
42+
MediaStream stream = await mediaDevices.getDisplayMedia({
43+
'video': true,
44+
'audio': true,
45+
});
46+
```
47+
48+
- `enumerateDevices`: Returns a Promise that resolves to an array of `MediaDeviceInfo` objects, each of which represents a media input or output device.
49+
50+
```dart
51+
List<MediaDeviceInfo> devices = await mediaDevices.enumerateDevices();
52+
```
53+
54+
- `getSupportedConstraints`: Returns a dictionary object that specifies the media constraints supported by the user agent.
55+
only support for web platform.
56+
57+
- `selectAudioOutput`: select audio output device.
58+
support platforms: macOS/Windows/Linux/Web.
59+
60+
## Event Callbacks
61+
62+
- `onDeviceChange`: The `ondevicechange` event handler for the `MediaDevices` interface. It is called when a media input or output device is attached or removed.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
sidebar_position: 7
3+
---
4+
5+
# MediaRecorder
6+
7+
The corresponding JS API docs is here [MediaRecorder](https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder).
8+
9+
Creates a new `MediaRecorder` object, given a MediaStream to record. Options are available to do things like set the container's MIME type (such as "video/webm" or "video/mp4") and the bit rates of the audio and video tracks or a single overall bit rate.
10+
11+
## Methods
12+
13+
- `start`: Starts recording the media.
14+
For Android use audioChannel param.
15+
For iOS use audioTrack.
16+
17+
```dart
18+
void start() async {
19+
if (Platform.isIOS) {
20+
print('Recording is not available on iOS');
21+
return;
22+
}
23+
// TODO(rostopira): request write storage permission
24+
final storagePath = await getExternalStorageDirectory();
25+
if (storagePath == null) throw Exception('Can\'t find storagePath');
26+
27+
final filePath = storagePath.path + '/webrtc_sample/test.mp4';
28+
mediaRecorder = MediaRecorder();
29+
setState(() {});
30+
final videoTrack = stream
31+
.getVideoTracks().first;
32+
await mediaRecorder.start(
33+
filePath,
34+
videoTrack: videoTrack,
35+
audioChannel: RecorderAudioChannel.INPUT,
36+
);
37+
}
38+
```
39+
40+
- `startWeb`: Starts recording the media in the web.only for flutter web.
41+
42+
```dart
43+
void startWeb() async {
44+
mediaRecorder = MediaRecorder();
45+
setState(() {});
46+
mediaRecorder.startWeb(stream,onDataChunk:(data){
47+
// do something with data
48+
dynamic blob, bool isLastOne
49+
} ,'video/webm', 1000);
50+
}
51+
```
52+
53+
- `stop`: Stops recording the media.
54+
55+
```dart
56+
void stop() async {
57+
await mediaRecorder.stop();
58+
setState(() {
59+
mediaRecorder = null;
60+
});
61+
}
62+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
sidebar_position: 6
3+
---
4+
5+
# MediaStreamTrack
6+
7+
The corresponding JS API docs is here [MediaStreamTrack](https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack).
8+
9+
The `MediaStreamTrack` interface represents a single media track within a stream; typically, these are audio or video tracks, but other track types may exist as well. A `MediaStreamTrack` can be associated with multiple `MediaStream` objects.
10+
11+
## Methods
12+
13+
- `stop`: Stops the track.
14+
15+
```dart
16+
void stopStreamedVideo(RTCVideoRenderer renderer) {
17+
var stream = renderer.srcObject;
18+
var tracks = stream.getTracks();
19+
20+
tracks.forEach((track) => {
21+
track.stop();
22+
});
23+
24+
randerer.srcObject = null;
25+
}
26+
```
27+
28+
## Events
29+
30+
- `onMute`: Sent to the MediaStreamTrack when the value of the muted property is changed to true, indicating that the track is unable to provide data temporarily (such as when the network is experiencing a service malfunction).
31+
32+
```dart
33+
track.onMute = (event) {
34+
print("Track ${track.id} is muted");
35+
};
36+
```
37+
38+
- `onUnMute`: Sent to the MediaStreamTrack when the value of the muted property is changed to false, indicating that the track is able to provide data again (such as when the network is no longer experiencing a service malfunction).
39+
40+
```dart
41+
track.onUnMute = (event) {
42+
print("Track ${track.id} is unmuted");
43+
};
44+
```
45+
46+
- `onEnded`:Sent when playback of the track ends (when the value readyState changes to ended), except when the track is ended by calling MediaStreamTrack.stop.
47+
48+
```dart
49+
track.onEnded = (event) {
50+
print("Track ${track.id} has ended");
51+
};
52+
```
53+
54+
## Properties
55+
56+
- `id`: Returns the unique identifier of the track.
57+
58+
- `label`:This may label audio and video sources (e.g., "Internal microphone" or "External USB Webcam"). Returns the label of the object's corresponding source, if any.
59+
If the corresponding source has or had no label, returns an empty string.
60+
61+
- `kind`: Returns the type of track, such as "audio" or "video".
62+
63+
- `enabled`: Returns the enable state of `MediaStreamTrack`.After a `MediaStreamTrack` has ended, setting the enable state
64+
will not change the ended state.
65+
66+
- `muted`: Returns true if the track is muted, and false otherwise.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
---
2+
sidebar_position: 8
3+
---
4+
5+
# MediaStream
6+
7+
The corresponding JS API docs is here [MediaStream](https://developer.mozilla.org/en-US/docs/Web/API/MediaStream).
8+
9+
The MediaStream interface of the Media Capture and Streams API 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.
10+
11+
## Methods
12+
13+
- `addTrack`:Adds the given `MediaStreamTrack` to this `MediaStream`.
14+
15+
```dart
16+
var mediaStream = MediaStream(
17+
id: 'audio-stream',
18+
ownerTag: 'audio-tag',
19+
active: true,
20+
/// The active attribute return true if this [MediaStream] is active and false otherwise.
21+
/// [MediaStream] is considered active if at least one of its [MediaStreamTracks] is not in the [MediaStreamTrack.ended] state.
22+
/// Once every track has ended, the stream's active property becomes false.
23+
onAddTrack: (MediaStreamTrack track) {
24+
print('Track added: ${track.id}');
25+
},
26+
onRemoveTrack: (MediaStreamTrack track) {
27+
print('Track removed: ${track.id}');
28+
},
29+
);
30+
mediaStream.addTrack(track, {addToNative: true});
31+
```
32+
33+
- `removeTrack`:Removes the given `MediaStreamTrack` object from this `MediaStream`.
34+
35+
```dart
36+
mediaStream.removeTrack(track,{removeFromNative: true});
37+
```
38+
39+
- `getTracks`:Returns a List `MediaStreamTrack` objects representing all the tracks in this stream.
40+
41+
```dart
42+
var tracks = mediaStream.getTracks();
43+
```
44+
45+
- `getAudioTracks`:Returns a List `MediaStreamTrack` objects representing the audio tracks in this stream.
46+
The list represents a snapshot of all the `MediaStreamTrack` objects in this stream's track set whose kind is equal to 'audio'.
47+
48+
```dart
49+
var audioTracks = mediaStream.getAudioTracks();
50+
```
51+
52+
- `getVideoTracks`:Returns a List `MediaStreamTrack` objects representing the video tracks in this stream.
53+
54+
```dart
55+
var videoTracks = mediaStream.getVideoTracks();
56+
```
57+
58+
- `getTrackById`:Returns either a `MediaStreamTrack` object from this stream's track set whose id is equal to trackId, or `StateError`, if no such track exists.
59+
60+
```dart
61+
var track = mediaStream.getTrackById('some-track-id');
62+
```
63+
64+
- `dispose`:Dispose the `MediaStream`.
65+
66+
```dart
67+
await mediaStream.dispose();
68+
```
69+
70+
## Events
71+
72+
- `onAddTrack`:Fires when a new `MediaStreamTrack` is added to this `MediaStream`.
73+
74+
```dart
75+
var mediaStream = MediaStream(
76+
id: 'audio-stream',
77+
ownerTag: 'audio-tag',
78+
active: true,
79+
);
80+
mediaStream.onAddTrack = (MediaStreamTrack track) {
81+
print('Track added: ${track.id}');
82+
};
83+
```
84+
85+
- `onRemoveTrack`:Fires when a `MediaStreamTrack` is removed from this `MediaStream`.
86+
87+
```dart
88+
var mediaStream = MediaStream(
89+
id: 'audio-stream',
90+
ownerTag: 'audio-tag',
91+
active: true,
92+
);
93+
mediaStream.onRemoveTrack = (MediaStreamTrack track) {
94+
print('Track removed: ${track.id}');
95+
};
96+
```
97+
98+

0 commit comments

Comments
 (0)