@stremio/stremio-video 0.0.62 → 0.0.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/TizenVideo/TizenVideo.js +24 -25
- package/src/TizenVideo/AVPlay.js +0 -98
package/package.json
CHANGED
|
@@ -4,7 +4,6 @@ var deepFreeze = require('deep-freeze');
|
|
|
4
4
|
var Color = require('color');
|
|
5
5
|
var ERROR = require('../error');
|
|
6
6
|
var getTracksData = require('../tracksData');
|
|
7
|
-
var createAVPlay = require('./AVPlay');
|
|
8
7
|
|
|
9
8
|
var SSA_DESCRIPTORS_REGEX = /^\{(\\an[1-8])+\}/i;
|
|
10
9
|
|
|
@@ -21,7 +20,7 @@ function TizenVideo(options) {
|
|
|
21
20
|
throw new Error('Container element required to be instance of HTMLElement');
|
|
22
21
|
}
|
|
23
22
|
|
|
24
|
-
var AVPlay =
|
|
23
|
+
var AVPlay = window.webapis.avplay;
|
|
25
24
|
|
|
26
25
|
var promiseAudioTrackChange = false;
|
|
27
26
|
|
|
@@ -41,17 +40,17 @@ function TizenVideo(options) {
|
|
|
41
40
|
var lastSub;
|
|
42
41
|
var disabledSubs = false;
|
|
43
42
|
|
|
44
|
-
|
|
43
|
+
function refreshSubtitle() {
|
|
45
44
|
if (lastSub) {
|
|
46
|
-
var currentTime =
|
|
45
|
+
var currentTime = getProp('time');
|
|
47
46
|
var lastSubDurationDiff = lastSub.duration - (currentTime - lastSub.now);
|
|
48
47
|
if (lastSubDurationDiff > 0) renderSubtitle(lastSubDurationDiff, lastSub.text);
|
|
49
48
|
}
|
|
50
49
|
}
|
|
51
50
|
|
|
52
|
-
|
|
51
|
+
function renderSubtitle(duration, text) {
|
|
53
52
|
if (disabledSubs) return;
|
|
54
|
-
var now =
|
|
53
|
+
var now = getProp('time');
|
|
55
54
|
var cleanedText = text.replace(SSA_DESCRIPTORS_REGEX, '');
|
|
56
55
|
|
|
57
56
|
// we ignore custom delay here, it's not needed for embedded subs
|
|
@@ -178,7 +177,7 @@ function TizenVideo(options) {
|
|
|
178
177
|
}
|
|
179
178
|
}
|
|
180
179
|
|
|
181
|
-
|
|
180
|
+
function getProp(propName) {
|
|
182
181
|
switch (propName) {
|
|
183
182
|
case 'stream': {
|
|
184
183
|
return stream;
|
|
@@ -191,7 +190,7 @@ function TizenVideo(options) {
|
|
|
191
190
|
return null;
|
|
192
191
|
}
|
|
193
192
|
|
|
194
|
-
var state =
|
|
193
|
+
var state = AVPlay.getState();
|
|
195
194
|
var isPaused = !!(state === 'PAUSED');
|
|
196
195
|
|
|
197
196
|
if (!isPaused && promiseAudioTrackChange) {
|
|
@@ -202,7 +201,7 @@ function TizenVideo(options) {
|
|
|
202
201
|
return isPaused;
|
|
203
202
|
}
|
|
204
203
|
case 'time': {
|
|
205
|
-
var currentTime =
|
|
204
|
+
var currentTime = AVPlay.getCurrentTime();
|
|
206
205
|
if (stream === null || currentTime === null || !isFinite(currentTime)) {
|
|
207
206
|
return null;
|
|
208
207
|
}
|
|
@@ -210,7 +209,7 @@ function TizenVideo(options) {
|
|
|
210
209
|
return Math.floor(currentTime);
|
|
211
210
|
}
|
|
212
211
|
case 'duration': {
|
|
213
|
-
var duration =
|
|
212
|
+
var duration = AVPlay.getDuration();
|
|
214
213
|
if (stream === null || duration === null || !isFinite(duration)) {
|
|
215
214
|
return null;
|
|
216
215
|
}
|
|
@@ -229,7 +228,7 @@ function TizenVideo(options) {
|
|
|
229
228
|
return [];
|
|
230
229
|
}
|
|
231
230
|
|
|
232
|
-
var totalTrackInfo =
|
|
231
|
+
var totalTrackInfo = AVPlay.getTotalTrackInfo();
|
|
233
232
|
var textTracks = [];
|
|
234
233
|
|
|
235
234
|
for (var i = 0; i < totalTrackInfo.length; i++) {
|
|
@@ -272,7 +271,7 @@ function TizenVideo(options) {
|
|
|
272
271
|
return null;
|
|
273
272
|
}
|
|
274
273
|
|
|
275
|
-
var currentTracks =
|
|
274
|
+
var currentTracks = AVPlay.getCurrentStreamInfo();
|
|
276
275
|
var currentIndex;
|
|
277
276
|
|
|
278
277
|
for (var i = 0; i < currentTracks.length; i++) {
|
|
@@ -333,7 +332,7 @@ function TizenVideo(options) {
|
|
|
333
332
|
return [];
|
|
334
333
|
}
|
|
335
334
|
|
|
336
|
-
var totalTrackInfo =
|
|
335
|
+
var totalTrackInfo = AVPlay.getTotalTrackInfo();
|
|
337
336
|
var audioTracks = [];
|
|
338
337
|
|
|
339
338
|
for (var i = 0; i < totalTrackInfo.length; i++) {
|
|
@@ -380,7 +379,7 @@ function TizenVideo(options) {
|
|
|
380
379
|
return promiseAudioTrackChange;
|
|
381
380
|
}
|
|
382
381
|
|
|
383
|
-
var currentTracks =
|
|
382
|
+
var currentTracks = AVPlay.getCurrentStreamInfo();
|
|
384
383
|
var currentIndex = false;
|
|
385
384
|
|
|
386
385
|
for (var i = 0; i < currentTracks.length; i++) {
|
|
@@ -414,20 +413,20 @@ function TizenVideo(options) {
|
|
|
414
413
|
function onEnded() {
|
|
415
414
|
events.emit('ended');
|
|
416
415
|
}
|
|
417
|
-
|
|
416
|
+
function onPropChanged(propName) {
|
|
418
417
|
if (observedProps[propName]) {
|
|
419
|
-
var propValue =
|
|
418
|
+
var propValue = getProp(propName);
|
|
420
419
|
events.emit('propChanged', propName, propValue);
|
|
421
420
|
}
|
|
422
421
|
}
|
|
423
|
-
|
|
422
|
+
function observeProp(propName) {
|
|
424
423
|
if (observedProps.hasOwnProperty(propName)) {
|
|
425
|
-
var propValue =
|
|
424
|
+
var propValue = getProp(propName);
|
|
426
425
|
events.emit('propValue', propName, propValue);
|
|
427
426
|
observedProps[propName] = true;
|
|
428
427
|
}
|
|
429
428
|
}
|
|
430
|
-
|
|
429
|
+
function setProp(propName, propValue) {
|
|
431
430
|
switch (propName) {
|
|
432
431
|
case 'paused': {
|
|
433
432
|
if (stream !== null) {
|
|
@@ -446,10 +445,10 @@ function TizenVideo(options) {
|
|
|
446
445
|
|
|
447
446
|
// the paused state is usually correct, but i have seen it not change on tizen 3
|
|
448
447
|
// which causes all kinds of issues in the UI: (only happens with some videos)
|
|
449
|
-
var lastKnownProp =
|
|
448
|
+
var lastKnownProp = getProp('paused');
|
|
450
449
|
|
|
451
|
-
setTimeout(
|
|
452
|
-
if (
|
|
450
|
+
setTimeout(function() {
|
|
451
|
+
if (getProp('paused') !== lastKnownProp) {
|
|
453
452
|
onPropChanged('paused');
|
|
454
453
|
}
|
|
455
454
|
}, 1000);
|
|
@@ -478,7 +477,7 @@ function TizenVideo(options) {
|
|
|
478
477
|
|
|
479
478
|
currentSubTrack = propValue;
|
|
480
479
|
|
|
481
|
-
var subtitlesTracks =
|
|
480
|
+
var subtitlesTracks = getProp('subtitlesTracks');
|
|
482
481
|
var selectedSubtitlesTrack = subtitlesTracks
|
|
483
482
|
.find(function(track) {
|
|
484
483
|
return track.id === propValue;
|
|
@@ -584,13 +583,13 @@ function TizenVideo(options) {
|
|
|
584
583
|
if (stream !== null) {
|
|
585
584
|
currentAudioTrack = propValue;
|
|
586
585
|
|
|
587
|
-
var audioTracks =
|
|
586
|
+
var audioTracks = getProp('audioTracks');
|
|
588
587
|
var selectedAudioTrack = audioTracks
|
|
589
588
|
.find(function(track) {
|
|
590
589
|
return track.id === propValue;
|
|
591
590
|
});
|
|
592
591
|
|
|
593
|
-
if (
|
|
592
|
+
if (getProp('paused')) {
|
|
594
593
|
// issues before this logic:
|
|
595
594
|
// tizen 3 does not allow changing audio track when paused
|
|
596
595
|
// tizen 5 does, but it will only change getProp('selectedAudioTrackId') after playback starts
|
package/src/TizenVideo/AVPlay.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
const SCOPE = 'AVPlay';
|
|
2
|
-
|
|
3
|
-
const createAVPlay = (transport) => {
|
|
4
|
-
const getState = () => {
|
|
5
|
-
return transport.request(SCOPE, 'getState');
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
const getCurrentTime = () => {
|
|
9
|
-
return transport.request(SCOPE, 'getCurrentTime');
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const getDuration = () => {
|
|
13
|
-
return transport.request(SCOPE, 'getDuration');
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const getTotalTrackInfo = () => {
|
|
17
|
-
return transport.request(SCOPE, 'getTotalTrackInfo');
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const getCurrentStreamInfo = () => {
|
|
21
|
-
return transport.request(SCOPE, 'getCurrentStreamInfo');
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const open = (path) => {
|
|
25
|
-
return transport.request(SCOPE, 'open', path);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const prepareAsync = async (successHandler, errorHandler) => {
|
|
29
|
-
const [handler, handlerResult] = await transport.request(SCOPE, 'prepareAsync', 'handler:success', 'handler:error');
|
|
30
|
-
if (handler === 'handler:success') successHandler();
|
|
31
|
-
if (handler === 'handler:error') errorHandler(...handlerResult);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const pause = () => {
|
|
35
|
-
return transport.request(SCOPE, 'pause');
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const play = () => {
|
|
39
|
-
return transport.request(SCOPE, 'play');
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const stop = () => {
|
|
43
|
-
return transport.request(SCOPE, 'stop');
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const seekTo = (time) => {
|
|
47
|
-
return transport.request(SCOPE, 'seekTo', time);
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const setSpeed = (rate) => {
|
|
51
|
-
return transport.request(SCOPE, 'setSpeed', rate);
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const setSelectTrack = (type, id) => {
|
|
55
|
-
return transport.request(SCOPE, 'setSelectTrack', type, id);
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
const setDisplayRect = (x, y, width, height) => {
|
|
59
|
-
return transport.request(SCOPE, 'setDisplayRect', x, y, width, height);
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const setDisplayMethod = (method) => {
|
|
63
|
-
return transport.request(SCOPE, 'setDisplayMethod', method);
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const setListener = (listener) => {
|
|
67
|
-
const handlers = Object.keys(listener).map((name) => `handler:${name}`);
|
|
68
|
-
const onHandlerResponse = (handler, handlerResult) => {
|
|
69
|
-
const name = handler.replace('handler:', '');
|
|
70
|
-
if (listener[name]) {
|
|
71
|
-
handlerResult ? listener[name](...handlerResult) : listener[name]();
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
transport.listen(SCOPE, 'setListener', onHandlerResponse, ...handlers);
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
return {
|
|
79
|
-
getState,
|
|
80
|
-
getCurrentTime,
|
|
81
|
-
getDuration,
|
|
82
|
-
getTotalTrackInfo,
|
|
83
|
-
getCurrentStreamInfo,
|
|
84
|
-
open,
|
|
85
|
-
prepareAsync,
|
|
86
|
-
pause,
|
|
87
|
-
play,
|
|
88
|
-
stop,
|
|
89
|
-
seekTo,
|
|
90
|
-
setSpeed,
|
|
91
|
-
setSelectTrack,
|
|
92
|
-
setDisplayRect,
|
|
93
|
-
setDisplayMethod,
|
|
94
|
-
setListener,
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
module.exports = createAVPlay;
|