@jxstjh/jhvideo
Version:
HTML5 jhvideo base on MPEG2-TS Stream Player
37 lines (31 loc) • 1.14 kB
text/typescript
import {audioOnSvg, audioOffSvg} from "../icons";
class audioCtrl {
private _videoBox:Element
private _muted:boolean = true
private _onMutedChange?: Function
constructor(videoBox:Element, muted:boolean = true, onMutedChange?: Function) {
this._videoBox = videoBox
this._muted = muted
this._onMutedChange = onMutedChange
}
// 状态设置
setState() {
return this.setMuted(!this._muted)
}
setMuted(muted:boolean) {
const className = '.jh-audio-change'
const callWrapper = this._videoBox.querySelector(className)
const video = this._videoBox.querySelector("video");
this._muted = muted
if (video) {
video.muted = this._muted;
}
this._onMutedChange && this._onMutedChange(this._muted)
if (callWrapper) {
callWrapper.innerHTML = this._muted ? audioOnSvg : audioOffSvg
callWrapper.setAttribute('aria-controls', this._muted ? '已关闭声音' : '已开启声音')
}
return this._muted
}
}
export default audioCtrl