You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 6a47096
Browse filesBrowse the repository at this point in the historyBrowse files
feat: port the media file player example to the client API (#399)
* Let a local track's close be waited for
LocalTrack.closeAsync completes once the native track is released, after
which a source it was made over may be closed.
* Port the media file player example to the client API
One runtime in the CUSTOM audio mode replaces the two factories, a loopback
signaling the hand-rolled offer, answer and candidate exchange, and the
Swing VideoView the example's own panel. Statistics come from onStats, and
a Record button records the received tracks with MediaRecorder.
Create the runtime before the file: the runtime loads the native library that the file's sources need. The sources belong to the `MediaFileSource`, not to the tracks, so close the runtime, or the tracks, before the file. The file's audio source is pushed audio, so the runtime needs the `CUSTOM` or `HEADLESS` audio mode.
309
+
Create the runtime before the file: the runtime loads the native library that the file's sources need. The sources belong to the `MediaFileSource`, not to the tracks, so close the runtime, or the tracks, before the file: `track.closeAsync()` returns a future that completes once the track let go of its source. The file's audio source is pushed audio, so the runtime needs the `CUSTOM` or `HEADLESS` audio mode.
The [`MediaFilePlayerExample`](https://github.com/devopvoid/webrtc-java/blob/master/webrtc-examples/src/main/java/dev/onvoid/webrtc/examples/MediaFilePlayerExample.java) is a Swing application that sends a media file, or a live RTSP stream, from one peer connection to another in the same process, then shows the received video and plays the received audio in sync. Start and Stop buttons set up and tear down the whole session.
103
+
The [`MediaFilePlayerExample`](https://github.com/devopvoid/webrtc-java/blob/master/webrtc-examples/src/main/java/dev/onvoid/webrtc/examples/MediaFilePlayerExample.java) is a Swing application built on the [Client API](/guide/client-api). It sends a media file, or a live RTSP stream, from one peer to another in the same process, then shows the received video and plays the received audio in sync, and records what is received. Start and Stop buttons set up and tear down the whole session, and Record starts and stops a recording.
104
104
105
105
**Key features demonstrated:**
106
-
- Connecting two peer connections in one application, without a signaling server
107
-
- Using one factory with a dummy audio layer to send the file, and another with the platform audio layer to play what is received
106
+
- Sending the sources of a `MediaFileSource` as client API tracks, with `videoTrack` and `audioTrack`
107
+
- Connecting two peers in one application through a loopback signaling
108
+
- Using one runtime in the `CUSTOM` audio mode, which sends the file's audio and plays what is received
109
+
- Running the peers' handlers on the Swing event dispatch thread
108
110
- Keeping audio and video in sync by sending both tracks in the same media stream
109
-
- Raising the video sender's `maxBitrate` above WebRTC's default, so a high-resolution file is not held to a fraction of its size
110
-
- Rendering received video frames in a Swing component with `VideoBufferConverter`
111
-
- Showing the source's format, the playback position, and live receive metrics (codec, resolution, frame rate, bitrate, packet loss, jitter, audio level) read from `getStats()`
112
-
- Releasing senders, peer connections, tracks and the source in order on Stop
111
+
- Raising the video sender's maximum bitrate once it is connected, so a high-resolution file is not held to a fraction of its size
112
+
- Rendering received video in the Swing `VideoView`
113
+
- Showing the source's format, the playback position, and live receive metrics (codec, resolution, frame rate, bitrate, packet loss, jitter, audio level) read from `onStats`
114
+
- Recording the received tracks into a Matroska file with `MediaRecorder`
115
+
- Closing the peers, then the tracks, then the source on Stop
113
116
114
117
::: info
115
118
Like the [Media File](#media-file) example, this one needs the `webrtc-java-media` module. The source argument is optional; a file can also be chosen from the window, or a stream URL typed into it. A stream URL's credentials are never shown, and the Loop box is disabled while a live stream plays, since it has no length to start over from.
0 commit comments