How to add video track in audio only mediastream

484 views
Skip to first unread message

Rishi Khandelwal

unread,
Jun 16, 2014, 7:14:40 AM6/16/14
to eas...@googlegroups.com
Hi

I have the scenario in which I have a media which contains only audio. Now i want to add video track as well. 

How can I do this ? I don't want to run allow/deny permission bar again for user.

Thanks

Eric Davies

unread,
Jun 23, 2014, 1:33:52 PM6/23/14
to eas...@googlegroups.com
You can't. It's a security issue imposed by the browser. The best you can do is always grab both audio and video, and then construct new media streams that only contain subsets of their tracks.

Rishi Khandelwal

unread,
Jun 24, 2014, 4:03:57 AM6/24/14
to eas...@googlegroups.com
Thank For your reply Eric.

Actually my scenario is that :
Initially I have mediastream with audio and video.  then after some time I am removing video tracks from media stream and then again I want video back in my mediastream without allowing permission bar. 

I tried some hacks and got my functionality working but i want to confirm with you whether i am doing correct or not ?

1. At the starting, when I got other user's stream then i extract video tracks from that and stored that in a global variable.

var videoTracks= otherUserStream.getVideoTracks();

2. then removed audio track from mediastream and set that mediastream in video element.

var audioOnlyStream = otherUserStream.removeTrack(otherStream.getVideoTracks[0]);

3. and when again, when I tried to add video track to media stream then I took videoTracks global variable and add that to media stream.

otherUserStream.addTrack(videoTracks[0]);

Following above steps, i got my functionality working. Now let me know , if i am doing anything wrong or if it will affect browser performance ?

Thank You

Eric Davies

unread,
Jun 24, 2014, 11:14:00 AM6/24/14
to eas...@googlegroups.com
In theory, what you are doing is legal. In the past, it would crash the video element. I would suggest trying it on Firefox as well as Chrome before concluding it's a viable approach. Outside of that, you may want to inquire on the discuss-webrtc group since this is really a webrtc issue rather than an easyrtc issue (googlers will be more knowledgeable about what the implications are to browser performance).

Eric.
Reply all
Reply to author
Forward
0 new messages