如何使用HTML5将视频嵌入本地文件 [英] How to Embed Video using HTML5 with local file

查看:1914
本文介绍了如何使用HTML5将视频嵌入本地文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用带有本地mp4文件的html5嵌入视频。

I'm trying to embed a video using html5 with a local mp4 file.

我本地计算机上的文件。

file on my local machine.

当我调试时,我一直收到无效的文件路径或不支持的视频类型。

when i debug i keep getting invalid file path or unsupported video type.

我缺少什么?如果我插入一个到mp4的http链接,我可以让它工作。但是,当我插入本地文件时,它不会

What am i missing? I can get this to work if i plug in a http link to a mp4. But when i plug in a local file it doesn't

    <link href="http://vjs.zencdn.net/4.1/video-js.css" rel="stylesheet" />
    <script src="http://vjs.zencdn.net/4.1/video.js">
        videojs("example_video_1", {}, function(){
        });
    </script>
    <video id="example_video_1" class="video-js vjs-default-skin" width="640" height="264">
        <source src="file:///C:/Users/rpimentel/Desktop/converts/demo1.mp4" type='video/mp4' />
    </video>


推荐答案

HTML5仅通过拥有视频标签。
请务必将视频源直接包含在视频标记中,例如:

HTML5 works just by having the video tags. Make sure to include the video source directly in the video tag like:

<video id="example_video_1" class="video-js vjs-default-skin" width="640" height="264" src="file:///C:/Users/rpimentel/Desktop/converts/demo1.mp4" type='video/mp4' />
</video>

关于视频src-path。视频必须位于应用程序目录中的某个位置才能播放。因此,当您的应用程序被称为video_homepage时,请在其中放入一个包含视频的文件夹。在此示例中,来源为:

Concerning the video src-path. The video must be somewhere inside your application directory in order to play. So when your application is called video_homepage then put a folder in it with videos. In this example case the source is:

<video src= video_homepage/videos/demo1.mp4></video>

这已经应该让视频在Safari和IE中运行(对于mp4)。对于Firefox和Chrome,您必须首先将视频转换为.webm(免费的webm视频转换器是一个免费且良好的转换器)

That already should make the video run in Safari and IE (for mp4). For Firefox and Chrome you must convert the video first to .webm (free webm video converter is a free and good converter)

视频ID和类等仅在需要时才需要你使用外部.js视频播放器(插件)。要在HTML5中播放视频,您只需要视频标签和src。而已。

video id and class etc. is only needed when you use an external .js video player (plug in). for playing videos in HTML5 you only need the video tags and src. thats it.

这篇关于如何使用HTML5将视频嵌入本地文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆