https://github.com/meething/streamswitcher
Allows MediaStream to switch tracks without setting srcObject this allows MediaRecording to continue recording
https://github.com/meething/streamswitcher
Last synced: 3 months ago
JSON representation
Allows MediaStream to switch tracks without setting srcObject this allows MediaRecording to continue recording
- Host: GitHub
- URL: https://github.com/meething/streamswitcher
- Owner: meething
- License: mit
- Created: 2020-06-16T10:44:50.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-06-21T16:33:44.000Z (almost 6 years ago)
- Last Synced: 2025-04-28T13:57:15.841Z (about 1 year ago)
- Language: JavaScript
- Homepage: https://meething.github.io/StreamSwitcher/
- Size: 4.71 MB
- Stars: 31
- Watchers: 6
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# StreamSwitcher
Allows MediaStream to switch tracks without setting srcObject this allows MediaRecording to continue recording.
## [Demo](https://meething.github.io/StreamSwitcher/)
## Problem
The MediaRecorder is designed to stop recording when you switch streams during recording.
## Solution
Use RTCPSender to switch stream without MediaRecorder to stop recording. Another solution would be using MediaSourceBuffers but that is way more error sensitive in case of different codes etc..
## Result
A stream where you switch for instance camera with screenshare and back without need to stop and start the MediaRecorder
## How to use it
HTML file
```
```
JS file
```
//Setup video with empty stream
var temporaryStream = new MediaStream();
video.srcObject = temporaryStream.remoteStream;
//Change the track from a stream
video.srcObject.replaceVideoTrack(stream.getVideoTracks()[0])//Video
video.srcObject.replaceAudioTrack(stream.getAudioTracks()[0])//Audio
//If not autoplay
video.play();
```
## Resource
- https://discourse.mozilla.org/t/switch-stream-in-media-recorder/27619/3
- https://stackoverflow.com/questions/59846230/mediarecorder-switch-video-tracks
- https://webrtc.github.io/samples/src/content/peerconnection/pc1/