如何在HTML5中添加外部源的字幕? [英] How to add subtitles from a external source in HTML5?

查看:337
本文介绍了如何在HTML5中添加外部源的字幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在视频html中添加外部来源的字幕,但我不能。我正在使用WebTorrent技术,因此,我在浏览器中播放视频种子,< track> 标记对我不起作用。以下是我使用的代码: https://plnkr.co/edit/31RZSBETaAQgnCgZgKUt?p=preview

字幕的代码就是这样:

I'm trying to add subtitles from an external source in a video html but I can't. I'm using the WebTorrent Technology, so, I'm streaming video torrents in my Browser and the <track> tag not works for me. Here's the code that I use: https://plnkr.co/edit/31RZSBETaAQgnCgZgKUt?p=preview
The code for subtitles it's this:

file.appendTo('body');
var video = document.querySelector("video");
var track = video.addTextTrack("subtitles", "prompt", "en");
track.mode = "showing";
});

谢谢,我希望你能帮助我!

Thanks, i hope that you can help me!

推荐答案

您可以在HTML中创建或包含< track> 元素作为父< video> 元素默认属性设置为 true src .vtt 文件,种类设置为字幕模式设置为显示 label 设置为Español srclang 设置为es

You can create or include a <track> element within HTML as a child of parent <video> element with default property set to true, src to to .vtt file, kind set to "subtitles", mode set to "showing", label set to "Español", and srclang set to "es"

  file.appendTo('body');
  var video = document.querySelector("video");

  var track = document.createElement("track");
  track.mode = "showing";
  track.label = "Español";
  track.kind = "subtitles";
  track.srclang = "es";
  track.src = "subs.vtt";
  track.default = true;
  video.appendChild(track);

plnkr https://plnkr.co/edit/9MpJNHTB08RP6Lz3tvEb?p=preview

这篇关于如何在HTML5中添加外部源的字幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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