Appearance
AudioPlayerService
集成
package.json
引入库
点击查看源码
js
"@extscreen/es-audio-player": "^x.x.x"
绑定服务
点击查看源码
vue
ESAudioPlayerServiceModule.bindService();
解绑服务
点击查看源码
vue
ESAudioPlayerServiceModule.unbindService();
停止服务
点击查看源码
vue
ESAudioPlayerServiceModule.stopService();
初始化AudioPlayer
点击查看源码
vue
ESAudioPlayerServiceModule.initAudioPlayer();
播放
点击查看源码
vue
let url = "http://qcloudimg-moss.cp47.ott.cibntv.net/channelzero/video/music/500years.mp3"
ESAudioPlayerServiceModule.play(url);
开始
点击查看源码
vue
ESAudioPlayerServiceModule.start();
暂停
点击查看源码
vue
ESAudioPlayerServiceModule.pause();
停止
点击查看源码
vue
ESAudioPlayerServiceModule.stop();
恢复
点击查看源码
vue
ESAudioPlayerServiceModule.resume();
释放资源
点击查看源码
vue
ESAudioPlayerServiceModule.release();
快进
点击查看源码
vue
ESAudioPlayerServiceModule.seekTo(2000);
设置倍速播放
点击查看源码
vue
ESAudioPlayerServiceModule.setPlayRate(2);
监听音频播放状态
点击查看源码
vue
export default {
mixins: [ESAudioPlayerMixin],
methods: {
onAudioPlayerInitSuccess(){
},
onAudioPlayerInitError(){
},
onAudioPlayerServiceBindSuccess(){
},
onAudioPlayerServiceBindError(){
},
//播放状态变化
onPlayerStatusChanged(event) {
switch (event.playerStatus) {
case ES_PLAYER_STATE_PREPARED: {
ESAudioPlayerModule.start();
break;
}
case ES_PLAYER_STATE_PAUSED: {
break;
}
case ES_PLAYER_STATE_STOP: {
break;
}
case ES_PLAYER_STATE_PLAYBACK_COMPLETED: {
break;
}
case ES_PLAYER_STATE_ERROR: {
break;
}
case ES_PLAYER_STATE_RESUMED: {
break;
}
case ES_PLAYER_STATE_BUFFER_START: {
break;
}
case ES_PLAYER_STATE_BUFFER_END: {
break;
}
case ES_PLAYER_STATE_SEEK_START: {
break;
}
case ES_PLAYER_STATE_SEEK_COMPLETED: {
break;
}
}
},
//播放错误
onPlayerError(errorCode, errorMessage) {
},
//播放信息
onPlayerInfo(info) {
},
//播放速率变化
onPlayRateChanged(playRate){
},
},
};
示例代码
点击查看源码
vue
<template>
<div class="es-sdk-root-css">
<title class="es-sdk-content-title-css" :text="this.$options.name"/>
<div class="es-sdk-content-divider-css"/>
<div class="es-sdk-content-row-css">
<text-button text="绑定服务" @onButtonClicked="bindService"/>
<text-button text="初始化" @onButtonClicked="initAudio"/>
<text-button text="播放" @onButtonClicked="playAudio"/>
<text-button text="开始" @onButtonClicked="startAudio"/>
<text-button text="暂停" @onButtonClicked="pauseAudio"/>
<text-button text="停止" @onButtonClicked="stopAudio"/>
<text-button text="快进" @onButtonClicked="seekAudio"/>
<text-button text="倍速" @onButtonClicked="speedAudio"/>
</div>
</div>
</template>
<script>
import {ESLaunchManager, ESPage} from '@extscreen/es-core';
import {
ESAudioPlayerMixin,
ESAudioPlayerServiceModule
} from '@extscreen/es-audio-player';
import {
ES_PLAYER_STATE_BUFFER_END,
ES_PLAYER_STATE_BUFFER_START,
ES_PLAYER_STATE_ERROR,
ES_PLAYER_STATE_PAUSED,
ES_PLAYER_STATE_PLAYBACK_COMPLETED,
ES_PLAYER_STATE_PREPARED,
ES_PLAYER_STATE_RESUMED,
ES_PLAYER_STATE_SEEK_COMPLETED,
ES_PLAYER_STATE_SEEK_START,
ES_PLAYER_STATE_STOP
} from '@extscreen/es-player';
import {ESLog} from "@extscreen/es-log";
const TAG = 'AudioPlayerServiceModule';
export default {
name: 'AudioPlayerServiceModule',
mixins: [ESPage, ESAudioPlayerMixin],
methods: {
bindService() {
ESAudioPlayerServiceModule.bindService();
},
initAudio() {
ESAudioPlayerServiceModule.initAudioPlayer();
},
playAudio() {
let url1 = 'http://qcloudimg-moss.cp47.ott.cibntv.net/channelzero/video/music/absolute_music_set_out.mp3';
ESAudioPlayerServiceModule.play(url1);
},
startAudio() {
ESAudioPlayerServiceModule.start();
},
pauseAudio() {
ESAudioPlayerServiceModule.pause();
},
stopAudio() {
ESAudioPlayerServiceModule.stop();
ESAudioPlayerServiceModule.release();
},
seekAudio() {
ESAudioPlayerServiceModule.seekTo(2000);
},
speedAudio() {
ESAudioPlayerServiceModule.setPlayRate(2);
},
onAudioPlayerServiceBindSuccess() {
},
onAudioPlayerServiceBindError() {
},
onAudioPlayerInitError() {
},
onAudioPlayerInitSuccess() {
},
onPlayerStatusChanged(event) {
switch (event.playerStatus) {
case ES_PLAYER_STATE_PREPARED: {
ESAudioPlayerServiceModule.start();
break;
}
case ES_PLAYER_STATE_PAUSED: {
break;
}
case ES_PLAYER_STATE_STOP: {
break;
}
case ES_PLAYER_STATE_PLAYBACK_COMPLETED: {
break;
}
case ES_PLAYER_STATE_ERROR: {
break;
}
case ES_PLAYER_STATE_RESUMED: {
break;
}
case ES_PLAYER_STATE_BUFFER_START: {
break;
}
case ES_PLAYER_STATE_BUFFER_END: {
break;
}
case ES_PLAYER_STATE_SEEK_START: {
break;
}
case ES_PLAYER_STATE_SEEK_COMPLETED: {
break;
}
}
},
onPlayerInfo(info) {
},
onPlayRateChanged(playRate) {
},
onPlayerError(errorCode, errorMessage) {
},
onBackPressed() {
this.stopAudio();
ESLaunchManager.finishESPage();
},
},
};
</script>
<style scoped>
</style>