InnerAudioContext
格式 | iOS | Android |
---|---|---|
flac | 否 | 是 |
amr | 否 | 是 |
wma | 否 | 是 |
ogg | 否 | 是 |
ape | 否 | 是 |
mp4 | 否 | 是 |
m4a | 是 | 是 |
wav | 是 | 是 |
mp3 | 是 | 是 |
aac | 是 | 是 |
aiff | 是 | 否 |
caf | 是 | 否 |
示例
请使用百度APP扫码
- 在 js 文件中
- 在 js 文件中
Page({
onLoad() {
// 每次触发就会注册一次回调事件,所以只需把所有回调写在onLoad中即可
const innerAudioContext = swan.createInnerAudioContext();
innerAudioContext.src = 'https://vd3.bdstatic.com/mda-ic7mxzt5cvz6f4y5/mda-ic7mxzt5cvz6f4y5.mp3';
innerAudioContext.autoplay = false;
innerAudioContext.obeyMuteSwitch = false;
innerAudioContext.onPlay(res => {
swan.showToast({
title: 'play',
icon: 'none'
});
console.log('onPlay', res);
});
innerAudioContext.onPause(res => {
swan.showToast({
title: 'pause',
icon: 'none'
});
console.log('onPause', res);
innerAudioContext.onStop(res => {
swan.showToast({
title: 'stop',
icon: 'none'
console.log('onStop', res);
});
innerAudioContext.onEnded(res => {
swan.showToast({
title: 'end',
icon: 'none'
});
console.log('onEnded', res);
});
innerAudioContext.onTimeUpdate(res => {
console.log('onTimeUpdate', res);
});
innerAudioContext.onError(res => {
swan.showToast({
title: 'error',
icon: 'none'
});
console.log('onError', res);
});
innerAudioContext.onWaiting(res => {
swan.showToast({
title: 'waiting',
});
});
this.innerAudioContext = innerAudioContext;
},
play() {
this.innerAudioContext.play();
},
pause() {
this.innerAudioContext.pause();
},
stop() {
this.innerAudioContext.stop();
},
seek() {
this.innerAudioContext.seek(10);
},
destroy() {
this.innerAudioContext.destroy();
},
offTimeUpdate() {
this.innerAudioContext.offTimeUpdate(res => {
swan.showToast({
title: 'offTimeUpdate',
icon: 'none'
});
console.log('offTimeUpdate', res);
});
}