所以我使用自己的 HTML 播放器并使用该元素在 VTT 文件中提供标题。我无法在 MVC 方法中正确提供 VTT 文件,但可以正常使用静态 HTML 文件。
现在我让 VTT 在 Rails 中工作的唯一方法是将 VTT 文件放在公共目录中,这需要我将它们 Git 到 Heroku 应用程序。
所以我想知道通过将文本内容放入数据库本身来动态呈现它们。
这是我正在考虑的结构
...
TextTracks
a one to many relationship with Videos
label:string
kind:string
srclang:string
default:boolean
cues-->
a one to many relationship with TextTracks
cue identifier number (sequential)
start_time
end_time
cue_settings (controls placement on screen)
line_1
line_2
...
提示块如下所示:
1
0:00:10.200 --> 0:00:15.000 [cue settings]
Hi, my name is John Doe.
This is a second line
我的问题是,我怎样才能在 view/videos 目录中的 text_track.vtt.erb 文件中获取这些信息?然后在 player.html.haml 的代码中引用这个?像这样:
- if @video.text_tracks.count > 0
- @video.text_tracks.each do |track|
%track{label: "#{track.label}", kind: "#{track.kind}", srclang: "#{track.srclang}", src: "#{REFERENCE_VTT_FILE}", default: "#{track.default}"}
text_track.vtt.erb 需要类似于:
WEBVTT
kind: <% @text_track.kind %>
lang: <% @text_track.srclang %>
<% - @text_track.cues.each do |cue| %>
<%= cue.number %>
<%= cue.start_time %> --> <%= cue.end_time %> <%= cue.cue_settings %>
<%= cue.line_1 %>
<%= cue.line_2 %>
<% end %>
任何帮助或建议将不胜感激。