mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-24 06:31:20 -08:00
add mse
This commit is contained in:
1 parent
b74ff6052c
commit
495782f5c6
11 files changed
+504
-7
No files matched your search
+20
-2
@@ -1,19 +1,37 @@
|
||||
import { clamp } from './utils';
|
||||
import mediaElement from './utils/mediaElement';
|
||||
|
||||
export default class Player {
|
||||
constructor(art) {
|
||||
this.art = art;
|
||||
this.eventFn = this.eventFn.bind(this);
|
||||
this.init();
|
||||
this.eventBind();
|
||||
}
|
||||
|
||||
init() {
|
||||
const { option } = this.art;
|
||||
const { $video } = this.art.refs;
|
||||
$video.controls = false;
|
||||
$video.controls = true;
|
||||
$video.poster = option.poster;
|
||||
$video.volume = clamp(option.volume, 0, 1);
|
||||
$video.autoplay = option.autoplay;
|
||||
$video.preload = option.preload;
|
||||
$video.src = option.url;
|
||||
}
|
||||
|
||||
eventBind() {
|
||||
const { $video } = this.art.refs;
|
||||
const { events } = mediaElement;
|
||||
for (let index = 0; index < events.length; index++) {
|
||||
const eventName = events[index];
|
||||
$video.addEventListener(eventName, this.eventFn);
|
||||
this.art.destroyEvents.push(() => {
|
||||
$video.removeEventListener(eventName, this.eventFn);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
eventFn(event) {
|
||||
this.art.emit(`video:${event.type}`, event);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user