【问题标题】:Catch Html5 video src on click play button单击播放按钮捕获 Html5 视频 src
【发布时间】:2014-08-26 21:32:44
【问题描述】:

我的目标是当我单击该 html5 视频帧的播放按钮时捕获 Html5 视频 src。在 jquery 中怎么可能?

<video src="video.ogv">
 video not supported
</video>

<script>
var video = document.getElementsByTagName('video')[0];
 video.onended = function(e) {
  /*Do things here!*/
};

$('video source').each(function(num,val){
console.log($(this).attr('src'));        // i am not getting this..
strSrc = $(this).attr('src'); 
strPath = strSrc.substring(0, strSrc.lastIndexOf('/'));
strExtenion = strSrc.substring(strSrc.lastIndexOf('.'));
$(this).attr('src', strPath + "/" + "newFileName" + strExtenion );
alert($(this).attr('src'));

})

【问题讨论】:

  • 为此,您必须创建自定义按钮并获取 $('video').attr('src');点击。您不能对嵌入式按钮进行更改。
  • @AshishMishra 你能给我举个例子吗?
  • @AshishMishra 例如 vimeo vimeo.com/m/102513133 中的视频,我按下播放按钮,然后我只想捕捉 html5 视频的来源。
  • 不,你不能播放其他服务器上的视频......比如 youtube 或 vimeo
  • @AshishMishra 我不想玩,我想使用 jquery 获取该视频 src,当我点击 html5 视频上的播放按钮时,jquery 会获取正在播放的视频的 src。跨度>

标签: jquery html html5-video


【解决方案1】:

类似

   <video id='vids' src="video.ogv">
       video not supported
   </video>

   <input id='plyvid' type='button'  />

 <script>
$('#plyvid').click(function(){
 var vid = $('#vids');
 vid.get(0).play();
  var vidSrc =  vid.attr('src'); //Here you get the SRC

 });
  var video = document.getElementsByTagName('video')[0];
  video.onended = function(e) {

  alert($(video).attr('src')) ;// I am not tested this ..may it works for you.

  };
    </script>

【讨论】:

  • 我想使用 jquery 从不在我网站中的其他 html5 视频流媒体网站动态获取该视频 src,当我点击 html5 视频上的播放按钮时,jquery 会获取正在播放的视频的 src。 ——
  • 无法获取在其他网站播放的视频的“onended event”。
  • 那么解决办法是什么?
  • 输入你的实际代码!用你使用的url、html、js。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-03
  • 1970-01-01
  • 1970-01-01
  • 2016-11-23
  • 2014-03-05
  • 1970-01-01
相关资源
最近更新 更多