如何解决颤振音频服务 ?? android.app.RemoteServiceException: Context.startForegroundService() 然后没有调用 Service.startForeground()
在 Flutter 中,我使用 audio_service(Android/IOS) 插件在后台播放音频。
当我在后台显示的通知中单击 pause 、 play 或任何按钮时,该服务会引发以下错误。 这有什么问题吗?
pubspec.yaml 文件包括:
audio_session: ^0.0.10
just_audio: ^0.6.9
audio_service: ^0.16.2
rxdart: ^0.24.1
================================================ ==========================
我在我的 androidManifest.xml 中添加以下标签
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<service android:name="com.ryanheise.audioservice.AudioService">
<intent-filter>
<action android:name="android.media.browse.MediaBrowserService" />
</intent-filter>
</service>
<receiver android:name="com.ryanheise.audioservice.MediaButtonReceiver" >
<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter>
</receiver>
然后在我的班级中,我用这个指令调用我的播放器班
Container(
child: AudioServiceWidget(child:Player()),width: MediaQuery.of(context).size.width,)
我的播放器类包含此处列出的相同代码,但不同之处在于它在我的树小部件中,而不是在如下示例中的主要部件中: https://pub.dev/packages/audio_service/example
import 'dart:async';
import 'dart:io';
import 'dart:math';
import 'package:audio_service/audio_service.dart';
import 'package:audio_session/audio_session.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:just_audio/just_audio.dart';
import 'package:rxdart/rxdart.dart';
class Player extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: StreamBuilder<bool>(
stream: AudioService.runningStream,builder: (context,snapshot) {
...........................
.............................
} } }
现在,当我使用我的应用程序时,播放器可以工作,但是当我单击通知栏上方的按钮时,应用程序崩溃并出现以下错误。
亚行日志:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.flutter_app1,PID: 10992
android.app.RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground()
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1793)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6524)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:451)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:888)
ADB LOG 把 AndroidServiceWidget 直接放到我的班级之后。播放器运行正常,但单击播放器通知栏中的按钮后应用程序崩溃:
021-02-18 16:01:12.980 28652-28652/com.example.flutter_app1 D/MediaBrowserCompat: Connecting to a MediaBrowserService.
2021-02-18 16:01:13.024 28652-28652/com.example.flutter_app1 W/MediaButtonReceiver: More than one BroadcastReceiver that handles android.intent.action.MEDIA_BUTTON was found,returning null.
2021-02-18 16:01:13.024 28652-28652/com.example.flutter_app1 W/MediaSessionCompat: Couldn't find a unique registered media button receiver in the given context.
2021-02-18 16:01:20.249 28652-28659/com.example.flutter_app1 I/zygote: Do full code cache collection,code=125KB,data=111KB
2021-02-18 16:01:20.259 28652-28659/com.example.flutter_app1 I/zygote: After code cache collection,code=101KB,data=70KB
2021-02-18 16:01:20.313 28652-28652/com.example.flutter_app1 I/ExoPlayerImpl: Init 7e1bce [ExoPlayerLib/2.12.2] [TECNO-KA7-GO,TECNO KA7,TECNO MOBILE LIMITED,27]
2021-02-18 16:01:20.604 28652-28829/com.example.flutter_app1 I/System.out: isEmailSend:GET
2021-02-18 16:01:20.706 28652-28668/com.example.flutter_app1 I/zygote: Background concurrent copying GC freed 79822(6MB) AllocSpace objects,43(1144KB) LOS objects,79% free,2MB/11MB,paused 503us total 185.099ms
2021-02-18 16:01:20.799 28652-28829/com.example.flutter_app1 I/System.out: port:443
2021-02-18 16:01:20.876 28652-28652/com.example.flutter_app1 W/le.flutter_app1: type=1400 audit(0.0:8059): avc: denied { search } for name="clients" dev="debugfs" ino=7420 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:debugfs_ion:s0 tclass=dir permissive=0
2021-02-18 16:01:20.879 28652-28652/com.example.flutter_app1 D/skia: SkJpegCodec::onGetPixels +
2021-02-18 16:01:21.071 28652-28652/com.example.flutter_app1 D/skia: SkJpegCodec::onGetPixels -
2021-02-18 16:01:21.521 28652-28668/com.example.flutter_app1 I/zygote: NativeAlloc concurrent copying GC freed 4664(306KB) AllocSpace objects,1(20KB) LOS objects,paused 214us total 177.472ms
2021-02-18 16:01:21.787 28652-28829/com.example.flutter_app1 I/System.out: [OkHttp] sendRequest>>
2021-02-18 16:01:21.789 28652-28829/com.example.flutter_app1 I/System.out: [OkHttp] sendRequest<<
2021-02-18 16:01:22.290 28652-28828/com.example.flutter_app1 W/AudioCapabilities: Unsupported mime audio/x-adpcm-ms
2021-02-18 16:01:22.292 28652-28828/com.example.flutter_app1 W/AudioCapabilities: Unsupported mime audio/x-adpcm-dvi-ima
2021-02-18 16:01:22.295 28652-28828/com.example.flutter_app1 W/AudioCapabilities: Unsupported mime audio/alac
2021-02-18 16:01:22.303 28652-28828/com.example.flutter_app1 W/AudioCapabilities: Unsupported mime audio/ape
2021-02-18 16:01:22.382 28652-28828/com.example.flutter_app1 W/VideoCapabilities: Unsupported mime video/divx
2021-02-18 16:01:22.421 28652-28828/com.example.flutter_app1 W/VideoCapabilities: Unrecognized profile/level 1/32 for video/mp4v-es
2021-02-18 16:01:22.421 28652-28828/com.example.flutter_app1 W/VideoCapabilities: Unrecognized profile/level 32768/2 for video/mp4v-es
2021-02-18 16:01:22.421 28652-28828/com.example.flutter_app1 W/VideoCapabilities: Unrecognized profile/level 32768/64 for video/mp4v-es
2021-02-18 16:01:22.436 28652-28828/com.example.flutter_app1 W/VideoCapabilities: Unsupported mime video/flv1
2021-02-18 16:01:22.475 28652-28828/com.example.flutter_app1 W/VideoCapabilities: Unsupported mime video/x-ms-wmv
2021-02-18 16:01:22.482 28652-28828/com.example.flutter_app1 W/VideoCapabilities: Unsupported mime video/xvid
2021-02-18 16:01:22.520 28652-28828/com.example.flutter_app1 W/VideoCapabilities: Unrecognized profile/level 1/32 for video/mp4v-es
2021-02-18 16:01:22.527 28652-28828/com.example.flutter_app1 I/VideoCapabilities: Unsupported profile 4 for video/mp4v-es
2021-02-18 16:01:22.859 28652-28834/com.example.flutter_app1 I/OMXClient: Treble IOmx obtained
2021-02-18 16:01:22.899 28652-28834/com.example.flutter_app1 I/ACodec: codec does not support config priority (err -2147483648)
2021-02-18 16:01:23.011 28652-28828/com.example.flutter_app1 D/AudioTrack: Client defaulted notificationFrames to 3675 for frameCount 11025
2021-02-18 16:01:23.242 28652-28659/com.example.flutter_app1 I/zygote: Do partial code cache collection,code=122KB,data=99KB
2021-02-18 16:01:23.278 28652-28659/com.example.flutter_app1 I/zygote: After code cache collection,data=99KB
2021-02-18 16:01:23.278 28652-28659/com.example.flutter_app1 I/zygote: Increasing code cache capacity to 512KB
2021-02-18 16:01:29.662 28652-28828/com.example.flutter_app1 D/AudioTrack: correcting timestamp time for pause,currentTimeNanos: 69361597167560 < limitNs: 69367023999339 < mStartNs: 69367075999339
2021-02-18 16:01:29.681 28652-28828/com.example.flutter_app1 D/AudioTrack: correcting timestamp time for pause,currentTimeNanos: 69361597167560 < limitNs: 69367023999339 < mStartNs: 69367075999339
2021-02-18 16:01:29.691 28652-28828/com.example.flutter_app1 D/AudioTrack: correcting timestamp time for pause,currentTimeNanos: 69361597167560 < limitNs: 69367023999339 < mStartNs: 69367075999339
2021-02-18 16:01:29.701 28652-28828/com.example.flutter_app1 D/AudioTrack: correcting timestamp time for pause,currentTimeNanos: 69361597167560 < limitNs: 69367023999339 < mStartNs: 69367075999339
2021-02-18 16:01:29.711 28652-28828/com.example.flutter_app1 I/chatty: uid=10467(com.example.flutter_app1) ExoPlayer:Playb identical 1 line
2021-02-18 16:01:29.721 28652-28828/com.example.flutter_app1 D/AudioTrack: correcting timestamp time for pause,currentTimeNanos: 69361597167560 < limitNs: 69367023999339 < mStartNs: 69367075999339
2021-02-18 16:01:29.732 28652-28828/com.example.flutter_app1 D/AudioTrack: correcting timestamp time for pause,currentTimeNanos: 69361597167560 < limitNs: 69367023999339 < mStartNs: 69367075999339
2021-02-18 16:01:29.742 28652-28828/com.example.flutter_app1 D/AudioTrack: correcting timestamp time for pause,currentTimeNanos: 69361597167560 < limitNs: 69367023999339 < mStartNs: 69367075999339
2021-02-18 16:01:36.585 28652-28668/com.example.flutter_app1 I/zygote: Background concurrent copying GC freed 29851(1403KB) AllocSpace objects,7(324KB) LOS objects,70% free,3MB/12MB,paused 596us total 101.321ms
2021-02-18 16:01:55.133 28652-28652/com.example.flutter_app1 D/AndroidRuntime: Shutting down VM
2021-02-18 16:01:55.152 28652-28652/com.example.flutter_app1 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.flutter_app1,PID: 28652
android.app.RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground()
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1793)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6524)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:451)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:888)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。