@tarojs/components
Version:
55 lines (51 loc) • 1.74 kB
JavaScript
import { r as registerInstance, c as createEvent, h } from './index-5e431bb8.js';
const indexCss = "audio{outline:none;max-width:100%}";
const Audio = class {
constructor(hostRef) {
registerInstance(this, hostRef);
this.onError = createEvent(this, "error", 7);
this.onPlay = createEvent(this, "play", 7);
this.onPause = createEvent(this, "pause", 7);
this.onTimeUpdate = createEvent(this, "timeupdate", 7);
this.onEnded = createEvent(this, "ended", 7);
this.src = undefined;
this.controls = true;
this.autoplay = false;
this.loop = false;
this.muted = false;
this.nativeProps = {};
}
bindevent() {
this.audio.addEventListener('timeupdate', (e) => {
this.onTimeUpdate.emit({
duration: e.srcElement.duration,
currentTime: e.srcElement.duration
});
});
this.audio.addEventListener('ended', () => {
this.onEnded.emit();
});
this.audio.addEventListener('play', () => {
this.onPlay.emit();
});
this.audio.addEventListener('pause', (e) => {
this.onPause.emit(e);
});
// 1网络错误, 2解码错误, 3解码错误,4 不合适资源
this.audio.addEventListener('error', (e) => {
var _a;
this.onError.emit({
errMsg: (_a = e.srcElement.error) === null || _a === void 0 ? void 0 : _a.code
});
});
}
componentDidLoad() {
this.bindevent();
}
render() {
const { src, controls, autoplay, loop, muted, nativeProps } = this;
return (h("audio", Object.assign({ src: src, controls: controls, autoplay: autoplay, loop: loop, muted: muted, ref: audio => { this.audio = audio; } }, nativeProps)));
}
};
Audio.style = indexCss;
export { Audio as taro_audio_core };