提交 bd2d17a6 编写于 作者: M mahaifeng

[backgroundaudio] 修改背景音乐示例

上级 88d0be0e
...@@ -23,13 +23,6 @@ ...@@ -23,13 +23,6 @@
</view> </view>
</template> </template>
<script> <script>
// #ifdef APP-ANDROID
import Build from 'android.os.Build'
import Application from 'android.app.Application'
// #endif
// import {
// *
// } from "@/uni_modules/uni-getBackgroundAudioManager"
export default { export default {
data() { data() {
return { return {
...@@ -39,7 +32,7 @@ ...@@ -39,7 +32,7 @@
playing: false, playing: false,
playTime: 0, playTime: 0,
formatedPlayTime: '00:00:00', formatedPlayTime: '00:00:00',
count:100, count: 100,
} }
}, },
onLoad: function () { onLoad: function () {
...@@ -65,8 +58,8 @@ ...@@ -65,8 +58,8 @@
bgAudioMannager.onNext(() => { bgAudioMannager.onNext(() => {
console.log("下一曲"); console.log("下一曲");
this.bgAudioMannager?.stop() this.bgAudioMannager?.stop()
bgAudioMannager.title = '致爱丽丝'+this.count++; bgAudioMannager.title = '致爱丽丝' + this.count++;
bgAudioMannager.singer = '暂无2'+this.count++; bgAudioMannager.singer = '暂无2' + this.count++;
bgAudioMannager.coverImgUrl = 'https://web-assets.dcloud.net.cn/unidoc/zh/Alice.jpeg'; bgAudioMannager.coverImgUrl = 'https://web-assets.dcloud.net.cn/unidoc/zh/Alice.jpeg';
this.bgAudioMannager!.src = this.dataUrl; this.bgAudioMannager!.src = this.dataUrl;
this.bgAudioMannager?.play() this.bgAudioMannager?.play()
...@@ -74,8 +67,8 @@ ...@@ -74,8 +67,8 @@
bgAudioMannager.onPrev(() => { bgAudioMannager.onPrev(() => {
console.log("上一曲"); console.log("上一曲");
this.bgAudioMannager?.stop() this.bgAudioMannager?.stop()
bgAudioMannager.title = '致爱丽丝'+this.count--; bgAudioMannager.title = '致爱丽丝' + this.count--;
bgAudioMannager.singer = '暂无'+this.count--; bgAudioMannager.singer = '暂无' + this.count--;
this.bgAudioMannager!.src = this.dataUrl; this.bgAudioMannager!.src = this.dataUrl;
this.bgAudioMannager?.play() this.bgAudioMannager?.play()
}) })
...@@ -92,35 +85,7 @@ ...@@ -92,35 +85,7 @@
play: function () { play: function () {
console.log('play') console.log('play')
this.bgAudioMannager!.src = this.dataUrl; this.bgAudioMannager!.src = this.dataUrl;
// #ifdef APP-ANDROID this.bgAudioMannager!.play()
if (UTSAndroid.checkSystemPermissionGranted(UTSAndroid.getUniActivity()!, ["android.permission.POST_NOTIFICATIONS"])) {
this.bgAudioMannager!.play()
} else {
// 检查当前 Android 版本和 targetSdkVersion
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
// Android 13 及以上版本
if ((UTSAndroid.getAppContext() as Application).applicationInfo.targetSdkVersion >= 33) {
UTSAndroid.requestSystemPermission(UTSAndroid.getUniActivity()!, ["android.permission.POST_NOTIFICATIONS"], (_ : boolean, p : string[]) => {
this.bgAudioMannager!.play()
}, (_ : boolean, p : string[]) => {
uni.showToast({
title: "权限被拒绝了",
position: "bottom"
})
console.log(p)
})
} else {
uni.showToast({
title: '请手动打开通知权限'
})
}
} else {
uni.showToast({
title: '请手动打开通知权限'
})
}
}
// #endif
}, },
pause: function () { pause: function () {
this.bgAudioMannager?.pause(); this.bgAudioMannager?.pause();
...@@ -178,4 +143,4 @@ ...@@ -178,4 +143,4 @@
flex-direction: row; flex-direction: row;
justify-content: center; justify-content: center;
} }
</style> </style>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册