HTML5 视频 JavaScript

发布于 2024-10-09 08:29:14 字数 791 浏览 4 评论 0原文

我没有 Javascript 经验,我有以下脚本在 Andriod 手机上播放视频文件,并且运行良好。

 <script type="text/javascript">
        function PlayMyVideo(arg) {
            var myVideo = document.getElementById([arg]);
            myVideo.play();
        }
    </script>
<video id="what" src="what.mp4" poster="" />
<input type="button" onclick="PlayMyVideo('what')" value="Play" />

我正在尝试即时编写标签:

  <script type="text/javascript">
        function PlayVideo() {
            new_video = document.createElement('video');
            new_video.setAttribute('scr', 'what.mp4'); 
            new_video.play(); 
         }
    </script>
<input type="button" onclick="PlayVideo()" value="Play2" />

没有发生任何事情,将不胜感激您的建议。 提前致谢

I am not experienced in Javascript, I have the following script to play video files on Andriod phone, and it works fine.

 <script type="text/javascript">
        function PlayMyVideo(arg) {
            var myVideo = document.getElementById([arg]);
            myVideo.play();
        }
    </script>
<video id="what" src="what.mp4" poster="" />
<input type="button" onclick="PlayMyVideo('what')" value="Play" />

I am trying to write the tag on the fly:

  <script type="text/javascript">
        function PlayVideo() {
            new_video = document.createElement('video');
            new_video.setAttribute('scr', 'what.mp4'); 
            new_video.play(); 
         }
    </script>
<input type="button" onclick="PlayVideo()" value="Play2" />

Nothing happen, would appreciate your suggestions.
Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ぃ双果 2024-10-16 08:29:14
new_video.setAttribute('scr', 'what.mp4');

“scr”拼写错误。它应该是“src”。

而且你应该在播放之前等待电影加载

new_video.setAttribute('scr', 'what.mp4');

'scr' is misspelled. It should be 'src'.

and also you should wait for the movie to load before play

半夏半凉 2024-10-16 08:29:14

好吧,您没有将新创建的标签附加到任何内容,因此它无法播放,因为它位于“内存”/“无效”中,而不是在屏幕上。

<div id='plc'> </div>

<script type='text/javascript'>
function PlayVideo() {
new_video = document.createElement('video');
document.getElementById('plc').appendChild(new_video);
new_video.setAttribute('scr', 'what.mp4');
new_video.play();
}

Well you're not appending the newly created tag to anything, so it can't play because it's in "memory"/"void", not on the screen.

<div id='plc'> </div>

<script type='text/javascript'>
function PlayVideo() {
new_video = document.createElement('video');
document.getElementById('plc').appendChild(new_video);
new_video.setAttribute('scr', 'what.mp4');
new_video.play();
}
甲如呢乙后呢 2024-10-16 08:29:14

您正在创建视频元素,您需要将其添加到 DOM 中,然后它才会可见,更多信息如下: http://www.javascriptkit.com/javatutors/dom2.shtml

you are creating the video element, you need to add it to the DOM before it will be visible, more info here: http://www.javascriptkit.com/javatutors/dom2.shtml

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文