如何使用javascript获取视频的第一个来源?

时间:2015-12-26 11:03:21

标签: javascript

无法获取视频的第一个来源

<video id="myvideo" width="800" height="400" class="video-js vjs-default-skin" controls="">             
<source class="active" src="http://localhost/CastingGallery/upload/2/marimatrubhasha.mp4" id="videosource" type="video/mp4" startat="00:00:00" endat="00:04:07" name="Gujarati Bhasha" description="This is Gujarati Video">            
<source class="active" src="http://localhost/CastingGallery/upload/2/php.mp4" id="videosource" type="video/mp4" startat="00:04:07" endat="00:19:06" name="PHP Video" description="This is PHP Video">           
<source class="active" src="http://localhost/CastingGallery/upload/2/php.mp4" id="videosource" type="video/mp4" startat="00:19:06" endat="00:34:05" name="PHP Video" description="This is PHP Video">           
<source class="active" src="http://localhost/CastingGallery/upload/2/php.mp4" id="videosource" type="video/mp4" startat="00:34:05" endat="00:49:04" name="PHP Video" description="This is PHP Video">               
</video>
var myvid = document.getElementById('myvideo');
var videoSource = document.getElementsByTagName('source');
var getSource = videoSource[0].src;
console.log(getSource);

1 个答案:

答案 0 :(得分:0)

&#13;
&#13;
do {
    output[i] = square[
                (edge & 1) * (
                    !(i & 1) * ((edge + 1) & 2) + 
                    (i & 1) * (
                        (!((edge - 1)/2)&1) * i + 
                        (((edge - 1)/2)&1) * (4-i)
                    )
                ) +     
                !(edge & 1) * (
                    (i & 1) * (edge + 1) + 
                    !(i & 1) * ((edge & 2) - ((edge & 2)-1) * i)
                )
                ];
} while(++i <= LEFT);
&#13;
var myvid = document.getElementById("myvideo");
var firstSource = myvid.getElementsByTagName("source")[0]

alert(firstSource.getAttribute("name"))
alert(firstSource.src)
&#13;
&#13;
&#13;

请注意,您还应该使用<video id="myvideo" width="800" height="400" class="video-js vjs-default-skin" controls=""> <source class="active" src="http://localhost/CastingGallery/upload/2/marimatrubhasha.mp4" id="videosource" type="video/mp4" startat="00:00:00" endat="00:04:07" name="Gujarati Bhasha" description="This is Gujarati Video" /> <source class="active" src="http://localhost/CastingGallery/upload/2/php.mp4" id="videosource" type="video/mp4" startat="00:04:07" endat="00:19:06" name="PHP Video" description="This is PHP Video" /> <source class="active" src="http://localhost/CastingGallery/upload/2/php.mp4" id="videosource" type="video/mp4" startat="00:19:06" endat="00:34:05" name="PHP Video" description="This is PHP Video" /> <source class="active" src="http://localhost/CastingGallery/upload/2/php.mp4" id="videosource" type="video/mp4" startat="00:34:05" endat="00:49:04" name="PHP Video" description="This is PHP Video" /> </video>

关闭<source标记