简体   繁体   English

以HTML格式在div中播放视频

[英]Play video in a div in HTML

I'm trying to play a video in a div tag in html but when I used the following code, the browser asked if I want to download the video. 我试图在html的div标签中播放视频,但是当我使用以下代码时,浏览器询问我是否要下载视频。 I do not want to download it, I just want to play it. 我不想下载它,我只想播放它。 Also this message appeared in the div 此消息也出现在div中

"You need to install an extension to view this content" “您需要安装扩展程序才能查看此内容”

I'm using firefox browser 我正在使用Firefox浏览器

This what I used in html file : 这是我在html文件中使用的:

<div>
<object type="Brave/quicktime" data="Brave.avi" width="624" height="352">
<param name="pluginurl" value="http://www.apple.com/quicktime/download/" />
<param name="controller" value="false" />
<param name="autoplay" value="true" />
</object>
</div> 

Try using the video tag 尝试使用视频标签

 <div>
   <video width="700" height="450" controls="controls" poster="image" preload="true">
     <source src="where the video is" type="video/mov"/>
     <source src="where the video is" type="video/mp4" />
     <source src="where the video is" type="video/oog" />
     Your browser does not support the video tag.
   </video>
</div>

You also need to use a different video type. 您还需要使用其他视频类型。 AVI file types are not supported in the html5 video tag. html5视频标记中不支持AVI文件类型。

Try this 尝试这个

<video width="624" height="352" controls>
<source src="Brave.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>

Also i wouldn't use AVI as the format for the video. 我也不会使用AVI作为视频的格式。

Use MP4 then you can use the HTML5 video tag. 使用MP4,则可以使用HTML5视频标签。

Your main problem is that you're using an invalid MIME type (as you've pointed out yourself, the browser returns an "invalid MIME type" message). 您的主要问题是您使用的是无效的MIME类型(正如您自己指出的那样,浏览器返回“无效的MIME类型”消息)。 You're also using the <object> tag, which is deprecated as of HTML5. 您还使用了<object>标记,从HTML5开始不推荐使用。

Before using up-to-date markup, make sure your DOCTYPE declaration reads, <DOCTYPE html> , and nothing more. 在使用最新标记之前,请确保您的DOCTYPE声明为<DOCTYPE html> ,并且仅此而已。 This tells the browser that you're using an HTML5 document, and that the proper tag definitions should be loaded. 这告诉浏览器您正在使用HTML5文档,并且应该加载正确的标记定义。 If you declare an HTML4 DOCTYPE , your browser might not be able to process HTML5 tags. 如果声明HTML4 DOCTYPE ,则浏览器可能无法处理HTML5标签。

Once that's done, use the <video> tag. 完成后,使用<video>标签。 Now, your markup should look something like this: 现在,您的标记应如下所示:

<DOCTYPE html>
<html>
    <head>
    <!-- your styles, scripts, and other head info -->
    </head>

    <body>
        <video src="Brave.avi" controls="yourControls" autoplay="false">
        Your browser doesn't support the `<video>` tag. /*this is a fallback*/
        </video>
    </body>
<html>

You'll notice that there's no type attribute for the <video> tag. 您会注意到, <video>标签没有type属性。 That's because the <video> tag doesn't actually support that attribute . 这是因为<video>标签实际上不支持该属性 This makes for less coding, which is always a good thing. 这样可以减少编码,这始终是一件好事。

On a side note, avoid using the .avi format. 另外,请避免使用.avi格式。 The h264 codec just became an official standard, which means that using .mp4 , or even the oft-neglected .ogg format are preferable, as they use less bandwidth, and are more widely supported. h264编解码器刚刚成为正式标准,这意味着使用.mp4甚至是经常被忽略的.ogg格式是更可取的,因为它们使用的带宽更少,并且得到了更广泛的支持。

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

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