@tarojs/components
Version:
241 lines (240 loc) • 5.71 kB
JavaScript
import { h } from '@stencil/core';
export class Audio {
constructor() {
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)));
}
static get is() { return "taro-audio-core"; }
static get originalStyleUrls() {
return {
"$": ["./style/index.scss"]
};
}
static get styleUrls() {
return {
"$": ["./style/index.css"]
};
}
static get properties() {
return {
"src": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"attribute": "src",
"reflect": false
},
"controls": {
"type": "boolean",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"attribute": "controls",
"reflect": false,
"defaultValue": "true"
},
"autoplay": {
"type": "boolean",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"attribute": "autoplay",
"reflect": false,
"defaultValue": "false"
},
"loop": {
"type": "boolean",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"attribute": "loop",
"reflect": false,
"defaultValue": "false"
},
"muted": {
"type": "boolean",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"attribute": "muted",
"reflect": false,
"defaultValue": "false"
},
"nativeProps": {
"type": "unknown",
"mutable": false,
"complexType": {
"original": "{}",
"resolved": "{}",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"defaultValue": "{}"
}
};
}
static get events() {
return [{
"method": "onError",
"name": "error",
"bubbles": true,
"cancelable": true,
"composed": true,
"docs": {
"tags": [],
"text": ""
},
"complexType": {
"original": "any",
"resolved": "any",
"references": {}
}
}, {
"method": "onPlay",
"name": "play",
"bubbles": true,
"cancelable": true,
"composed": true,
"docs": {
"tags": [],
"text": ""
},
"complexType": {
"original": "any",
"resolved": "any",
"references": {}
}
}, {
"method": "onPause",
"name": "pause",
"bubbles": true,
"cancelable": true,
"composed": true,
"docs": {
"tags": [],
"text": ""
},
"complexType": {
"original": "any",
"resolved": "any",
"references": {}
}
}, {
"method": "onTimeUpdate",
"name": "timeupdate",
"bubbles": true,
"cancelable": true,
"composed": true,
"docs": {
"tags": [],
"text": ""
},
"complexType": {
"original": "any",
"resolved": "any",
"references": {}
}
}, {
"method": "onEnded",
"name": "ended",
"bubbles": true,
"cancelable": true,
"composed": true,
"docs": {
"tags": [],
"text": ""
},
"complexType": {
"original": "any",
"resolved": "any",
"references": {}
}
}];
}
}