HTML 5视频标签中的视频字幕不起作用

huangapple go评论80阅读模式
英文:

Subtitle of video not working in HTML 5 video tag

问题

以下是您提供的HTML代码的翻译部分:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>页面标题</title>
</head>
<body>
<video id="video" controls preload="metadata" height='400px' width='500px' src="https://media.w3.org/2010/05/sintel/trailer_hd.mp4">
   <track label="英语" kind="subtitles" srclang="en" src="https://video-react.js.org/assets/elephantsdream/captions.en.vtt" default>
   <track label="德语" kind="subtitles" srclang="de" src="https://video-react.js.org/assets/elephantsdream/captions.en.vtt">
   <track label="西班牙语" kind="subtitles" srclang="es" src="https://video-react.js.org/assets/elephantsdream/captions.en.vtt">
</video>

</body>
</html>

请注意,我只翻译了HTML代码中的文本部分,不包括代码或注释。

英文:
    &lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta charset=&quot;UTF-8&quot;&gt;
&lt;title&gt;Page Title&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;video id=&quot;video&quot; controls preload=&quot;metadata&quot; height=&#39;400px&#39; width=&#39;500px&#39;src=&quot;https://media.w3.org/2010/05/sintel/trailer_hd.mp4&quot;&gt;
   &lt;track label=&quot;English&quot; kind=&quot;subtitles&quot; srclang=&quot;en&quot; src=&quot;https://video-react.js.org/assets/elephantsdream/captions.en.vtt&quot; default&gt;
   &lt;track label=&quot;Deutsch&quot; kind=&quot;subtitles&quot; srclang=&quot;de&quot; src=&quot;https://video-react.js.org/assets/elephantsdream/captions.en.vtt&quot;&gt;
   &lt;track label=&quot;Espa&#241;ol&quot; kind=&quot;subtitles&quot; srclang=&quot;es&quot; src=&quot;https://video-react.js.org/assets/elephantsdream/captions.en.vtt&quot;&gt;
&lt;/video&gt;

&lt;/body&gt;
&lt;/html&gt;

I have use HTMl 5 video tag. video is working fine but subtitle not working. Please guys give me any suggestion. Here is https://video-react.js.org/assets/elephantsdream/captions.en.vtt caption file

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta charset=&quot;UTF-8&quot;&gt;
&lt;title&gt;Page Title&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;video id=&quot;video&quot; controls preload=&quot;metadata&quot; height=&#39;400px&#39; width=&#39;500px&#39; src=&quot;https://media.w3.org/2010/05/sintel/trailer_hd.mp4&quot;&gt;
   &lt;track label=&quot;English&quot; kind=&quot;subtitles&quot; srclang=&quot;en&quot; src=&quot;https://video-react.js.org/assets/elephantsdream/captions.en.vtt&quot; default&gt;
   &lt;track label=&quot;Deutsch&quot; kind=&quot;subtitles&quot; srclang=&quot;de&quot; src=&quot;https://video-react.js.org/assets/elephantsdream/captions.en.vtt&quot;&gt;
   &lt;track label=&quot;Espa&#241;ol&quot; kind=&quot;subtitles&quot; srclang=&quot;es&quot; src=&quot;https://video-react.js.org/assets/elephantsdream/captions.en.vtt&quot;&gt;
&lt;/video&gt;

&lt;/body&gt;
&lt;/html&gt;

<!-- end snippet -->

答案1

得分: 1

如果您在控制台中检查错误,您将看到如下消息:

尝试加载不安全的URL
https://video-react.js.org/assets/elephantsdream/captions.en.vtt,来自
带有URL https://stacksnippets.net/js 的框架。域名,
协议和端口必须匹配。

这意味着视频源和字幕文件必须位于相同的位置。

在您的示例中,您正在 https://stacksnippets.net/js 上播放视频,同时引用 https://video-react.js.org 上的字幕文件。这就是为什么请求被阻止的原因。

英文:

If you check the error from console, you will see the message like this:

> Unsafe attempt to load URL
> https://video-react.js.org/assets/elephantsdream/captions.en.vtt from
> frame with URL https://stacksnippets.net/js. Domains,
> protocols and ports must match.

That mean the source of the video and the subtitle file must be in same location.

HTML 5视频标签中的视频字幕不起作用

In your example, you're playing video on https://stacksnippets.net/js while refering the subtitle file on https://video-react.js.org. That's why the request had been blocked.

答案2

得分: 1

我的网站位于 https://www.example.org,而视频和字幕文件托管在 https://files.example.org,由MinIO(兼容S3的存储)提供服务。
Chromium和Firefox都抱怨字幕文件无法加载。

&lt;video&gt; 标签中添加了 crossorigin=anonymous 属性后,它就可以正常工作。

英文:

My website is at https://www.example.org, while video and subtitle files were hosted on https://files.example.org, served by MinIO (S3-compatible storage).
Both Chromium and Firefox complained that the subtitle file could not be loaded.

After adding the crossorigin=anonymous attribute to the &lt;video&gt; tag it worked.

huangapple
  • 本文由 发表于 2020年1月3日 15:20:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/59574625.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定