ravnur-player-public 3.4.2 → 3.4.4
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/.eslintignore +7 -0
- package/.eslintrc.js +206 -0
- package/.flowconfig +3 -0
- package/.vscode/extensions.json +7 -0
- package/.vscode/launch.json +37 -0
- package/.vscode/settings.json +4 -0
- package/README-Private.md +54 -0
- package/babel.config.js +28 -0
- package/bitbucket-pipelines.yml +61 -0
- package/cert.pem +23 -0
- package/demo/BaseM.mp4 +0 -0
- package/demo/HD.mp4 +0 -0
- package/demo/annotations.json +50 -0
- package/demo/annotations_ge.json +50 -0
- package/demo/base.mp3 +0 -0
- package/demo/cc_2125en.vtt +4958 -0
- package/demo/cc_en.vtt +171 -0
- package/demo/cc_ge.vtt +178 -0
- package/demo/chapters_en.vtt +38 -0
- package/demo/chapters_ge.vtt +5 -0
- package/demo/chapters_ge1.json +23 -0
- package/demo/hls/audio/stereo/en/128kbit.m3u8 +912 -0
- package/demo/hls/audio/stereo/none/128kbit.m3u8 +912 -0
- package/demo/hls/audio/surround/en/320kbit.m3u8 +912 -0
- package/demo/hls/playlist.m3u8 +31 -0
- package/demo/hls/video/10000kbit.m3u8 +894 -0
- package/demo/hls/video/1100kbit.m3u8 +894 -0
- package/demo/hls/video/1500kbit.m3u8 +894 -0
- package/demo/hls/video/250kbit.m3u8 +894 -0
- package/demo/hls/video/4000kbit.m3u8 +894 -0
- package/demo/hls/video/500kbit.m3u8 +894 -0
- package/demo/hls/video/6000kbit.m3u8 +894 -0
- package/demo/hls/video/800kbit.m3u8 +894 -0
- package/demo/hls.js +5 -0
- package/demo/hls.js.map +1 -0
- package/demo/hls.min.js +2 -0
- package/demo/hls.min.js.map +1 -0
- package/demo/playlist.m3u8 +31 -0
- package/demo/ravnur-flash-audio.swf +0 -0
- package/demo/ravnur-flash-video-hls.swf +0 -0
- package/demo/ravnur-flash-video.swf +0 -0
- package/demo/shaka/shaka-player.foo.debug.d.ts +4532 -0
- package/demo/shaka/shaka-player.foo.debug.externs.js +3886 -0
- package/demo/shaka/shaka-player.foo.debug.js +1746 -0
- package/demo/shaka/shaka-player.foo.debug.map +8 -0
- package/demo/shaka/wrapper.js +7 -0
- package/demo/test.html +458 -0
- package/dist/RavnurMediaPlayer.min.js +1 -1
- package/dist/cdn/RavnurMediaPlayer.min.js +1 -1
- package/jest.config.js +4 -0
- package/key.pem +27 -0
- package/lib/es5.js +344 -0
- package/lib/images/Spinner-small.gif +0 -0
- package/lib/images/close.png +0 -0
- package/lib/images/ic_check_box_black_24dp_1x.png +0 -0
- package/lib/images/ic_check_box_outline_blank_black_24dp_1x.png +0 -0
- package/lib/images/ic_chevron_left_white_24dp_1x.png +0 -0
- package/lib/images/ic_chevron_right_white_24dp_1x.png +0 -0
- package/lib/images/ic_closed_caption_white_24dp_1x.png +0 -0
- package/lib/images/ic_fast_forward_white_24dp_1x.png +0 -0
- package/lib/images/ic_fast_rewind_white_24dp_1x.png +0 -0
- package/lib/images/ic_fullscreen_exit_white_24dp_1x.png +0 -0
- package/lib/images/ic_fullscreen_white_24dp_1x.png +0 -0
- package/lib/images/ic_hd_white_24dp_1x.png +0 -0
- package/lib/images/ic_keyboard_arrow_left_black_24dp_1x.png +0 -0
- package/lib/images/ic_keyboard_arrow_right_black_24dp_1x.png +0 -0
- package/lib/images/ic_pause_white_24dp_1x.png +0 -0
- package/lib/images/ic_photo_white_24dp_1x.png +0 -0
- package/lib/images/ic_play_arrow_white_24dp_1x.png +0 -0
- package/lib/images/ic_refresh_white_24dp_1x.png +0 -0
- package/lib/images/ic_settings_white_24dp_1x.png +0 -0
- package/lib/images/ic_skip_next_white_24dp_1x.png +0 -0
- package/lib/images/ic_skip_previous_white_24dp_1x.png +0 -0
- package/lib/images/ic_toc_white_24dp_1x.png +0 -0
- package/lib/images/ic_volume_off_white_24dp_1x.png +0 -0
- package/lib/images/ic_volume_up_white_24dp_1x.png +0 -0
- package/lib/player4ie8.css +225 -0
- package/package.json +1 -5
- package/server.js +29 -0
- package/src/config/cc.js +56 -0
- package/src/config/i18n.js +101 -0
- package/src/config/options.js +123 -0
- package/src/config/playlist.js +9 -0
- package/src/config/source.js +23 -0
- package/src/config/statuses.js +8 -0
- package/src/config/styles.js +16 -0
- package/src/entity.js +27 -0
- package/src/events.js +5 -0
- package/src/extensions/annotations.js +142 -0
- package/src/extensions/audio-tarcks.js +115 -0
- package/src/extensions/backward.js +45 -0
- package/src/extensions/base.js +73 -0
- package/src/extensions/bottom-next.js +50 -0
- package/src/extensions/bottom-prev.js +50 -0
- package/src/extensions/buffering.js +78 -0
- package/src/extensions/c2pa.js +350 -0
- package/src/extensions/caption-search.js +230 -0
- package/src/extensions/cc.js +874 -0
- package/src/extensions/crawl.js +118 -0
- package/src/extensions/download.js +411 -0
- package/src/extensions/error.js +47 -0
- package/src/extensions/forward.js +44 -0
- package/src/extensions/fullscreen.js +84 -0
- package/src/extensions/help.js +201 -0
- package/src/extensions/helpers/FileSaver.js +157 -0
- package/src/extensions/helpers/clickOpener.js +180 -0
- package/src/extensions/helpers/opener.js +30 -0
- package/src/extensions/helpers/openerHeightChecker.js +13 -0
- package/src/extensions/helpers/popover.js +33 -0
- package/src/extensions/helpers/popoverPosition.js +30 -0
- package/src/extensions/helpers/scrollIntoView.js +9 -0
- package/src/extensions/helpers/storage.js +20 -0
- package/src/extensions/helpers/textContent.js +6 -0
- package/src/extensions/helpers/timeCodeToSeconds.js +44 -0
- package/src/extensions/helpers/transport.js +43 -0
- package/src/extensions/helpers/vtt-loader.js +42 -0
- package/src/extensions/index.js +87 -0
- package/src/extensions/live.js +76 -0
- package/src/extensions/mux.js +57 -0
- package/src/extensions/next-frame.js +44 -0
- package/src/extensions/next.js +48 -0
- package/src/extensions/placeholder.js +241 -0
- package/src/extensions/play.js +102 -0
- package/src/extensions/poster.js +47 -0
- package/src/extensions/prev-frame.js +44 -0
- package/src/extensions/prev.js +48 -0
- package/src/extensions/progress.js +465 -0
- package/src/extensions/resizer.js +37 -0
- package/src/extensions/settings.js +367 -0
- package/src/extensions/theater.js +56 -0
- package/src/extensions/title.js +38 -0
- package/src/extensions/toc.js +334 -0
- package/src/extensions/volume.js +196 -0
- package/src/flash/FlashPlugin.js +301 -0
- package/src/flash/MediaElement.js +361 -0
- package/src/flash/plugins.js +32 -0
- package/src/flash-detector.js +66 -0
- package/src/helpers/$t.js +10 -0
- package/src/helpers/binder.js +11 -0
- package/src/helpers/isAndroid.js +5 -0
- package/src/helpers/isBlackBerry.js +5 -0
- package/src/helpers/isCanvasSupported.js +6 -0
- package/src/helpers/isIE.js +21 -0
- package/src/helpers/isMobile.js +10 -0
- package/src/helpers/isWindows.js +5 -0
- package/src/helpers/isWindowsPhone.js +5 -0
- package/src/helpers/isiOS.js +5 -0
- package/src/html5media.js +19 -0
- package/src/index.js +2 -0
- package/src/logger.js +31 -0
- package/src/microevent.js +65 -0
- package/src/normalize-options.js +139 -0
- package/src/player.js +864 -0
- package/src/players/base.js +209 -0
- package/src/players/flash.js +172 -0
- package/src/players/hls.js +278 -0
- package/src/players/html.js +205 -0
- package/src/players/index.js +59 -0
- package/src/players/shaka.js +219 -0
- package/src/playlist.js +362 -0
- package/src/screenfull.js +121 -0
- package/src/state.js +474 -0
- package/src/static/es5.js +344 -0
- package/src/static/images/Spinner-small.gif +0 -0
- package/src/static/images/close.png +0 -0
- package/src/static/images/ic_check_box_black_24dp_1x.png +0 -0
- package/src/static/images/ic_check_box_outline_blank_black_24dp_1x.png +0 -0
- package/src/static/images/ic_chevron_left_white_24dp_1x.png +0 -0
- package/src/static/images/ic_chevron_right_white_24dp_1x.png +0 -0
- package/src/static/images/ic_closed_caption_white_24dp_1x.png +0 -0
- package/src/static/images/ic_fast_forward_white_24dp_1x.png +0 -0
- package/src/static/images/ic_fast_rewind_white_24dp_1x.png +0 -0
- package/src/static/images/ic_fullscreen_exit_white_24dp_1x.png +0 -0
- package/src/static/images/ic_fullscreen_white_24dp_1x.png +0 -0
- package/src/static/images/ic_hd_white_24dp_1x.png +0 -0
- package/src/static/images/ic_keyboard_arrow_left_black_24dp_1x.png +0 -0
- package/src/static/images/ic_keyboard_arrow_right_black_24dp_1x.png +0 -0
- package/src/static/images/ic_pause_white_24dp_1x.png +0 -0
- package/src/static/images/ic_play_arrow_white_24dp_1x.png +0 -0
- package/src/static/images/ic_refresh_white_24dp_1x.png +0 -0
- package/src/static/images/ic_settings_white_24dp_1x.png +0 -0
- package/src/static/images/ic_skip_next_white_24dp_1x.png +0 -0
- package/src/static/images/ic_skip_previous_white_24dp_1x.png +0 -0
- package/src/static/images/ic_toc_white_24dp_1x.png +0 -0
- package/src/static/images/ic_volume_off_white_24dp_1x.png +0 -0
- package/src/static/images/ic_volume_up_white_24dp_1x.png +0 -0
- package/src/static/player4ie8.css +225 -0
- package/src/styles/bplaylist.css.js +124 -0
- package/src/styles/index.js +1966 -0
- package/src/styles/playlist.css.js +84 -0
- package/src/styles/rplaylist.css.js +98 -0
- package/src/svgs.js +111 -0
- package/src/types/Logger.js +10 -0
- package/src/types/Options.js +179 -0
- package/src/types/Playlist.js +3 -0
- package/src/types/Source.js +28 -0
- package/src/types/State.js +46 -0
- package/src/types/Styles.js +11 -0
- package/src/types/TimeData.js +8 -0
- package/src/types/Translation.js +69 -0
- package/src/utils/absolutizeUrl.js +9 -0
- package/src/utils/addClass.js +9 -0
- package/src/utils/addEvent.js +31 -0
- package/src/utils/addProperty.js +65 -0
- package/src/utils/appendChild.js +14 -0
- package/src/utils/buff2hex.js +5 -0
- package/src/utils/contains.js +33 -0
- package/src/utils/createElement.js +24 -0
- package/src/utils/each.js +34 -0
- package/src/utils/escapeHTML.js +8 -0
- package/src/utils/existy.js +4 -0
- package/src/utils/extend.js +17 -0
- package/src/utils/filter.js +16 -0
- package/src/utils/find.js +11 -0
- package/src/utils/findIndex.js +20 -0
- package/src/utils/first.js +5 -0
- package/src/utils/get.js +19 -0
- package/src/utils/has.js +5 -0
- package/src/utils/hasClass.js +6 -0
- package/src/utils/head.js +11 -0
- package/src/utils/inRange.js +16 -0
- package/src/utils/index.js +73 -0
- package/src/utils/isArray.js +4 -0
- package/src/utils/isBoolean.js +3 -0
- package/src/utils/isElement.js +7 -0
- package/src/utils/isEmpty.js +6 -0
- package/src/utils/isEqual.js +33 -0
- package/src/utils/isEqualBuffer.js +13 -0
- package/src/utils/isFunction.js +3 -0
- package/src/utils/isNotEmpty.js +5 -0
- package/src/utils/isObject.js +5 -0
- package/src/utils/isString.js +9 -0
- package/src/utils/last.js +4 -0
- package/src/utils/map.js +11 -0
- package/src/utils/negate.js +8 -0
- package/src/utils/noop.js +1 -0
- package/src/utils/notExisty.js +5 -0
- package/src/utils/reduce.js +8 -0
- package/src/utils/remove.js +7 -0
- package/src/utils/removeClass.js +8 -0
- package/src/utils/removeEvent.js +7 -0
- package/src/utils/toArray.js +7 -0
- package/src/utils/toggleClass.js +16 -0
- package/src/utils/uidGenerator.js +8 -0
- package/src/utils/upperFirst.js +4 -0
- package/tests/extensions/__snapshots__/download.spec.js.snap +226 -0
- package/tests/extensions/__snapshots__/fullscreen.spec.js.snap +30 -0
- package/tests/extensions/__snapshots__/title.spec.js.snap +16 -0
- package/tests/extensions/download.spec.js +111 -0
- package/tests/extensions/fullscreen.spec.js +56 -0
- package/tests/extensions/title.spec.js +35 -0
- package/tests/mocks/assets/BaseM.mp4 +0 -0
- package/tests/mocks/assets/hls.min.js +5 -0
- package/tests/mocks/assets/styleMock.js +1 -0
- package/tests/mocks/base-player-options.js +47 -0
- package/tests/mocks/sources.js +58 -0
- package/tests/mocks/timedata/cc_en.vtt +171 -0
- package/tests/mocks/timedata/cc_ge.vtt +178 -0
- package/tests/utils/wait.js +1 -0
- package/webpack.config.js +78 -0
- package/dist/.DS_Store +0 -0
- package/dist/cdn/.DS_Store +0 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import Entity from '../entity';
|
|
3
|
+
|
|
4
|
+
import type { Player$ControllerOptions } from '../types/Options';
|
|
5
|
+
|
|
6
|
+
const MS_IN_SEC = 1000;
|
|
7
|
+
|
|
8
|
+
export default class BasePlayer extends Entity {
|
|
9
|
+
options: Player$ControllerOptions
|
|
10
|
+
state;
|
|
11
|
+
constructor(options: Player$ControllerOptions, state) {
|
|
12
|
+
super(options.bus, options.logger);
|
|
13
|
+
this.state = state;
|
|
14
|
+
this.logger.debug('player:created');
|
|
15
|
+
this.options = options;
|
|
16
|
+
setTimeout( () => this.getElement().setAttribute('tabindex', '-1') );
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
focus() {
|
|
20
|
+
let el = this.getElement();
|
|
21
|
+
// fix for ff
|
|
22
|
+
if ( this.options.isAudio ) {
|
|
23
|
+
// $FlowFixMe
|
|
24
|
+
el = el.parentNode.parentNode;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if ( el && el instanceof HTMLElement ) {
|
|
28
|
+
el.focus();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
getTimeCode(): number {
|
|
33
|
+
return this.options.timecode;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
getCurrentTime() {
|
|
37
|
+
return this.getElement().currentTime + this.getTimeCode();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
setCurrentTime(time: number, silent: ?boolean = true) {
|
|
41
|
+
if (!this.getElement()) return;
|
|
42
|
+
|
|
43
|
+
time -= this.getTimeCode();
|
|
44
|
+
|
|
45
|
+
const { clip } = this.options;
|
|
46
|
+
if ( clip ) {
|
|
47
|
+
let [ start, end ] = clip;
|
|
48
|
+
start = start || 0;
|
|
49
|
+
end = end || this.getElement().duration;
|
|
50
|
+
time = Math.max(time, start);
|
|
51
|
+
time = Math.min(time, end);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
this.getElement().currentTime = time;
|
|
55
|
+
if ( !silent ) {
|
|
56
|
+
this.focus();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
nextFrame() {
|
|
61
|
+
const frameDuration = this._getFrameDuration();
|
|
62
|
+
let time = this.getElement().currentTime;
|
|
63
|
+
let frameNumber = Math.floor(time * MS_IN_SEC / frameDuration);
|
|
64
|
+
time = Math.ceil(++frameNumber * frameDuration) / MS_IN_SEC;
|
|
65
|
+
this.setCurrentTime(time + this.getTimeCode());
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
prevFrame() {
|
|
69
|
+
const frameDuration = this._getFrameDuration();
|
|
70
|
+
let time = this.getElement().currentTime;
|
|
71
|
+
let frameNumber = Math.floor(time * MS_IN_SEC / frameDuration);
|
|
72
|
+
time = Math.ceil(--frameNumber * frameDuration) / MS_IN_SEC;
|
|
73
|
+
this.setCurrentTime(time + this.getTimeCode());
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
isPaused() {
|
|
77
|
+
if (!this.getElement()) return false;
|
|
78
|
+
return this.getElement().paused;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
isEnded() {
|
|
82
|
+
if (!this.getElement()) return false;
|
|
83
|
+
|
|
84
|
+
const { clip } = this.options;
|
|
85
|
+
if ( clip ) {
|
|
86
|
+
const duration = this.getElement().duration;
|
|
87
|
+
let [ start, end ] = clip; // eslint-disable-line no-unused-vars
|
|
88
|
+
end = end || duration;
|
|
89
|
+
end += this.getTimeCode();
|
|
90
|
+
return this.getCurrentTime() >= end;
|
|
91
|
+
}
|
|
92
|
+
return this.getElement().ended;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
play(silent: ?boolean = true) {
|
|
96
|
+
this.bus.emit('handle-play-clicked');
|
|
97
|
+
if (!silent) {
|
|
98
|
+
this.focus();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const { clip } = this.options;
|
|
102
|
+
if ( this.isEnded() && clip ) {
|
|
103
|
+
const [ start ] = clip;
|
|
104
|
+
this.setCurrentTime(start || 0);
|
|
105
|
+
}
|
|
106
|
+
return this.getElement().play();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
pause(silent: ?boolean = true) {
|
|
110
|
+
if (!silent) {
|
|
111
|
+
this.focus();
|
|
112
|
+
}
|
|
113
|
+
return this.getElement().pause();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
getDuration() {
|
|
117
|
+
if (!this.getElement()) return '';
|
|
118
|
+
|
|
119
|
+
let duration = this.getElement().duration;
|
|
120
|
+
const { clip } = this.options;
|
|
121
|
+
if ( clip ) {
|
|
122
|
+
let [ start, end ] = clip;
|
|
123
|
+
start = start || 0;
|
|
124
|
+
end = end || duration;
|
|
125
|
+
duration = end - start;
|
|
126
|
+
}
|
|
127
|
+
return duration + this.getTimeCode();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
isMuted() {
|
|
131
|
+
return this.getElement().muted;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
setMuted(muted: boolean, silent: ?boolean = true) {
|
|
135
|
+
this.getElement().muted = muted;
|
|
136
|
+
if (!silent) {
|
|
137
|
+
this.focus();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
getVolume() {
|
|
142
|
+
return this.getElement().volume;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
setVolume(volume: number, silent: ?boolean = true) {
|
|
146
|
+
this.getElement().volume = volume;
|
|
147
|
+
if (!silent) {
|
|
148
|
+
this.focus();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
destroy() {
|
|
153
|
+
this.logger.debug('player:destroy');
|
|
154
|
+
super.destroy();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
getLevels() {
|
|
158
|
+
throw new Error('You must override it');
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
getLevel() {
|
|
162
|
+
throw new Error('You must override it');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
setLevel(/* level */) {
|
|
166
|
+
throw new Error('You must override it');
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
isMultiAudioTracks() {
|
|
170
|
+
return this.getAudioTracks().length > 1;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
getAudioTracks() {
|
|
174
|
+
return [];
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
getAudioTrack() {
|
|
178
|
+
return 0;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
setAudioTrack(idx) {
|
|
182
|
+
// noop;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
getTextTracks() {
|
|
186
|
+
// noop;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
load(/* sources */) {
|
|
190
|
+
throw new Error('You must override it');
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
isMultiQuality(): boolean {
|
|
194
|
+
// eslint-disable-next-line no-magic-numbers
|
|
195
|
+
return this.getLevels().length > 1;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
getBufferedPercent(): number {
|
|
199
|
+
return 0;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
getElement(): HTMLVideoElement | HTMLAudioElement {
|
|
203
|
+
throw new Error('You must override it');
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
_getFrameDuration(): number {
|
|
207
|
+
return MS_IN_SEC / this.options.frameRate;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import BasePlayer from './base';
|
|
2
|
+
|
|
3
|
+
import MediaElement from '../flash/MediaElement';
|
|
4
|
+
|
|
5
|
+
import { get, createElement, toArray, find, first, isArray } from '../utils';
|
|
6
|
+
|
|
7
|
+
import type { Player$Options } from '../types/Options';
|
|
8
|
+
|
|
9
|
+
const AUTO_LEVEL = { name: 'Auto', index: -1 };
|
|
10
|
+
|
|
11
|
+
export default class FlashPlayer extends BasePlayer {
|
|
12
|
+
$el: HTMLAudioElement | HTMLVideoElement
|
|
13
|
+
_levels = [];
|
|
14
|
+
_currentLevel = null;
|
|
15
|
+
|
|
16
|
+
mediaElement: ?MediaElement = null
|
|
17
|
+
|
|
18
|
+
constructor(options: Player$Options, state) {
|
|
19
|
+
super(options, state);
|
|
20
|
+
this.logger.debug('flash:controller:creating');
|
|
21
|
+
|
|
22
|
+
this.$el = createElement(options.isAudio ? 'audio' : 'video');
|
|
23
|
+
|
|
24
|
+
this.onFullScreenChanged = this.onFullScreenChanged.bind(this);
|
|
25
|
+
|
|
26
|
+
this.logger.debug('flash:controller:created');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
load({src}) {
|
|
30
|
+
|
|
31
|
+
if ( isArray(src) ) {
|
|
32
|
+
this._levels = src;
|
|
33
|
+
this._currentLevel = find(this._levels, lvl => lvl.default) || first(this._levels);
|
|
34
|
+
src = this._currentLevel.src;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
this.logger.debug('flash:controller:loading', src);
|
|
38
|
+
|
|
39
|
+
const mediaElement = new MediaElement(this.$el, this.options);
|
|
40
|
+
this.mediaElement = mediaElement;
|
|
41
|
+
mediaElement.setSrc(src);
|
|
42
|
+
mediaElement.setSize('100%', '100%');
|
|
43
|
+
|
|
44
|
+
mediaElement.play();
|
|
45
|
+
|
|
46
|
+
this.bus.once('loadedmetadata', () => {
|
|
47
|
+
mediaElement.pause();
|
|
48
|
+
|
|
49
|
+
if (this.options.qualityLevel) {
|
|
50
|
+
const h = parseInt(this.options.qualityLevel, 10);
|
|
51
|
+
const level = find(this.getLevels(), l => l.height === h);
|
|
52
|
+
if (level) {
|
|
53
|
+
this.setLevel(level);
|
|
54
|
+
this.bus.emit('qualitychange', `${h}p`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
if (this.options.isAudio) {
|
|
60
|
+
mediaElement.pause();
|
|
61
|
+
this.bus.once('canplaythrough', () => {
|
|
62
|
+
mediaElement.pause();
|
|
63
|
+
this.bus.emit('loadedmetadata');
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
this.bus.on('fullscreenchanged', this.onFullScreenChanged);
|
|
68
|
+
this.bus.on('cclayoutchange', this.onFullScreenChanged);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
isHLS() {
|
|
72
|
+
return get(this.mediaElement, 'rendererName') === 'flash_hls';
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
getLevels() {
|
|
76
|
+
if (this.isHLS()) {
|
|
77
|
+
const levels = toArray(this.mediaElement.levels);
|
|
78
|
+
return [ AUTO_LEVEL ].concat(levels);
|
|
79
|
+
}
|
|
80
|
+
return this._levels;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
setLevel(level) {
|
|
84
|
+
if (this.isHLS()) {
|
|
85
|
+
this.mediaElement.level = level.index;
|
|
86
|
+
} else if ( this._currentLevel !== level ) {
|
|
87
|
+
const currentTime = this.mediaElement.currentTime;
|
|
88
|
+
const paused = this.mediaElement.paused;
|
|
89
|
+
this._currentLevel = level;
|
|
90
|
+
this.mediaElement.setSrc(level.src);
|
|
91
|
+
this.mediaElement.setSize('100%', '100%');
|
|
92
|
+
this.mediaElement.play();
|
|
93
|
+
this.bus.once('loadedmetadata', () => {
|
|
94
|
+
this.mediaElement.currentTime = currentTime;
|
|
95
|
+
this.mediaElement.pause();
|
|
96
|
+
this.mediaElement.play();
|
|
97
|
+
if (paused) {
|
|
98
|
+
this.mediaElement.pause();
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
getLevel() {
|
|
105
|
+
if (this.isHLS()) {
|
|
106
|
+
return this.mediaElement.levels[this.getElement().currentLevel] || AUTO_LEVEL;
|
|
107
|
+
}
|
|
108
|
+
return this._currentLevel;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
getElement() {
|
|
112
|
+
return this.mediaElement;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
setCurrentTime(time: number, silent: ?boolean = true) {
|
|
116
|
+
const paused = this.isPaused();
|
|
117
|
+
this.pause(silent);
|
|
118
|
+
super.setCurrentTime(time, silent);
|
|
119
|
+
if ( !paused ) {
|
|
120
|
+
this.play(silent);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
isMultiQuality() {
|
|
125
|
+
const levels = this.isHLS() ? this.mediaElement.levels : this._levels;
|
|
126
|
+
// eslint-disable-next-line no-magic-numbers
|
|
127
|
+
return levels.length > 1;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
onFullScreenChanged(isFullScreen: ?boolean = false) {
|
|
131
|
+
if (isFullScreen) {
|
|
132
|
+
const { mediaElement } = this;
|
|
133
|
+
if (mediaElement) {
|
|
134
|
+
mediaElement.setSize('100%', '100%');
|
|
135
|
+
}
|
|
136
|
+
} else {
|
|
137
|
+
setTimeout(() => this._resizeME());
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
_resizeME() {
|
|
142
|
+
const parent = this.$el.parentNode;
|
|
143
|
+
const me = this.mediaElement;
|
|
144
|
+
if (parent && me && parent instanceof HTMLElement) {
|
|
145
|
+
const width = parent.offsetWidth;
|
|
146
|
+
const height = parent.offsetHeight;
|
|
147
|
+
me.setSize(`${width}px`, `${height}px`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
getBufferedPercent() {
|
|
152
|
+
const $el = this.mediaElement;
|
|
153
|
+
return $el.buffered.end($el.buffered.length - 1) / $el.duration;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
destroy() {
|
|
157
|
+
this.pause();
|
|
158
|
+
const { mediaElement } = this;
|
|
159
|
+
if ( mediaElement ) {
|
|
160
|
+
mediaElement.renderer.hide();
|
|
161
|
+
}
|
|
162
|
+
super.destroy();
|
|
163
|
+
this.bus.off('fullscreenchanged', this.onFullScreenChanged);
|
|
164
|
+
this.bus.off('cclayoutchange', this.onFullScreenChanged);
|
|
165
|
+
|
|
166
|
+
if (mediaElement) {
|
|
167
|
+
mediaElement.removeChild(this.$el);
|
|
168
|
+
mediaElement.parentNode.removeChild(mediaElement);
|
|
169
|
+
}
|
|
170
|
+
this.mediaElement = null;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import HTMLPlayer from './html';
|
|
2
|
+
|
|
3
|
+
// import { C2PA, ValidationResult, C2PAValidationError } from '@ravnur-inc/c2pa';
|
|
4
|
+
import {
|
|
5
|
+
findIndex,
|
|
6
|
+
existy,
|
|
7
|
+
createElement,
|
|
8
|
+
first,
|
|
9
|
+
isArray,
|
|
10
|
+
isObject,
|
|
11
|
+
head,
|
|
12
|
+
extend,
|
|
13
|
+
find
|
|
14
|
+
// isEqualBuffer
|
|
15
|
+
} from '../utils';
|
|
16
|
+
|
|
17
|
+
const AUTO_LEVEL = { name: 'Auto' };
|
|
18
|
+
const HLS_OPTIONS = {
|
|
19
|
+
maxFragLookUpTolerance: 0.5,
|
|
20
|
+
maxMaxBufferLength: 600,
|
|
21
|
+
highBufferWatchdogPeriod: 3,
|
|
22
|
+
playlistLoadPolicy: {
|
|
23
|
+
default: {
|
|
24
|
+
maxTimeToFirstByteMs: 10000,
|
|
25
|
+
maxLoadTimeMs: 120000,
|
|
26
|
+
timeoutRetry: {
|
|
27
|
+
maxNumRetry: 10,
|
|
28
|
+
retryDelayMs: 0,
|
|
29
|
+
maxRetryDelayMs: 0
|
|
30
|
+
},
|
|
31
|
+
errorRetry: {
|
|
32
|
+
maxNumRetry: 10,
|
|
33
|
+
retryDelayMs: 3000,
|
|
34
|
+
maxRetryDelayMs: 8000
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export default class HLSPlayer extends HTMLPlayer {
|
|
41
|
+
constructor(options, state) {
|
|
42
|
+
super(options, state);
|
|
43
|
+
this.logger.debug('hls:player:created');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
load({ src }) {
|
|
47
|
+
src = isArray(src) ? head(src) : src;
|
|
48
|
+
src = isObject(src) ? src.src : src;
|
|
49
|
+
this.logger.debug('hls:player:loading', src);
|
|
50
|
+
|
|
51
|
+
if (existy(window.Hls)) {
|
|
52
|
+
this._attachMedia(src);
|
|
53
|
+
} else {
|
|
54
|
+
this._loadLibraryAndAttachMedia(src);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
_loadLibraryAndAttachMedia(src) {
|
|
59
|
+
// use requiresjs if we can
|
|
60
|
+
if (typeof window.define === 'function' && window.define.amd) {
|
|
61
|
+
window.require.config({
|
|
62
|
+
paths: {
|
|
63
|
+
hlsjs: this.options.hlsjsURL
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
window.require(['hlsjs'], hls => {
|
|
68
|
+
window.Hls = hls;
|
|
69
|
+
this._attachMedia(src);
|
|
70
|
+
});
|
|
71
|
+
} else {
|
|
72
|
+
const script = createElement('script', { src: this.options.hlsjsURL });
|
|
73
|
+
const firstScriptTag = first(document.getElementsByTagName('script'));
|
|
74
|
+
script.onload = script.onreadystatechange = () => this._attachMedia(src);
|
|
75
|
+
|
|
76
|
+
if (!firstScriptTag.parentNode) return;
|
|
77
|
+
|
|
78
|
+
firstScriptTag.parentNode.insertBefore(script, firstScriptTag);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
_attachMedia(src) {
|
|
83
|
+
const Hls = window.Hls;
|
|
84
|
+
if (Hls.isSupported()) {
|
|
85
|
+
this.hls = new Hls(extend(HLS_OPTIONS, this.options.hls));
|
|
86
|
+
|
|
87
|
+
// if (this.options.showC2PA) {
|
|
88
|
+
// this.c2pa = new C2PA((status, data) => {
|
|
89
|
+
// switch (status) {
|
|
90
|
+
// case ValidationResult.Complete:
|
|
91
|
+
// this.bus.emit('c2painit', { status, data });
|
|
92
|
+
// break;
|
|
93
|
+
// case ValidationResult.NoData:
|
|
94
|
+
// this.bus.emit('c2painit', { status, data });
|
|
95
|
+
// break;
|
|
96
|
+
// case ValidationResult.Failed:
|
|
97
|
+
// this.bus.emit('c2painit', { status, data });
|
|
98
|
+
// if (!(data instanceof C2PAValidationError)) {
|
|
99
|
+
// this.bus.emit('c2paexception');
|
|
100
|
+
// }
|
|
101
|
+
// break;
|
|
102
|
+
// default:
|
|
103
|
+
// console.debug(`[HLS] Unrecognized status ${status}`);
|
|
104
|
+
// }
|
|
105
|
+
// });
|
|
106
|
+
|
|
107
|
+
// // The video init segment is parsing
|
|
108
|
+
// this.hls.on(Hls.Events.FRAG_PARSING_INIT_SEGMENT, (name, data) => {
|
|
109
|
+
// console.debug(`[HLS] Executed ${name} handler, data: ${data}`);
|
|
110
|
+
|
|
111
|
+
// this.c2pa.initSegment(data);
|
|
112
|
+
// });
|
|
113
|
+
|
|
114
|
+
// // The video segment is appending to buffer
|
|
115
|
+
// this.hls.on(Hls.Events.BUFFER_APPENDING, (name, data) => {
|
|
116
|
+
// console.debug(`[HLS] Executed ${name} handler, data: ${data}`);
|
|
117
|
+
|
|
118
|
+
// // Check whether buffered segment is init segment
|
|
119
|
+
// if (isEqualBuffer(data.data, data.frag.initSegment.data)) {
|
|
120
|
+
// return;
|
|
121
|
+
// }
|
|
122
|
+
|
|
123
|
+
// // TODO: c2pa.validateSegment should define own data model, not just accept hls event data
|
|
124
|
+
// data.data1 = data.data;
|
|
125
|
+
// this.c2pa.validateSegment(data, validationResult => {
|
|
126
|
+
// this.bus.emit('c2pafragment', validationResult);
|
|
127
|
+
// });
|
|
128
|
+
// });
|
|
129
|
+
// }
|
|
130
|
+
|
|
131
|
+
this.hls.loadSource(src);
|
|
132
|
+
this.hls.attachMedia(this.$el);
|
|
133
|
+
|
|
134
|
+
this.hls.on(Hls.Events.ERROR, (a, data) => {
|
|
135
|
+
this.bus.emit('error', data);
|
|
136
|
+
this.logger.error(data);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
this.hls.on(Hls.Events.AUDIO_TRACK_SWITCHED, () => {
|
|
140
|
+
this.bus.emit('audiotrackswitched');
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
this.hls.on(Hls.Events.MANIFEST_PARSED, (a, data) => {
|
|
144
|
+
if (!this.options.showSubtitles) {
|
|
145
|
+
this.hls.subtitleDisplay = false;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (this.options.qualityLevel) {
|
|
149
|
+
const h = parseInt(this.options.qualityLevel, 10);
|
|
150
|
+
if (h) {
|
|
151
|
+
const level = find(data.levels, l => l.height === h);
|
|
152
|
+
if (level) {
|
|
153
|
+
this.setLevel(level);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (this.options.maxQualityLevel) {
|
|
159
|
+
this.limitLevel(this.options.maxQualityLevel);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (this.options.startLevel) {
|
|
163
|
+
const h = parseInt(this.options.startLevel, 10);
|
|
164
|
+
if (h) {
|
|
165
|
+
const idx = findIndex(data.levels, l => l.height === h);
|
|
166
|
+
this.hls.startLevel = idx;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
this.hls.on(Hls.Events.BUFFER_CREATED, () => {
|
|
172
|
+
if (this.options.isLive) {
|
|
173
|
+
this.goToLive();
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
// Encryption. Token should be passed as an option or as a query parameter
|
|
178
|
+
if (this.options.aesToken) {
|
|
179
|
+
let descriptionUrl;
|
|
180
|
+
|
|
181
|
+
this.hls.config.xhrSetup = (xhr, url) => {
|
|
182
|
+
xhr.addEventListener('load', () => {
|
|
183
|
+
if (typeof xhr.response === 'string' && xhr.response.indexOf('#EXTM3U') >= 0) {
|
|
184
|
+
const lines = xhr.response.split('\n');
|
|
185
|
+
const keyLine = lines.find(line => line.indexOf('#EXT-X-KEY') === 0);
|
|
186
|
+
const keyUrl = keyLine?.split('URI="')[1].split('"')[0];
|
|
187
|
+
const urlBase = 'https://' + url.split('/')[2];
|
|
188
|
+
const finalUrl = urlBase + keyUrl;
|
|
189
|
+
|
|
190
|
+
if (keyUrl) {
|
|
191
|
+
descriptionUrl = finalUrl;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
if (url === descriptionUrl) {
|
|
197
|
+
xhr.setRequestHeader('Authorization', 'Bearer ' + this.options.aesToken);
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
} else {
|
|
201
|
+
// append all query parameters to the subsequent requests
|
|
202
|
+
const query = src.split('?')[1];
|
|
203
|
+
|
|
204
|
+
if (query) {
|
|
205
|
+
this.hls.config.xhrSetup = (xhr, url) => {
|
|
206
|
+
xhr.open('GET', url + `?${query}`, true);
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
} else {
|
|
211
|
+
this.logger.error('HLS is not supported for this browser');
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
goToLive() {
|
|
216
|
+
if (!this.hls.media) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
this.logger.debug('hls:player:live');
|
|
221
|
+
this.hls.media.currentTime = this.hls.liveSyncPosition || this.hls.media.duration - 10;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
isLive() {
|
|
225
|
+
if (this.hls?.liveSyncPosition) {
|
|
226
|
+
return this.hls?.media.currentTime >= (this.hls?.liveSyncPosition - 10);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return this.hls?.media.currentTime >= (this.hls?.media.duration - 10); // Default to 10s from duration
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
getLevels() {
|
|
233
|
+
return [AUTO_LEVEL].concat(this.hls.levels);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
setLevel(level) {
|
|
237
|
+
const idx = findIndex(this.hls.levels, level);
|
|
238
|
+
this.hls.currentLevel = idx;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
limitLevel(level) {
|
|
242
|
+
const h = parseInt(level, 10);
|
|
243
|
+
if (h) {
|
|
244
|
+
const idx = findIndex(this.hls.levels, l => l.height === h);
|
|
245
|
+
this.hls.autoLevelCapping = idx;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
getLevel() {
|
|
250
|
+
return this.hls.levels[this.hls.manualLevel] || AUTO_LEVEL;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
isMultiQuality() {
|
|
254
|
+
// eslint-disable-next-line no-magic-numbers
|
|
255
|
+
return this.hls.levels.length > 1;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
getAudioTracks() {
|
|
259
|
+
return this.hls.audioTracks;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
getAudioTrack() {
|
|
263
|
+
return this.hls.audioTrack;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
getTextTracks() {
|
|
267
|
+
return this.$el.textTracks || [];
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
setAudioTrack(idx) {
|
|
271
|
+
this.hls.audioTrack = idx;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
destroy() {
|
|
275
|
+
this.hls.destroy();
|
|
276
|
+
super.destroy();
|
|
277
|
+
}
|
|
278
|
+
}
|