简体   繁体   English

如何暂停A帧中的视频圈?

[英]How to pause a videosphere in A-frame?

I don't want a video controller but pause the video and change its current time in JS, what should I do? 我不想要一个视频控制器但暂停视频并改变它在JS的当前时间,我该怎么办? I have done a lot of research and tried a lot, but it always says" Cannot read property 'pause' of null". 我做了很多研究并尝试了很多,但它总是说“无法读取属性'暂停'为null”。

If You have a video in your <a-assets> : 如果您的<a-assets>有视频:

<a-assets>
   <video id="myvideo">
</a-assets>

<a-videosphere src="#myvideo>

then You can call play()/pause() on the video asset, like: 然后你可以在视频资产上调用play()/ pause(),例如:

document.querySelector("#myvideo").pause();


If You set Your a-videosphere src as a direct link to an .mp4 file, then try to call the functions on the videosphereElReference.getAttribute('src').pause(); 如果您将a-videosphere src为.mp4文件的直接链接,则尝试调用videosphereElReference.getAttribute('src').pause();上的函数videosphereElReference.getAttribute('src').pause();
Working fiddle here . 在这里工作小提琴。

This code working for me 这段代码对我有用

Fiddle 小提琴

You can see it in the console log, when does it play / pause 您可以在控制台日志中看到它,它何时播放/暂停

right click -> inspect element -> click console tab 右键单击 - >检查元素 - >单击控制台选项卡

<meta charset="utf-8">
<title>360 Video</title>
<meta name="description" content="360 Video — A-Frame">
<script src="https://aframe.io/releases/0.8.2/aframe.min.js"></script>    <script>
AFRAME.registerComponent('foo',{
init:function(){
  var vid = document.getElementById('video');
  setTimeout(function(){

  document.querySelector('#video').pause();
  console.log('pause');
  },5000);
  setTimeout(function(){
   vid.play();
   console.log('play');
  },10000);
}
})
</script>
<a-scene foo>
  <a-assets>
    <video id="video" src="https://ucarecdn.com/fadab25d-0b3a-45f7-8ef5-85318e92a261/"
           autoplay loop crossorigin="anonymous"></video>
  </a-assets>

  <a-videosphere src="#video" rotation="0 180 0"></a-videosphere>
</a-scene>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM