Skip to content

Commit 36828da

Browse files
authored
Merge branch 'master' into bump-hls-js
2 parents ff37867 + 6fc8b43 commit 36828da

File tree

5 files changed

+91
-8
lines changed

5 files changed

+91
-8
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@stremio/stremio-video",
3-
"version": "0.0.29-beta.2",
3+
"version": "0.0.31",
44
"description": "Abstraction layer on top of different media players",
55
"author": "Smart Code OOD",
66
"main": "src/index.js",

src/TizenVideo/TizenVideo.js

+29-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ function TizenVideo(options) {
2424
var textColor = 'rgb(255, 255, 255)';
2525
var backgroundColor = 'rgba(0, 0, 0, 0)';
2626
var outlineColor = 'rgb(34, 34, 34)';
27+
var subtitlesOpacity = 1;
2728

2829
var objElement = document.createElement('object');
2930
objElement.type = 'application/avplayer';
@@ -59,6 +60,8 @@ function TizenVideo(options) {
5960
}
6061

6162
subtitlesElement.style.bottom = offset + '%';
63+
subtitlesElement.style.opacity = subtitlesOpacity;
64+
6265
var cueNode = document.createElement('span');
6366
cueNode.innerHTML = text;
6467
cueNode.style.display = 'inline-block';
@@ -138,6 +141,7 @@ function TizenVideo(options) {
138141
subtitlesTextColor: false,
139142
subtitlesBackgroundColor: false,
140143
subtitlesOutlineColor: false,
144+
subtitlesOpacity: false,
141145
audioTracks: false,
142146
selectedAudioTrackId: false,
143147
playbackSpeed: false
@@ -272,6 +276,13 @@ function TizenVideo(options) {
272276

273277
return outlineColor;
274278
}
279+
case 'subtitlesOpacity': {
280+
if (destroyed) {
281+
return null;
282+
}
283+
284+
return subtitlesOpacity;
285+
}
275286
case 'audioTracks': {
276287
if (stream === null) {
277288
return [];
@@ -506,6 +517,22 @@ function TizenVideo(options) {
506517

507518
break;
508519
}
520+
case 'subtitlesOpacity': {
521+
if (typeof propValue === 'number') {
522+
try {
523+
subtitlesOpacity = Math.min(Math.max(propValue / 100, 0), 1);
524+
} catch (error) {
525+
// eslint-disable-next-line no-console
526+
console.error('Tizen player with HTML Subtitles', error);
527+
}
528+
529+
refreshSubtitle();
530+
531+
onPropChanged('subtitlesOpacity');
532+
}
533+
534+
break;
535+
}
509536
case 'selectedAudioTrackId': {
510537
if (stream !== null) {
511538

@@ -608,6 +635,7 @@ function TizenVideo(options) {
608635
onPropChanged('subtitlesTextColor');
609636
onPropChanged('subtitlesBackgroundColor');
610637
onPropChanged('subtitlesOutlineColor');
638+
onPropChanged('subtitlesOpacity');
611639
onPropChanged('playbackSpeed');
612640
events.removeAllListeners();
613641
containerElement.removeChild(objElement);
@@ -657,7 +685,7 @@ TizenVideo.canPlayStream = function() {
657685
TizenVideo.manifest = {
658686
name: 'TizenVideo',
659687
external: false,
660-
props: ['stream', 'paused', 'time', 'duration', 'buffering', 'audioTracks', 'selectedAudioTrackId', 'subtitlesTracks', 'selectedSubtitlesTrackId', 'subtitlesOffset', 'subtitlesSize', 'subtitlesTextColor', 'subtitlesBackgroundColor', 'subtitlesOutlineColor', 'playbackSpeed'],
688+
props: ['stream', 'paused', 'time', 'duration', 'buffering', 'audioTracks', 'selectedAudioTrackId', 'subtitlesTracks', 'selectedSubtitlesTrackId', 'subtitlesOffset', 'subtitlesSize', 'subtitlesTextColor', 'subtitlesBackgroundColor', 'subtitlesOutlineColor', 'subtitlesOpacity', 'playbackSpeed'],
661689
commands: ['load', 'unload', 'destroy'],
662690
events: ['propValue', 'propChanged', 'ended', 'error', 'subtitlesTrackLoaded', 'audioTrackLoaded']
663691
};

src/WebOsVideo/WebOsVideo.js

+27-1
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ function WebOsVideo(options) {
430430
var stream = null;
431431
var startTime = null;
432432
var subtitlesOffset = 0;
433+
var subtitlesOpacity = 255;
433434
var observedProps = {
434435
stream: false,
435436
paused: false,
@@ -443,6 +444,7 @@ function WebOsVideo(options) {
443444
subtitlesSize: false,
444445
subtitlesTextColor: false,
445446
subtitlesBackgroundColor: false,
447+
subtitlesOpacity: false,
446448
audioTracks: false,
447449
selectedAudioTrackId: false,
448450
volume: false,
@@ -539,6 +541,13 @@ function WebOsVideo(options) {
539541

540542
return lastSubBgColor || 'rgba(255, 255, 255, 0)';
541543
}
544+
case 'subtitlesOpacity': {
545+
if (destroyed) {
546+
return null;
547+
}
548+
549+
return subtitlesOpacity || 255;
550+
}
542551
case 'audioTracks': {
543552
return audioTracks;
544553
}
@@ -821,6 +830,22 @@ function WebOsVideo(options) {
821830

822831
break;
823832
}
833+
case 'subtitlesOpacity': {
834+
if (typeof propValue === 'number') {
835+
luna({
836+
method: 'setSubtitleBackgroundOpacity',
837+
parameters: {
838+
'mediaId': knownMediaId,
839+
'bgOpacity': Math.min(Math.max(propValue / 0.4, 0), 255),
840+
}
841+
});
842+
843+
subtitlesOpacity = propValue;
844+
onPropChanged('subtitlesOpacity');
845+
}
846+
847+
break;
848+
}
824849
case 'selectedAudioTrackId': {
825850
// console.log('WebOS', 'change audio track for id: ', knownMediaId, ' index:', propValue);
826851

@@ -1014,6 +1039,7 @@ function WebOsVideo(options) {
10141039
onPropChanged('subtitlesSize');
10151040
onPropChanged('subtitlesTextColor');
10161041
onPropChanged('subtitlesBackgroundColor');
1042+
onPropChanged('subtitlesOpacity');
10171043
onPropChanged('volume');
10181044
onPropChanged('muted');
10191045
onPropChanged('playbackSpeed');
@@ -1084,7 +1110,7 @@ WebOsVideo.canPlayStream = function() { // function(stream)
10841110
WebOsVideo.manifest = {
10851111
name: 'WebOsVideo',
10861112
external: false,
1087-
props: ['stream', 'paused', 'time', 'duration', 'buffering', 'buffered', 'audioTracks', 'selectedAudioTrackId', 'subtitlesTracks', 'selectedSubtitlesTrackId', 'subtitlesOffset', 'subtitlesSize', 'subtitlesTextColor', 'subtitlesBackgroundColor', 'volume', 'muted', 'playbackSpeed'],
1113+
props: ['stream', 'paused', 'time', 'duration', 'buffering', 'buffered', 'audioTracks', 'selectedAudioTrackId', 'subtitlesTracks', 'selectedSubtitlesTrackId', 'subtitlesOffset', 'subtitlesSize', 'subtitlesTextColor', 'subtitlesBackgroundColor', 'subtitlesOpacity', 'volume', 'muted', 'playbackSpeed'],
10881114
commands: ['load', 'unload', 'destroy'],
10891115
events: ['propValue', 'propChanged', 'ended', 'error', 'subtitlesTrackLoaded', 'audioTrackLoaded']
10901116
};

src/mediaCapabilities.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ var VIDEO_CODEC_CONFIGS = [
66
},
77
{
88
codec: 'h265',
9-
force: window.chrome || window.cast,
9+
// Disabled because chrome only has partial support for h265/hvec,
10+
// force: window.chrome || window.cast,
1011
mime: 'video/mp4; codecs="hev1.1.6.L150.B0"',
1112
aliases: ['hevc']
1213
},

src/withHTMLSubtitles/withHTMLSubtitles.js

+32-4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ function withHTMLSubtitles(Video) {
5353
var textColor = 'rgb(255, 255, 255)';
5454
var backgroundColor = 'rgba(0, 0, 0, 0)';
5555
var outlineColor = 'rgb(34, 34, 34)';
56+
var opacity = 1;
5657
var observedProps = {
5758
extraSubtitlesTracks: false,
5859
selectedExtraSubtitlesTrackId: false,
@@ -61,7 +62,8 @@ function withHTMLSubtitles(Video) {
6162
extraSubtitlesOffset: false,
6263
extraSubtitlesTextColor: false,
6364
extraSubtitlesBackgroundColor: false,
64-
extraSubtitlesOutlineColor: false
65+
extraSubtitlesOutlineColor: false,
66+
extraSubtitlesOpacity: false
6567
};
6668

6769
function renderSubtitles() {
@@ -74,9 +76,11 @@ function withHTMLSubtitles(Video) {
7476
}
7577

7678
subtitlesElement.style.bottom = offset + '%';
77-
subtitlesRenderer.render(cuesByTime, videoState.time + delay).forEach(function(cueNode) {
79+
subtitlesElement.style.opacity = opacity;
80+
subtitlesRenderer.render(cuesByTime, videoState.time - delay).forEach(function(cueNode) {
7881
cueNode.style.display = 'inline-block';
7982
cueNode.style.padding = '0.2em';
83+
cueNode.style.whiteSpace = 'pre-wrap';
8084
cueNode.style.fontSize = Math.floor(size / 25) + 'vmin';
8185
cueNode.style.color = textColor;
8286
cueNode.style.backgroundColor = backgroundColor;
@@ -177,6 +181,13 @@ function withHTMLSubtitles(Video) {
177181

178182
return outlineColor;
179183
}
184+
case 'extraSubtitlesOpacity': {
185+
if (destroyed) {
186+
return null;
187+
}
188+
189+
return opacity;
190+
}
180191
default: {
181192
return videoPropValue;
182193
}
@@ -191,7 +202,8 @@ function withHTMLSubtitles(Video) {
191202
case 'extraSubtitlesOffset':
192203
case 'extraSubtitlesTextColor':
193204
case 'extraSubtitlesBackgroundColor':
194-
case 'extraSubtitlesOutlineColor': {
205+
case 'extraSubtitlesOutlineColor':
206+
case 'extraSubtitlesOpacity': {
195207
events.emit('propValue', propName, getProp(propName, null));
196208
observedProps[propName] = true;
197209
return true;
@@ -325,6 +337,21 @@ function withHTMLSubtitles(Video) {
325337

326338
return true;
327339
}
340+
case 'extraSubtitlesOpacity': {
341+
if (typeof propValue === 'number') {
342+
try {
343+
opacity = Math.min(Math.max(propValue / 100, 0), 1);
344+
} catch (error) {
345+
// eslint-disable-next-line no-console
346+
console.error('withHTMLSubtitles', error);
347+
}
348+
349+
renderSubtitles();
350+
onPropChanged('extraSubtitlesOpacity');
351+
}
352+
353+
return true;
354+
}
328355
default: {
329356
return false;
330357
}
@@ -386,6 +413,7 @@ function withHTMLSubtitles(Video) {
386413
onPropChanged('extraSubtitlesTextColor');
387414
onPropChanged('extraSubtitlesBackgroundColor');
388415
onPropChanged('extraSubtitlesOutlineColor');
416+
onPropChanged('extraSubtitlesOpacity');
389417
video.dispatch({ type: 'command', commandName: 'destroy' });
390418
events.removeAllListeners();
391419
containerElement.removeChild(subtitlesElement);
@@ -447,7 +475,7 @@ function withHTMLSubtitles(Video) {
447475
VideoWithHTMLSubtitles.manifest = {
448476
name: Video.manifest.name + 'WithHTMLSubtitles',
449477
external: Video.manifest.external,
450-
props: Video.manifest.props.concat(['extraSubtitlesTracks', 'selectedExtraSubtitlesTrackId', 'extraSubtitlesDelay', 'extraSubtitlesSize', 'extraSubtitlesOffset', 'extraSubtitlesTextColor', 'extraSubtitlesBackgroundColor', 'extraSubtitlesOutlineColor'])
478+
props: Video.manifest.props.concat(['extraSubtitlesTracks', 'selectedExtraSubtitlesTrackId', 'extraSubtitlesDelay', 'extraSubtitlesSize', 'extraSubtitlesOffset', 'extraSubtitlesTextColor', 'extraSubtitlesBackgroundColor', 'extraSubtitlesOutlineColor', 'extraSubtitlesOpacity'])
451479
.filter(function(value, index, array) { return array.indexOf(value) === index; }),
452480
commands: Video.manifest.commands.concat(['load', 'unload', 'destroy', 'addExtraSubtitlesTracks'])
453481
.filter(function(value, index, array) { return array.indexOf(value) === index; }),

0 commit comments

Comments
 (0)