xgplayer 2.32.2 → 2.32.3
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/browser/controls/danmu.js +3 -1
- package/browser/controls/errorRetry.js +1 -1
- package/browser/controls/nativeTextTrack.js +1 -1
- package/browser/core_player.js +1 -1
- package/browser/core_player.js.map +1 -1
- package/browser/index.js +7 -5
- package/browser/index.js.map +1 -1
- package/browser/simple_player.js +1 -1
- package/browser/simple_player.js.map +1 -1
- package/dist/controls/danmu.js +3 -1
- package/dist/controls/errorRetry.js +1 -1
- package/dist/controls/nativeTextTrack.js +1 -1
- package/dist/core_player.js +6 -7
- package/dist/core_player.js.map +1 -1
- package/dist/index.js +2881 -1887
- package/dist/index.js.map +1 -1
- package/dist/index.min.css +1 -0
- package/dist/index.min.js +2 -0
- package/dist/index.min.js.map +1 -0
- package/dist/simple_player.js +6 -7
- package/dist/simple_player.js.map +1 -1
- package/es/controls/danmu.js +3 -1
- package/es/controls/errorRetry.js +1 -1
- package/es/controls/nativeTextTrack.js +1 -1
- package/es/core_player.js +1 -1
- package/es/core_player.js.map +1 -1
- package/es/index.js +7 -5
- package/es/index.js.map +1 -1
- package/es/simple_player.js +1 -1
- package/es/simple_player.js.map +1 -1
- package/package.json +11 -2
- package/types/index.d.ts +0 -11
- package/postcss.config.js +0 -7
- package/src/bind/airplay.js +0 -10
- package/src/bind/cssFullscreen.js +0 -10
- package/src/bind/danmu.js +0 -10
- package/src/bind/definition.js +0 -10
- package/src/bind/download.js +0 -10
- package/src/bind/enter.js +0 -8
- package/src/bind/error.js +0 -8
- package/src/bind/errorRetry.js +0 -8
- package/src/bind/flex.js +0 -8
- package/src/bind/fullscreen.js +0 -10
- package/src/bind/i18n.js +0 -8
- package/src/bind/keyboard.js +0 -8
- package/src/bind/loading.js +0 -8
- package/src/bind/localPreview.js +0 -10
- package/src/bind/memoryPlay.js +0 -10
- package/src/bind/miniplayer.js +0 -10
- package/src/bind/mobile.js +0 -8
- package/src/bind/nativeTextTrack.js +0 -8
- package/src/bind/pc.js +0 -8
- package/src/bind/pip.js +0 -10
- package/src/bind/play.js +0 -10
- package/src/bind/playNext.js +0 -10
- package/src/bind/playbackRate.js +0 -8
- package/src/bind/poster.js +0 -8
- package/src/bind/progress.js +0 -8
- package/src/bind/reload.js +0 -10
- package/src/bind/replay.js +0 -10
- package/src/bind/rotate.js +0 -10
- package/src/bind/screenShot.js +0 -10
- package/src/bind/stallCheck.js +0 -8
- package/src/bind/start.js +0 -10
- package/src/bind/textTrack.js +0 -8
- package/src/bind/time.js +0 -8
- package/src/bind/volume.js +0 -10
- package/src/controls/airplay.js +0 -20
- package/src/controls/cssFullscreen.js +0 -49
- package/src/controls/danmu.js +0 -75
- package/src/controls/definition.js +0 -13
- package/src/controls/download.js +0 -28
- package/src/controls/errorRetry.js +0 -132
- package/src/controls/fullscreen.js +0 -145
- package/src/controls/keyboard.js +0 -214
- package/src/controls/localPreview.js +0 -32
- package/src/controls/memoryPlay.js +0 -14
- package/src/controls/miniplayer.js +0 -128
- package/src/controls/mobile.js +0 -100
- package/src/controls/pc.js +0 -123
- package/src/controls/pip.js +0 -52
- package/src/controls/play.js +0 -34
- package/src/controls/playNext.js +0 -29
- package/src/controls/reload.js +0 -24
- package/src/controls/replay.js +0 -30
- package/src/controls/rotate.js +0 -99
- package/src/controls/screenShot.js +0 -65
- package/src/controls/stallCheck.js +0 -38
- package/src/controls/start.js +0 -60
- package/src/controls/textTrack.js +0 -182
- package/src/controls/volume.js +0 -178
- package/src/controls.js +0 -36
- package/src/core_player.js +0 -13
- package/src/error.js +0 -74
- package/src/index.js +0 -57
- package/src/player.js +0 -553
- package/src/proxy.js +0 -495
- package/src/simple_player.js +0 -42
- package/src/skin/assets/airplay.svg +0 -1
- package/src/skin/assets/download.svg +0 -14
- package/src/skin/assets/exitCssFull.svg +0 -3
- package/src/skin/assets/exitFull.svg +0 -3
- package/src/skin/assets/loading.svg +0 -3
- package/src/skin/assets/panel.svg +0 -4
- package/src/skin/assets/pause.svg +0 -3
- package/src/skin/assets/play.svg +0 -3
- package/src/skin/assets/playNext.svg +0 -3
- package/src/skin/assets/reload.svg +0 -3
- package/src/skin/assets/replay.svg +0 -3
- package/src/skin/assets/requestCssFull.svg +0 -3
- package/src/skin/assets/requestFull.svg +0 -3
- package/src/skin/assets/rotate.svg +0 -11
- package/src/skin/assets/startPause.svg +0 -3
- package/src/skin/assets/startPlay.svg +0 -3
- package/src/skin/assets/volumeLarge.svg +0 -4
- package/src/skin/assets/volumeMuted.svg +0 -4
- package/src/skin/assets/volumeSmall.svg +0 -4
- package/src/skin/controls/airplay.js +0 -44
- package/src/skin/controls/cssFullscreen.js +0 -36
- package/src/skin/controls/danmu.js +0 -214
- package/src/skin/controls/definition.js +0 -251
- package/src/skin/controls/download.js +0 -29
- package/src/skin/controls/enter.js +0 -21
- package/src/skin/controls/error.js +0 -57
- package/src/skin/controls/flex.js +0 -13
- package/src/skin/controls/fullscreen.js +0 -43
- package/src/skin/controls/i18n.js +0 -168
- package/src/skin/controls/loading.js +0 -17
- package/src/skin/controls/localPreview.js +0 -18
- package/src/skin/controls/memoryPlay.js +0 -39
- package/src/skin/controls/miniplayer.js +0 -26
- package/src/skin/controls/nativeTextTrack.js +0 -153
- package/src/skin/controls/pip.js +0 -26
- package/src/skin/controls/play.js +0 -43
- package/src/skin/controls/playNext.js +0 -41
- package/src/skin/controls/playbackRate.js +0 -141
- package/src/skin/controls/poster.js +0 -18
- package/src/skin/controls/progress.js +0 -407
- package/src/skin/controls/reload.js +0 -29
- package/src/skin/controls/replay.js +0 -56
- package/src/skin/controls/rotate.js +0 -29
- package/src/skin/controls/screenShot.js +0 -27
- package/src/skin/controls/start.js +0 -62
- package/src/skin/controls/textTrack.js +0 -113
- package/src/skin/controls/time.js +0 -40
- package/src/skin/controls/volume.js +0 -63
- package/src/skin/index.js +0 -63
- package/src/skin/style/common/animation.scss +0 -16
- package/src/skin/style/common/svg-url.scss +0 -70
- package/src/skin/style/controls/airplay.scss +0 -35
- package/src/skin/style/controls/controls.scss +0 -40
- package/src/skin/style/controls/cssfullscreen.scss +0 -103
- package/src/skin/style/controls/danmu.scss +0 -333
- package/src/skin/style/controls/definition.scss +0 -76
- package/src/skin/style/controls/download.scss +0 -45
- package/src/skin/style/controls/enter.scss +0 -55
- package/src/skin/style/controls/error.scss +0 -34
- package/src/skin/style/controls/fullscreen.scss +0 -60
- package/src/skin/style/controls/icon.scss +0 -12
- package/src/skin/style/controls/live.scss +0 -9
- package/src/skin/style/controls/loading.scss +0 -44
- package/src/skin/style/controls/memoryPlay.scss +0 -28
- package/src/skin/style/controls/miniplayer.scss +0 -104
- package/src/skin/style/controls/pip.scss +0 -42
- package/src/skin/style/controls/placeholder.scss +0 -7
- package/src/skin/style/controls/play.scss +0 -79
- package/src/skin/style/controls/playNext.scss +0 -44
- package/src/skin/style/controls/playbackRate.scss +0 -82
- package/src/skin/style/controls/poster.scss +0 -19
- package/src/skin/style/controls/progress.scss +0 -182
- package/src/skin/style/controls/reload.scss +0 -43
- package/src/skin/style/controls/replay.scss +0 -46
- package/src/skin/style/controls/rotate.scss +0 -41
- package/src/skin/style/controls/screenShot.scss +0 -42
- package/src/skin/style/controls/start.scss +0 -78
- package/src/skin/style/controls/textTrack.scss +0 -87
- package/src/skin/style/controls/time.scss +0 -24
- package/src/skin/style/controls/tips.scss +0 -24
- package/src/skin/style/controls/videoProxy.scss +0 -6
- package/src/skin/style/controls/volume.scss +0 -143
- package/src/skin/style/index.scss +0 -88
- package/src/utils/sniffer.js +0 -47
- package/src/utils/url.js +0 -10
- package/src/utils/util.js +0 -358
- package/src/utils/xgplayerTimeRange.js +0 -17
- package/src/version.js +0 -7
- package/version.json +0 -3
- package/webpack.config.js +0 -168
package/src/player.js
DELETED
|
@@ -1,553 +0,0 @@
|
|
|
1
|
-
import Proxy from './proxy'
|
|
2
|
-
import { util, deepCopy, findDom, createDom, addClass, typeOf, hasClass, removeClass, checkIsBrowser } from './utils/util'
|
|
3
|
-
import sniffer from './utils/sniffer'
|
|
4
|
-
import XgplayerTimeRange from './utils/xgplayerTimeRange'
|
|
5
|
-
import Errors from './error'
|
|
6
|
-
import allOff from 'event-emitter/all-off'
|
|
7
|
-
import s_i18n from './skin/controls/i18n.js'
|
|
8
|
-
import './skin/style/index.scss'
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
version
|
|
12
|
-
} from '../version.json'
|
|
13
|
-
class Player extends Proxy {
|
|
14
|
-
constructor (options) {
|
|
15
|
-
super(options)
|
|
16
|
-
this.config = deepCopy({
|
|
17
|
-
width: 600,
|
|
18
|
-
height: 337.5,
|
|
19
|
-
ignores: [],
|
|
20
|
-
whitelist: [],
|
|
21
|
-
lang: (document.documentElement.getAttribute('lang') || navigator.language || 'zh-cn').toLocaleLowerCase(),
|
|
22
|
-
inactive: 3000,
|
|
23
|
-
volume: 0.6,
|
|
24
|
-
controls: true,
|
|
25
|
-
controlsList: ['nodownload']
|
|
26
|
-
}, options)
|
|
27
|
-
this.version = version
|
|
28
|
-
this.userTimer = null
|
|
29
|
-
this.waitTimer = null
|
|
30
|
-
this.history = []
|
|
31
|
-
this.isProgressMoving = false
|
|
32
|
-
this.root = findDom(document, `#${this.config.id}`)
|
|
33
|
-
this.controls = createDom('xg-controls', '', {
|
|
34
|
-
unselectable: 'on',
|
|
35
|
-
onselectstart: 'return false'
|
|
36
|
-
}, 'xgplayer-controls')
|
|
37
|
-
if (this.config.isShowControl) {
|
|
38
|
-
this.controls.style.display = 'none'
|
|
39
|
-
}
|
|
40
|
-
if (!this.root) {
|
|
41
|
-
let el = this.config.el
|
|
42
|
-
if (el && el.nodeType === 1) {
|
|
43
|
-
this.root = el
|
|
44
|
-
} else {
|
|
45
|
-
this.emit('error', new Errors({
|
|
46
|
-
type: 'use',
|
|
47
|
-
errd: {
|
|
48
|
-
line: 45,
|
|
49
|
-
handle: 'Constructor',
|
|
50
|
-
msg: 'container id can\'t be empty'
|
|
51
|
-
},
|
|
52
|
-
vid: this.config.vid
|
|
53
|
-
}))
|
|
54
|
-
console.error('container id can\'t be empty')
|
|
55
|
-
return false
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
// this.rootBackup = copyDom(this.root)
|
|
59
|
-
addClass(this.root, `xgplayer xgplayer-${sniffer.device} xgplayer-nostart xgplayer-pause ${this.config.controls ? '' : 'xgplayer-no-controls'}`)
|
|
60
|
-
this.root.appendChild(this.controls)
|
|
61
|
-
if (this.config.fluid) {
|
|
62
|
-
this.root.style['max-width'] = '100%'
|
|
63
|
-
this.root.style['width'] = '100%'
|
|
64
|
-
this.root.style['height'] = '0'
|
|
65
|
-
this.root.style['padding-top'] = `${this.config.height * 100 / this.config.width}%`
|
|
66
|
-
|
|
67
|
-
this.video.style['position'] = 'absolute'
|
|
68
|
-
this.video.style['top'] = '0'
|
|
69
|
-
this.video.style['left'] = '0'
|
|
70
|
-
} else {
|
|
71
|
-
// this.root.style.width = `${this.config.width}px`
|
|
72
|
-
// this.root.style.height = `${this.config.height}px`
|
|
73
|
-
if (this.config.width) {
|
|
74
|
-
if (typeof this.config.width !== 'number') {
|
|
75
|
-
this.root.style.width = this.config.width
|
|
76
|
-
} else {
|
|
77
|
-
this.root.style.width = `${this.config.width}px`
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
if (this.config.height) {
|
|
81
|
-
if (typeof this.config.height !== 'number') {
|
|
82
|
-
this.root.style.height = this.config.height
|
|
83
|
-
} else {
|
|
84
|
-
this.root.style.height = `${this.config.height}px`
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
if (this.config.execBeforePluginsCall) {
|
|
89
|
-
this.config.execBeforePluginsCall.forEach(item => {
|
|
90
|
-
item.call(this, this)
|
|
91
|
-
})
|
|
92
|
-
}
|
|
93
|
-
if(!this.config.closeI18n) {
|
|
94
|
-
Player.install(s_i18n.name, s_i18n.method)
|
|
95
|
-
}
|
|
96
|
-
if (this.config.controlStyle && typeOf(this.config.controlStyle) === 'String') {
|
|
97
|
-
let self = this
|
|
98
|
-
fetch(self.config.controlStyle, {
|
|
99
|
-
method: 'GET',
|
|
100
|
-
headers: {
|
|
101
|
-
Accept: 'application/json'
|
|
102
|
-
}
|
|
103
|
-
}).then(function (res) {
|
|
104
|
-
if (res.ok) {
|
|
105
|
-
res.json().then(function (obj) {
|
|
106
|
-
for (var prop in obj) {
|
|
107
|
-
if (obj.hasOwnProperty(prop)) {
|
|
108
|
-
self.config[prop] = obj[prop]
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
self.pluginsCall()
|
|
112
|
-
})
|
|
113
|
-
}
|
|
114
|
-
}).catch(function (err) {
|
|
115
|
-
console.log('Fetch错误:' + err)
|
|
116
|
-
})
|
|
117
|
-
} else {
|
|
118
|
-
this.pluginsCall()
|
|
119
|
-
}
|
|
120
|
-
if(this.config.controlPlugins) {
|
|
121
|
-
Player.controlsRun(this.config.controlPlugins, this)
|
|
122
|
-
}
|
|
123
|
-
this.ev.forEach((item) => {
|
|
124
|
-
let evName = Object.keys(item)[0]
|
|
125
|
-
let evFunc = this[item[evName]]
|
|
126
|
-
if (evFunc) {
|
|
127
|
-
this.on(evName, evFunc)
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
['focus', 'blur'].forEach(item => {
|
|
132
|
-
this.on(item, this['on' + item.charAt(0).toUpperCase() + item.slice(1)])
|
|
133
|
-
})
|
|
134
|
-
let player = this
|
|
135
|
-
this.mousemoveFunc = function () {
|
|
136
|
-
player.emit('focus')
|
|
137
|
-
if (!player.config.closeFocusVideoFocus) {
|
|
138
|
-
player.video.focus()
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
this.root.addEventListener('mousemove', this.mousemoveFunc)
|
|
142
|
-
this.playFunc = function () {
|
|
143
|
-
player.emit('focus')
|
|
144
|
-
if (!player.config.closePlayVideoFocus) {
|
|
145
|
-
player.video.focus()
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
player.once('play', this.playFunc)
|
|
149
|
-
|
|
150
|
-
this.getVideoSize = function () {
|
|
151
|
-
if (this.video.videoWidth && this.video.videoHeight) {
|
|
152
|
-
let containerSize = player.root.getBoundingClientRect()
|
|
153
|
-
if (player.config.fitVideoSize === 'auto') {
|
|
154
|
-
if (containerSize.width / containerSize.height > this.video.videoWidth / this.video.videoHeight) {
|
|
155
|
-
player.root.style.height = `${this.video.videoHeight / this.video.videoWidth * containerSize.width}px`
|
|
156
|
-
} else {
|
|
157
|
-
player.root.style.width = `${this.video.videoWidth / this.video.videoHeight * containerSize.height}px`
|
|
158
|
-
}
|
|
159
|
-
} else if (player.config.fitVideoSize === 'fixWidth') {
|
|
160
|
-
player.root.style.height = `${this.video.videoHeight / this.video.videoWidth * containerSize.width}px`
|
|
161
|
-
} else if (player.config.fitVideoSize === 'fixHeight') {
|
|
162
|
-
player.root.style.width = `${this.video.videoWidth / this.video.videoHeight * containerSize.height}px`
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
player.once('loadeddata', this.getVideoSize)
|
|
167
|
-
|
|
168
|
-
setTimeout(() => {
|
|
169
|
-
this.emit('ready')
|
|
170
|
-
this.isReady = true
|
|
171
|
-
}, 0)
|
|
172
|
-
|
|
173
|
-
if (this.config.videoInit) {
|
|
174
|
-
if (hasClass(this.root, 'xgplayer-nostart')) {
|
|
175
|
-
this.start()
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
if (player.config.rotate) {
|
|
179
|
-
player.on('requestFullscreen', this.updateRotateDeg)
|
|
180
|
-
player.on('exitFullscreen', this.updateRotateDeg)
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
function onDestroy () {
|
|
184
|
-
player.root.removeEventListener('mousemove', player.mousemoveFunc)
|
|
185
|
-
player.off('destroy', onDestroy)
|
|
186
|
-
}
|
|
187
|
-
player.once('destroy', onDestroy)
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
attachVideo () {
|
|
191
|
-
if(this.video && this.video.nodeType === 1) {
|
|
192
|
-
this.root.insertBefore(this.video, this.root.firstChild)
|
|
193
|
-
}
|
|
194
|
-
setTimeout(() => {
|
|
195
|
-
this.emit('complete')
|
|
196
|
-
if(this.danmu && typeof this.danmu.resize === 'function') {
|
|
197
|
-
this.danmu.resize()
|
|
198
|
-
}
|
|
199
|
-
}, 1)
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
start (url = this.config.url) {
|
|
203
|
-
if(!this.video) return
|
|
204
|
-
let player = this
|
|
205
|
-
if (!url || url === '') {
|
|
206
|
-
this.emit('urlNull')
|
|
207
|
-
return
|
|
208
|
-
}
|
|
209
|
-
this.canPlayFunc = function () {
|
|
210
|
-
player.off('canplay', player.canPlayFunc)
|
|
211
|
-
let playPromise = player.video.play()
|
|
212
|
-
if (playPromise !== undefined && playPromise) {
|
|
213
|
-
playPromise.then(function () {
|
|
214
|
-
player.emit('autoplay started')
|
|
215
|
-
}).catch(function () {
|
|
216
|
-
player.emit('autoplay was prevented')
|
|
217
|
-
addClass(player.root, 'xgplayer-is-autoplay')
|
|
218
|
-
})
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
if (typeOf(url) !== 'Array') {
|
|
222
|
-
if (typeOf(url) === 'String' && url.indexOf('blob:') > -1 && url === this.video.src) {
|
|
223
|
-
// 在Chromium环境下用mse url给video二次赋值会导致错误
|
|
224
|
-
} else {
|
|
225
|
-
this.video.src = url
|
|
226
|
-
}
|
|
227
|
-
} else {
|
|
228
|
-
url.forEach(item => {
|
|
229
|
-
this.video.appendChild(createDom('source', '', {
|
|
230
|
-
src: `${item.src}`,
|
|
231
|
-
type: `${item.type || ''}`
|
|
232
|
-
}))
|
|
233
|
-
})
|
|
234
|
-
}
|
|
235
|
-
if (this.config.autoplay) {
|
|
236
|
-
if (sniffer.os.isPhone) {
|
|
237
|
-
this.canPlayFunc()
|
|
238
|
-
} else {
|
|
239
|
-
this.on('canplay', this.canPlayFunc)
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
if(!this.config.disableStartLoad) {
|
|
243
|
-
this.video.load()
|
|
244
|
-
}
|
|
245
|
-
this.attachVideo()
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
reload () {
|
|
249
|
-
this.video.load()
|
|
250
|
-
this.reloadFunc = function () {
|
|
251
|
-
// eslint-disable-next-line handle-callback-err
|
|
252
|
-
let playPromise = this.play()
|
|
253
|
-
if (playPromise !== undefined && playPromise) {
|
|
254
|
-
playPromise.catch(err => {})
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
this.once('loadeddata', this.reloadFunc)
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
destroy (isDelDom = true) {
|
|
261
|
-
let player = this
|
|
262
|
-
clearInterval(this.bulletResizeTimer)
|
|
263
|
-
for (let k in this._interval) {
|
|
264
|
-
clearInterval(this._interval[k])
|
|
265
|
-
this._interval[k] = null
|
|
266
|
-
}
|
|
267
|
-
if (this.checkTimer) {
|
|
268
|
-
clearInterval(this.checkTimer)
|
|
269
|
-
}
|
|
270
|
-
if (this.waitTimer) {
|
|
271
|
-
clearTimeout(this.waitTimer)
|
|
272
|
-
}
|
|
273
|
-
this.ev.forEach((item) => {
|
|
274
|
-
let evName = Object.keys(item)[0]
|
|
275
|
-
let evFunc = this[item[evName]]
|
|
276
|
-
if (evFunc) {
|
|
277
|
-
this.off(evName, evFunc)
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
if (this.loadeddataFunc) {
|
|
281
|
-
this.off('loadeddata', this.loadeddataFunc)
|
|
282
|
-
}
|
|
283
|
-
if (this.reloadFunc) {
|
|
284
|
-
this.off('loadeddata', this.reloadFunc)
|
|
285
|
-
}
|
|
286
|
-
if (this.replayFunc) {
|
|
287
|
-
this.off('play', this.replayFunc)
|
|
288
|
-
}
|
|
289
|
-
if (this.playFunc) {
|
|
290
|
-
this.off('play', this.playFunc)
|
|
291
|
-
}
|
|
292
|
-
if (this.getVideoSize) {
|
|
293
|
-
this.off('loadeddata', this.getVideoSize)
|
|
294
|
-
};
|
|
295
|
-
['focus', 'blur'].forEach(item => {
|
|
296
|
-
this.off(item, this['on' + item.charAt(0).toUpperCase() + item.slice(1)])
|
|
297
|
-
})
|
|
298
|
-
if (!this.config.keyShortcut || this.config.keyShortcut === 'on') {
|
|
299
|
-
['video', 'controls'].forEach(item => {
|
|
300
|
-
if (this[item]) {
|
|
301
|
-
this[item].removeEventListener('keydown', function (e) { player.onKeydown(e, player) })
|
|
302
|
-
}
|
|
303
|
-
})
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
function destroyFunc () {
|
|
307
|
-
this.emit('destroy')
|
|
308
|
-
// this.root.id = this.root.id + '_del'
|
|
309
|
-
// parentNode.insertBefore(this.rootBackup, this.root)
|
|
310
|
-
|
|
311
|
-
// fix video destroy https://stackoverflow.com/questions/3258587/how-to-properly-unload-destroy-a-video-element
|
|
312
|
-
this.video.removeAttribute('src') // empty source
|
|
313
|
-
this.video.load()
|
|
314
|
-
if (isDelDom) {
|
|
315
|
-
// parentNode.removeChild(this.root)
|
|
316
|
-
this.root.innerHTML = ''
|
|
317
|
-
let classNameList = this.root.className.split(' ')
|
|
318
|
-
if (classNameList.length > 0) {
|
|
319
|
-
this.root.className = classNameList.filter(name => name.indexOf('xgplayer') < 0).join(' ')
|
|
320
|
-
} else {
|
|
321
|
-
this.root.className = ''
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
for (let k in this) {
|
|
326
|
-
// if (k !== 'config') {
|
|
327
|
-
delete this[k]
|
|
328
|
-
// }
|
|
329
|
-
}
|
|
330
|
-
allOff(this)
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
// destroy immediately
|
|
334
|
-
// Don't use the paused property detection, it doesn't use MediaElement.paused,
|
|
335
|
-
// so it's not accurate enough. Destroy after waiting for pause event, this
|
|
336
|
-
// changes the synchronous behavior of destroy api
|
|
337
|
-
destroyFunc.call(this)
|
|
338
|
-
|
|
339
|
-
super.destroy()
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
replay () {
|
|
343
|
-
let self = this
|
|
344
|
-
let _replay = this._replay
|
|
345
|
-
// ie9 bugfix
|
|
346
|
-
removeClass(this.root, 'xgplayer-ended')
|
|
347
|
-
if(sniffer.browser.indexOf('ie') > -1) {
|
|
348
|
-
this.emit('play')
|
|
349
|
-
this.emit('playing')
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
if (_replay && _replay instanceof Function) {
|
|
353
|
-
_replay()
|
|
354
|
-
} else {
|
|
355
|
-
this.currentTime = 0
|
|
356
|
-
// eslint-disable-next-line handle-callback-err
|
|
357
|
-
let playPromise = this.play()
|
|
358
|
-
if (playPromise !== undefined && playPromise) {
|
|
359
|
-
playPromise.catch(err => {})
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
userGestureTrigEvent (name, param) {
|
|
365
|
-
const defaultUserGestureEventHandler = (name, param) => {
|
|
366
|
-
this.emit(name, param)
|
|
367
|
-
}
|
|
368
|
-
if(this.config.userGestureEventMiddleware && typeof this.config.userGestureEventMiddleware[name] === 'function') {
|
|
369
|
-
this.config.userGestureEventMiddleware[name].call(this, this, name, param, defaultUserGestureEventHandler)
|
|
370
|
-
} else {
|
|
371
|
-
defaultUserGestureEventHandler.call(this, name, param);
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
pluginsCall () {
|
|
376
|
-
if(Player.plugins['s_i18n']) {
|
|
377
|
-
Player.plugins['s_i18n'].call(this, this)
|
|
378
|
-
}
|
|
379
|
-
let self = this
|
|
380
|
-
if (Player.plugins) {
|
|
381
|
-
let ignores = this.config.ignores
|
|
382
|
-
Object.keys(Player.plugins).forEach(name => {
|
|
383
|
-
let descriptor = Player.plugins[name]
|
|
384
|
-
if(!descriptor || typeof descriptor !== 'function'){
|
|
385
|
-
console.warn('plugin name', name , 'is invalid')
|
|
386
|
-
} else {
|
|
387
|
-
if (!ignores.some(item => name === item || name === 's_' + item) && name !== 's_i18n') {
|
|
388
|
-
if (['pc', 'tablet', 'mobile'].some(type => type === name)) {
|
|
389
|
-
if (name === sniffer.device) {
|
|
390
|
-
setTimeout(() => {
|
|
391
|
-
// if destroyed, skip
|
|
392
|
-
if (!self.video) return;
|
|
393
|
-
descriptor.call(self, self)
|
|
394
|
-
}, 0)
|
|
395
|
-
}
|
|
396
|
-
} else {
|
|
397
|
-
descriptor.call(this, this)
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
})
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
onFocus () {
|
|
406
|
-
let player = this
|
|
407
|
-
if(hasClass(this.root, 'xgplayer-inactive')) {
|
|
408
|
-
player.emit('controlShow')
|
|
409
|
-
}
|
|
410
|
-
removeClass(this.root, 'xgplayer-inactive')
|
|
411
|
-
if (player.userTimer) {
|
|
412
|
-
clearTimeout(player.userTimer)
|
|
413
|
-
}
|
|
414
|
-
player.userTimer = setTimeout(function () {
|
|
415
|
-
player.emit('blur')
|
|
416
|
-
}, player.config.inactive)
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
onBlur () {
|
|
420
|
-
// this.video.blur()
|
|
421
|
-
if ((this.config.enablePausedInactive || !this.paused) && !this.ended && !this.config.closeInactive) {
|
|
422
|
-
if(!hasClass(this.root, 'xgplayer-inactive')) {
|
|
423
|
-
this.emit('controlHide')
|
|
424
|
-
}
|
|
425
|
-
addClass(this.root, 'xgplayer-inactive')
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
onPlay () {
|
|
430
|
-
addClass(this.root, 'xgplayer-isloading')
|
|
431
|
-
addClass(this.root, 'xgplayer-playing')
|
|
432
|
-
removeClass(this.root, 'xgplayer-pause')
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
onPause () {
|
|
436
|
-
addClass(this.root, 'xgplayer-pause')
|
|
437
|
-
if (this.userTimer) {
|
|
438
|
-
clearTimeout(this.userTimer)
|
|
439
|
-
}
|
|
440
|
-
this.emit('focus')
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
onEnded () {
|
|
444
|
-
addClass(this.root, 'xgplayer-ended')
|
|
445
|
-
removeClass(this.root, 'xgplayer-playing')
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
onSeeking () {
|
|
449
|
-
this.isSeeking = true
|
|
450
|
-
// 兼容IE下无法触发waiting事件的问题 seeking的时候直接出发waiting
|
|
451
|
-
this.onWaiting()
|
|
452
|
-
// addClass(this.root, 'seeking');
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
// onTimeupdate () {
|
|
456
|
-
// // for ie,playing fired before waiting
|
|
457
|
-
// if (this.waitTimer) {
|
|
458
|
-
// clearTimeout(this.waitTimer)
|
|
459
|
-
// }
|
|
460
|
-
// removeClass(this.root, 'xgplayer-isloading')
|
|
461
|
-
|
|
462
|
-
// }
|
|
463
|
-
|
|
464
|
-
onSeeked () {
|
|
465
|
-
// for ie,playing fired before waiting
|
|
466
|
-
this.once('timeupdate', () => {
|
|
467
|
-
this.isSeeking = false
|
|
468
|
-
})
|
|
469
|
-
if (this.waitTimer) {
|
|
470
|
-
clearTimeout(this.waitTimer)
|
|
471
|
-
}
|
|
472
|
-
removeClass(this.root, 'xgplayer-isloading')
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
onWaiting () {
|
|
476
|
-
let self = this
|
|
477
|
-
if (self.waitTimer) {
|
|
478
|
-
clearTimeout(self.waitTimer)
|
|
479
|
-
}
|
|
480
|
-
if (self.checkTimer) {
|
|
481
|
-
clearInterval(self.checkTimer)
|
|
482
|
-
self.checkTimer = null
|
|
483
|
-
}
|
|
484
|
-
let time = self.currentTime
|
|
485
|
-
self.waitTimer = setTimeout(function () {
|
|
486
|
-
addClass(self.root, 'xgplayer-isloading')
|
|
487
|
-
self.checkTimer = setInterval(function () {
|
|
488
|
-
if (self.currentTime !== time) {
|
|
489
|
-
removeClass(self.root, 'xgplayer-isloading')
|
|
490
|
-
clearInterval(self.checkTimer)
|
|
491
|
-
self.checkTimer = null
|
|
492
|
-
}
|
|
493
|
-
}, 1000)
|
|
494
|
-
}, 500)
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
onPlaying () {
|
|
498
|
-
// 兼容safari下无法自动播放会触发该事件的场景
|
|
499
|
-
if (this.paused) {
|
|
500
|
-
return
|
|
501
|
-
}
|
|
502
|
-
this.isSeeking = false
|
|
503
|
-
if (this.waitTimer) {
|
|
504
|
-
clearTimeout(this.waitTimer)
|
|
505
|
-
}
|
|
506
|
-
removeClass(this.root, 'xgplayer-isloading xgplayer-nostart xgplayer-pause xgplayer-ended xgplayer-is-error xgplayer-replay')
|
|
507
|
-
addClass(this.root, 'xgplayer-playing')
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
static install (name, descriptor) {
|
|
511
|
-
if (!checkIsBrowser()) {
|
|
512
|
-
return
|
|
513
|
-
}
|
|
514
|
-
if (!Player.plugins) {
|
|
515
|
-
Player.plugins = {}
|
|
516
|
-
}
|
|
517
|
-
if (!Player.plugins[name]) {
|
|
518
|
-
Player.plugins[name] = descriptor
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
static installAll (list) {
|
|
523
|
-
for(let k = 0; k < list.length; k++){
|
|
524
|
-
Player.install(list[k].name, list[k].method)
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
static use (name, descriptor) {
|
|
529
|
-
if (!Player.plugins) {
|
|
530
|
-
Player.plugins = {}
|
|
531
|
-
}
|
|
532
|
-
Player.plugins[name] = descriptor
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
static useAll (list) {
|
|
536
|
-
for (let k in list) {
|
|
537
|
-
Player.use(list[k].name, list[k].method)
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
static controlsRun (controlLst, context) {
|
|
542
|
-
controlLst.forEach(function(control) {
|
|
543
|
-
control.method.call(context)
|
|
544
|
-
})
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
Player.util = util
|
|
549
|
-
Player.sniffer = sniffer
|
|
550
|
-
Player.Errors = Errors
|
|
551
|
-
Player.XgplayerTimeRange = XgplayerTimeRange
|
|
552
|
-
|
|
553
|
-
export default Player
|