提交 df94390e 编写于 作者: zhaofengliang920817's avatar zhaofengliang920817

调整背景音频播放示例。

上级 1416b9d0
...@@ -2,7 +2,12 @@ ...@@ -2,7 +2,12 @@
<view> <view>
<page-head :title="title"></page-head> <page-head :title="title"></page-head>
<view class="uni-padding-wrap"> <view class="uni-padding-wrap">
<view class="uni-hello-text">注意:离开当前页面后背景音乐将保持播放,后台控制中心点击上一曲、下一曲切换到第102和104首音乐时会出现播放失败示例</view> <text>
注意:1.离开当前页面后背景音乐将保持播放;\n
2. 后台控制中心点击上一曲、下一曲切换到第102和104首音乐时会出现播放失败示例\n
3. 硬退出app、调用stop api、播放结束都会清理后台控制中心和锁屏信息显示
</text>
<view class="page-body-buttons"> <view class="page-body-buttons">
<template v-if="playing"> <template v-if="playing">
<view class="page-body-button" @tap="stop"> <view class="page-body-button" @tap="stop">
...@@ -32,8 +37,7 @@ ...@@ -32,8 +37,7 @@
playing: false, playing: false,
playTime: 0, playTime: 0,
formatedPlayTime: '00:00:00', formatedPlayTime: '00:00:00',
count: 100, count: 100
isCanplay: false,
} }
}, },
onLoad: function () { onLoad: function () {
...@@ -44,7 +48,6 @@ ...@@ -44,7 +48,6 @@
bgAudioMannager.coverImgUrl = 'https://web-assets.dcloud.net.cn/unidoc/zh/Alice.jpeg'; bgAudioMannager.coverImgUrl = 'https://web-assets.dcloud.net.cn/unidoc/zh/Alice.jpeg';
bgAudioMannager.onCanplay(() => { bgAudioMannager.onCanplay(() => {
console.log("音频进入可以播放状态事件"); console.log("音频进入可以播放状态事件");
this.isCanplay = true
}) })
bgAudioMannager.onPlay(() => { bgAudioMannager.onPlay(() => {
console.log("开始播放"); console.log("开始播放");
...@@ -67,7 +70,7 @@ ...@@ -67,7 +70,7 @@
bgAudioMannager.onNext(() => { bgAudioMannager.onNext(() => {
this.count++ this.count++
console.log("下一曲", this.count); console.log("下一曲", this.count);
this.bgAudioMannager?.stop() // this.bgAudioMannager?.stop()
bgAudioMannager.title = '致爱丽丝' + this.count; bgAudioMannager.title = '致爱丽丝' + this.count;
bgAudioMannager.singer = '歌手:暂无' + this.count; bgAudioMannager.singer = '歌手:暂无' + this.count;
if (this.count == 102 || this.count == 104) { if (this.count == 102 || this.count == 104) {
...@@ -82,7 +85,7 @@ ...@@ -82,7 +85,7 @@
bgAudioMannager.onPrev(() => { bgAudioMannager.onPrev(() => {
this.count-- this.count--
console.log("上一曲", this.count); console.log("上一曲", this.count);
this.bgAudioMannager?.stop() // this.bgAudioMannager?.stop()
bgAudioMannager.title = '致爱丽丝' + this.count; bgAudioMannager.title = '致爱丽丝' + this.count;
bgAudioMannager.singer = '歌手:暂无' + this.count; bgAudioMannager.singer = '歌手:暂无' + this.count;
if (this.count == 102 || this.count == 104) { if (this.count == 102 || this.count == 104) {
...@@ -110,16 +113,13 @@ ...@@ -110,16 +113,13 @@
console.log('播放出错err', err); console.log('播放出错err', err);
}) })
this.bgAudioMannager = bgAudioMannager; this.bgAudioMannager = bgAudioMannager;
this.playing = !bgAudioMannager.paused this.playing = !bgAudioMannager.paused
this.isCanplay = this.bgAudioMannager.duration > 0
}, },
methods: { methods: {
play: function () { play: function () {
console.log('play') console.log('play')
this.bgAudioMannager!.src = this.dataUrl; this.bgAudioMannager!.src = this.dataUrl;
if (this.isCanplay) { this.bgAudioMannager!.play()
this.bgAudioMannager!.play()
}
}, },
pause: function () { pause: function () {
this.bgAudioMannager?.pause(); this.bgAudioMannager?.pause();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册