j***@163.com
j***@163.com
  • 发布:2024-03-14 11:08
  • 更新:2024-03-19 09:54
  • 阅读:512

android uni.getBackgroundAudioManager 熄屏后,有的手机会自动停止播放

分类:uni-app

在用uniapp开发的addroid应用中,应用的功能为播放音频,出现的问题如标题。主要手机集中在比较便宜的手机,1000左右的。而且插上电源就不停止,不插的话,播一会儿就自动停了。

2024-03-14 11:08 负责人:无 分享
已邀请:
套马杆的套子

套马杆的套子 - 没有解决不了的问题,只有解决不完的问题

手机设置 => 应用程序设置 => 选择你的应用 => 允许后台活动试试
可以设置保持前台服务别被杀死试试

if (uni.getSystemInfoSync().platform === 'android' && Number(uni.getSystemInfoSync().system.split(' ')[1].split('.')[0]) >= 8) {  
    const main = plus.android.runtimeMainActivity();  
    const Intent = plus.android.importClass('android.content.Intent');  
    const PendingIntent = plus.android.importClass('android.app.PendingIntent');  
    const Notification = plus.android.importClass('android.app.Notification');  
    const service = plus.android.runtimeMainActivity();  
    const nb = new Notification.Builder(main);  
    nb.setContentIntent(PendingIntent.getActivity(main, 0, new Intent(main, main.getClass()), PendingIntent.FLAG_UPDATE_CURRENT));  
    main.startForeground(110, nb.build());  
}
  • j***@163.com (作者)

    你好,这段代码应该放在哪里啊

    2024-03-18 16:28

  • 套马杆的套子

    回复 j***@163.com: uni.getBackgroundAudioManager下面

    2024-03-19 07:55

j***@163.com

j***@163.com (作者)

报错说没有这个方法呢

  • 套马杆的套子

    额..那试试这个保活插件呢


    https://ext.dcloud.net.cn/plugin?id=16644

    2024-03-19 13:49

要回复问题请先登录注册