ovenplayer 0.10.46 → 0.10.48

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.
@@ -1,67 +1,67 @@
1
- /**
2
- * Created by hoho on 2018. 7. 4..
3
- */
4
- import SrtParser from "api/caption/parser/SrtParser";
5
- import WebVTT from 'api/caption/parser/VttParser'
6
- import VTTCue from 'utils/captions/vttCue'
7
- import SmiParser from 'api/caption/parser/SmiParser'
8
-
9
- const Loader = function () {
10
- const that = {};
11
-
12
- const convertToVTTCues = function (cues) {
13
- return cues.map(cue => new VTTCue(cue.start, cue.end, cue.text));
14
- };
15
-
16
- that.load = (track, language, successCallback, errorCallback) => {
17
-
18
- fetch(track.file).then(function (response) {
19
- if (response.ok) {
20
-
21
- response.text().then(function (body) {
22
- let cues = [];
23
- let vttCues = [];
24
-
25
- if (body.indexOf('WEBVTT') >= 0) {
26
- OvenPlayerConsole.log("WEBVTT LOADED");
27
- let parser = new WebVTT.Parser(window, WebVTT.StringDecoder());
28
- vttCues = [];
29
- parser.oncue = function (cue) {
30
- vttCues.push(cue);
31
- };
32
- parser.onflush = function () {
33
- //delete track.xhr;
34
- successCallback(vttCues);
35
- };
36
- // Parse calls onflush internally
37
- parser.parse(body);
38
- parser.flush();
39
- } else if (body.indexOf('SAMI') >= 0) {
40
- OvenPlayerConsole.log("SAMI LOADED");
41
- let parsedData = SmiParser(body, {fixedLang: language});
42
- vttCues = convertToVTTCues(parsedData.result);
43
- successCallback(vttCues);
44
-
45
- } else {
46
- OvenPlayerConsole.log("SRT LOADED");
47
- cues = SrtParser(body);
48
- vttCues = convertToVTTCues(cues);
49
- successCallback(vttCues);
50
- }
51
- }).catch(function (e) {
52
- errorCallback(e);
53
- });
54
-
55
- } else {
56
- errorCallback(response.status);
57
- }
58
- }).catch(function (e) {
59
- errorCallback(e);
60
- });
61
-
62
- };
63
-
64
- return that;
65
- };
66
-
67
- export default Loader;
1
+ /**
2
+ * Created by hoho on 2018. 7. 4..
3
+ */
4
+ import SrtParser from "api/caption/parser/SrtParser";
5
+ import WebVTT from 'api/caption/parser/VttParser'
6
+ import VTTCue from 'utils/captions/vttCue'
7
+ import SmiParser from 'api/caption/parser/SmiParser'
8
+
9
+ const Loader = function () {
10
+ const that = {};
11
+
12
+ const convertToVTTCues = function (cues) {
13
+ return cues.map(cue => new VTTCue(cue.start, cue.end, cue.text));
14
+ };
15
+
16
+ that.load = (track, language, successCallback, errorCallback) => {
17
+
18
+ fetch(track.file).then(function (response) {
19
+ if (response.ok) {
20
+
21
+ response.text().then(function (body) {
22
+ let cues = [];
23
+ let vttCues = [];
24
+
25
+ if (body.indexOf('WEBVTT') >= 0) {
26
+ OvenPlayerConsole.log("WEBVTT LOADED");
27
+ let parser = new WebVTT.Parser(window, WebVTT.StringDecoder());
28
+ vttCues = [];
29
+ parser.oncue = function (cue) {
30
+ vttCues.push(cue);
31
+ };
32
+ parser.onflush = function () {
33
+ //delete track.xhr;
34
+ successCallback(vttCues);
35
+ };
36
+ // Parse calls onflush internally
37
+ parser.parse(body);
38
+ parser.flush();
39
+ } else if (body.indexOf('SAMI') >= 0) {
40
+ OvenPlayerConsole.log("SAMI LOADED");
41
+ let parsedData = SmiParser(body, {fixedLang: language});
42
+ vttCues = convertToVTTCues(parsedData.result);
43
+ successCallback(vttCues);
44
+
45
+ } else {
46
+ OvenPlayerConsole.log("SRT LOADED");
47
+ cues = SrtParser(body);
48
+ vttCues = convertToVTTCues(cues);
49
+ successCallback(vttCues);
50
+ }
51
+ }).catch(function (e) {
52
+ errorCallback(e);
53
+ });
54
+
55
+ } else {
56
+ errorCallback(response.status);
57
+ }
58
+ }).catch(function (e) {
59
+ errorCallback(e);
60
+ });
61
+
62
+ };
63
+
64
+ return that;
65
+ };
66
+
67
+ export default Loader;
@@ -1,141 +1,143 @@
1
- /**
2
- * Created by hoho on 2018. 5. 17..
3
- */
4
- import CaptionLoader from 'api/caption/Loader';
5
- import {READY, ERRORS, ERROR, PLAYER_CAPTION_ERROR, CONTENT_META, CONTENT_TIME, CONTENT_CAPTION_CUE_CHANGED, CONTENT_CAPTION_CHANGED} from "api/constants";
6
- import _ from "utils/underscore";
7
-
8
- const isSupport = function(kind){
9
- return kind === 'subtitles' || kind === 'captions';
10
- };
11
-
12
- const Manager = function(api, playlistIndex){
13
-
14
- const that = {};
15
- let captionList = [];
16
- let currentCaptionIndex = -1;
17
-
18
- let captionLoader = CaptionLoader();
19
- let isFisrtLoad = true;
20
- let isShowing = false;
21
-
22
- OvenPlayerConsole.log("Caption Manager >> ", playlistIndex);
23
-
24
-
25
- let bindTrack = function(track, vttCues){
26
- track.data = vttCues || [];
27
- track.name = track.label || track.name || track.language;
28
- track.id = (function(track, tracksCount) {
29
- var trackId;
30
- var prefix = track.kind || 'cc';
31
- if (track.default || track.defaulttrack) {
32
- trackId = 'default';
33
-
34
- } else {
35
- trackId = track.id || (prefix + tracksCount);
36
- }
37
- if(isFisrtLoad){
38
- //This execute only on. and then use flushCaptionList(lastCaptionIndex);
39
- changeCurrentCaption(captionList.length||0);
40
- isFisrtLoad = false;
41
-
42
- }
43
- return trackId;
44
- })(track, captionList.length);
45
-
46
- captionList.push(track);
47
- return track.id;
48
- };
49
- let changeCurrentCaption = function(index){
50
- currentCaptionIndex = index;
51
- api.trigger(CONTENT_CAPTION_CHANGED, currentCaptionIndex);
52
- };
53
- if(api.getConfig().playlist && api.getConfig().playlist.length > 0){
54
- let playlist = api.getConfig().playlist[playlistIndex];
55
-
56
- if(playlist && playlist.tracks && playlist.tracks.length > 0){
57
- for(let i = 0; i < playlist.tracks.length; i ++){
58
- const track = playlist.tracks[i];
59
-
60
- if(isSupport(track.kind) && ! _.findWhere(track, {file : track.file})){
61
- //that.flushCaptionList(currentCaptionIndex);
62
-
63
- captionLoader.load(track, track.lang, function(vttCues){
64
- if(vttCues && vttCues.length > 0){
65
- let captionId = bindTrack(track, vttCues);
66
- }
67
- }, function(error){
68
- let tempError = ERRORS.codes[PLAYER_CAPTION_ERROR];
69
- tempError.error = error;
70
- api.trigger(ERROR, tempError);
71
- });
72
- }
73
- }
74
-
75
- }
76
- }
77
-
78
- api.on(CONTENT_TIME, function(meta){
79
- let position = meta.position;
80
- if(currentCaptionIndex > -1 && captionList[currentCaptionIndex]){
81
- let currentCues = _.filter(captionList[currentCaptionIndex].data, function (cue) {
82
- return position >= (cue.startTime) && ( (!cue.endTime || position) <= cue.endTime);
83
- });
84
- if(currentCues && currentCues.length > 0){
85
- api.trigger(CONTENT_CAPTION_CUE_CHANGED, currentCues[0]);
86
- }
87
- }
88
-
89
- });
90
- that.flushCaptionList = (lastCaptionIndex) =>{
91
- captionList = [];
92
- changeCurrentCaption(lastCaptionIndex);
93
- //currentCaptionIndex = lastCaptionIndex;
94
- };
95
- that.getCaptionList = () =>{
96
- return captionList||[];
97
- };
98
- that.getCurrentCaption = () =>{
99
- return currentCaptionIndex;
100
- };
101
- that.setCurrentCaption = (_index) =>{
102
- if(_index > -2 && _index < captionList.length){
103
- changeCurrentCaption(_index);
104
- }else{
105
- return null;
106
- }
107
- };
108
- that.addCaption = (track) =>{
109
- if(isSupport(track.kind) && ! _.findWhere(captionLoader, {file : track.file})){
110
- captionLoader.load(track, function(vttCues){
111
- if(vttCues && vttCues.length > 0){
112
- bindTrack(track, vttCues);
113
- }
114
- }, function(error){
115
- let tempError = errors[PLAYER_CAPTION_ERROR];
116
- tempError.error = error;
117
- api.trigger(ERROR, tempError);
118
- });
119
- }
120
- };
121
- that.removeCaption = (index) => {
122
- if(index > -1 && index < captionList.length){
123
- captionList.splice(index, 1);
124
- return captionList;
125
- }else{
126
- return null;
127
- }
128
- };
129
- that.destroy = () => {
130
- captionList = [];
131
- captionLoader = null;
132
- api.off(CONTENT_TIME, null, that);
133
- };
134
-
135
- return that;
136
- };
137
-
138
-
139
-
140
-
141
- export default Manager;
1
+ /**
2
+ * Created by hoho on 2018. 5. 17..
3
+ */
4
+ import CaptionLoader from 'api/caption/Loader';
5
+ import {READY, ERRORS, ERROR, PLAYER_CAPTION_ERROR, CONTENT_META, CONTENT_TIME, CONTENT_CAPTION_CUE_CHANGED, CONTENT_CAPTION_CHANGED} from "api/constants";
6
+ import _ from "utils/underscore";
7
+
8
+ const isSupport = function(kind){
9
+ return kind === 'subtitles' || kind === 'captions';
10
+ };
11
+
12
+ const Manager = function(api, playlistIndex){
13
+
14
+ const that = {};
15
+ let captionList = [];
16
+ let currentCaptionIndex = -1;
17
+
18
+ let captionLoader = CaptionLoader();
19
+ let isFisrtLoad = true;
20
+ let isShowing = false;
21
+
22
+ OvenPlayerConsole.log("Caption Manager >> ", playlistIndex);
23
+
24
+
25
+ let bindTrack = function(track, vttCues){
26
+ track.data = vttCues || [];
27
+ track.name = track.label || track.name || track.language;
28
+ track.id = (function(track, tracksCount) {
29
+ var trackId;
30
+ var prefix = track.kind || 'cc';
31
+ if (track.default || track.defaulttrack) {
32
+ trackId = 'default';
33
+
34
+ } else {
35
+ trackId = track.id || (prefix + tracksCount);
36
+ }
37
+ if(isFisrtLoad){
38
+ //This execute only on. and then use flushCaptionList(lastCaptionIndex);
39
+ changeCurrentCaption(captionList.length||0);
40
+ isFisrtLoad = false;
41
+
42
+ }
43
+ return trackId;
44
+ })(track, captionList.length);
45
+
46
+ captionList.push(track);
47
+ return track.id;
48
+ };
49
+ let changeCurrentCaption = function(index){
50
+ currentCaptionIndex = index;
51
+ api.trigger(CONTENT_CAPTION_CHANGED, currentCaptionIndex);
52
+ };
53
+ if(api.getConfig().playlist && api.getConfig().playlist.length > 0){
54
+ let playlist = api.getConfig().playlist[playlistIndex];
55
+
56
+ if(playlist && playlist.tracks && playlist.tracks.length > 0){
57
+ for(let i = 0; i < playlist.tracks.length; i ++){
58
+ const track = playlist.tracks[i];
59
+
60
+ if(isSupport(track.kind) && ! _.findWhere(track, {file : track.file})){
61
+ //that.flushCaptionList(currentCaptionIndex);
62
+
63
+ captionLoader.load(track, track.lang, function(vttCues){
64
+ if (vttCues && vttCues.length > 0) {
65
+ if (!captionList.find(c => c.file === track.file)) {
66
+ let captionId = bindTrack(track, vttCues);
67
+ }
68
+ }
69
+ }, function(error){
70
+ let tempError = ERRORS.codes[PLAYER_CAPTION_ERROR];
71
+ tempError.error = error;
72
+ api.trigger(ERROR, tempError);
73
+ });
74
+ }
75
+ }
76
+
77
+ }
78
+ }
79
+
80
+ api.on(CONTENT_TIME, function(meta){
81
+ let position = meta.position;
82
+ if(currentCaptionIndex > -1 && captionList[currentCaptionIndex]){
83
+ let currentCues = _.filter(captionList[currentCaptionIndex].data, function (cue) {
84
+ return position >= (cue.startTime) && ( (!cue.endTime || position) <= cue.endTime);
85
+ });
86
+ if(currentCues && currentCues.length > 0){
87
+ api.trigger(CONTENT_CAPTION_CUE_CHANGED, currentCues[0]);
88
+ }
89
+ }
90
+
91
+ });
92
+ that.flushCaptionList = (lastCaptionIndex) =>{
93
+ captionList = [];
94
+ changeCurrentCaption(lastCaptionIndex);
95
+ //currentCaptionIndex = lastCaptionIndex;
96
+ };
97
+ that.getCaptionList = () =>{
98
+ return captionList||[];
99
+ };
100
+ that.getCurrentCaption = () =>{
101
+ return currentCaptionIndex;
102
+ };
103
+ that.setCurrentCaption = (_index) =>{
104
+ if(_index > -2 && _index < captionList.length){
105
+ changeCurrentCaption(_index);
106
+ }else{
107
+ return null;
108
+ }
109
+ };
110
+ that.addCaption = (track) =>{
111
+ if(isSupport(track.kind) && ! _.findWhere(captionLoader, {file : track.file})){
112
+ captionLoader.load(track, function(vttCues){
113
+ if(vttCues && vttCues.length > 0){
114
+ bindTrack(track, vttCues);
115
+ }
116
+ }, function(error){
117
+ let tempError = errors[PLAYER_CAPTION_ERROR];
118
+ tempError.error = error;
119
+ api.trigger(ERROR, tempError);
120
+ });
121
+ }
122
+ };
123
+ that.removeCaption = (index) => {
124
+ if(index > -1 && index < captionList.length){
125
+ captionList.splice(index, 1);
126
+ return captionList;
127
+ }else{
128
+ return null;
129
+ }
130
+ };
131
+ that.destroy = () => {
132
+ captionList = [];
133
+ captionLoader = null;
134
+ api.off(CONTENT_TIME, null, that);
135
+ };
136
+
137
+ return that;
138
+ };
139
+
140
+
141
+
142
+
143
+ export default Manager;