admin管理员组

文章数量:1406937

I am using one of the webrtc libraries to show video and attaching the stream received to video element. But when I inspect the video element, src attribute is missing.

<video autoplay="" id="EKA-e2RERLzhCFy8AAEd" class="videoRoom"></video>

I have couple of questions here :

  1. Is it possible for video element to have no src attribute.
  2. If possible, how to get src for that video

I am using one of the webrtc libraries to show video and attaching the stream received to video element. But when I inspect the video element, src attribute is missing.

<video autoplay="" id="EKA-e2RERLzhCFy8AAEd" class="videoRoom"></video>

I have couple of questions here :

  1. Is it possible for video element to have no src attribute.
  2. If possible, how to get src for that video
Share Improve this question edited Sep 15, 2016 at 12:06 Karthick Kumar Ramakrishnan 516 bronze badges asked Sep 15, 2016 at 10:37 Aman GuptaAman Gupta 3,7974 gold badges46 silver badges67 bronze badges 4
  • src or source ? – David R Commented Sep 15, 2016 at 10:39
  • <video autoplay="" src="???" id="EKA-e2RERLzhCFy8AAEd" class="videoRoom"></video> – Aman Gupta Commented Sep 15, 2016 at 10:42
  • 1 Please try to keep it to one question per post. --- 1. yes, this can be assigned using JS, although it should show up in dev tools. --- 2. Try document.getElementById('EKA-e2RERLzhCFy8AAEd').src – evolutionxbox Commented Sep 15, 2016 at 10:42
  • document.getElementById('EKA-e2RERLzhCFy8AAEd').src produces "" . – Aman Gupta Commented Sep 15, 2016 at 10:45
Add a ment  | 

2 Answers 2

Reset to default 7

Is it possible for video element to have no src attribute.

Yes it's possible.

The library you do use probably sets the srcObject property of your videoElement.

This property allows to set the source of your video directly to a MediaStream, a MediaSource, a Blob or a File Object. Note that FF only supports MediaStreams currently.

Example for FF (inspect the element afterward)

navigator.mediaDevices.getUserMedia({video:true}).then(s=>(vid.srcObject = s));
<video id="vid" controls></video>

And a fiddle for chrome since it requires https protocol for GUM to work.


If possible, how to get src for that video

Well, there is not really an src so I'd say not possible.

You can still call yourVideoElement.srcObject, but this will return the object to what it was set (usually a MediaStream).
If you need to record it, you can then use a MediaRecorder.

<div class="col-sm-12">
         
        <video width="400" controls>
          <source src="http://ia800803.us.archive/17/items/MickeyMouse-RunawayTrain/Film-42.mp4" type="video/mp4">           
        </video>
      </div>

In src place the video url you want

<video width="400" controls>
    <source src="" type="video/mp4">           
</video>

本文标签: javascriptHTML5Video element without 39src39 attributeStack Overflow