Skip to content

Commit 29ce393

Browse files
committed
Implement subtitles for the videojs player
1 parent ad5b543 commit 29ce393

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

platform/video.videojs/backend.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ var Player = function(ui) {
5151
}
5252
}
5353

54+
var subtitleContainer = document.querySelector('.vjs-text-track-display');
55+
if (subtitleContainer) {
56+
subtitleContainer.style.top = '90%';
57+
subtitleContainer.style.left = '10%';
58+
subtitleContainer.style.width = '80%';
59+
subtitleContainer.style.fontSize = '28px';
60+
subtitleContainer.style.textAlign = 'center';
61+
}
62+
5463
this.videojsContaner = document.getElementById(uniqueId)
5564
this.videojsContaner.style.zindex = -1
5665
}
@@ -84,6 +93,37 @@ Player.prototype.setSource = function(url) {
8493
this.play()
8594
}
8695

96+
Player.prototype.getSubtitles = function() {
97+
var tracks = this.videojs.textTracks()
98+
var subsTracks = []
99+
for (var i = 0; i < tracks.tracks_.length; ++i) {
100+
var track = tracks.tracks_[i]
101+
subsTracks.push({
102+
id: track.id,
103+
active: track.mode == 'showing',
104+
language: track.language,
105+
label: track.label
106+
})
107+
}
108+
return subsTracks
109+
}
110+
111+
Player.prototype.setSubtitles = function(trackId) {
112+
var tracks = this.videojs.textTracks().tracks_
113+
114+
var subTrack = tracks.find(function(track) {
115+
return track.id === trackId
116+
})
117+
118+
tracks.map(function(track) {
119+
if (subTrack && track.id === subTrack.id) {
120+
track.mode = 'showing'
121+
} else {
122+
track.mode = 'disabled'
123+
}
124+
})
125+
}
126+
87127
Player.prototype.play = function() {
88128
var playPromise = this.element.dom.play()
89129
if (playPromise !== undefined) {

0 commit comments

Comments
 (0)