UNPKG

@tarojs/components

Version:
59 lines (53 loc) 1.82 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const index = require('./index-5b029707.js'); const indexCss = "audio{outline:none;max-width:100%}"; const Audio = class { constructor(hostRef) { index.registerInstance(this, hostRef); this.onError = index.createEvent(this, "error", 7); this.onPlay = index.createEvent(this, "play", 7); this.onPause = index.createEvent(this, "pause", 7); this.onTimeUpdate = index.createEvent(this, "timeupdate", 7); this.onEnded = index.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 (index.h("audio", Object.assign({ src: src, controls: controls, autoplay: autoplay, loop: loop, muted: muted, ref: audio => { this.audio = audio; } }, nativeProps))); } }; Audio.style = indexCss; exports.taro_audio_core = Audio;