我只想向我的应用添加audio_service
https://pub.dartlang.org/packages/audio_service#-readme-tab-。
用于播放音频。但是没有成功。
基本上,我是iOS开发人员,因此对android设置了解不多。
我必须在哪里创建MainApplication,如果我尝试更改AndroidManifest.xml
,它会因为android:name=".MainApplication"
而给出错误消息。如何更改 android:name 。 Flutter不允许。
请帮助我进行android安装。
已编辑:
odChannel#ryanheise.com/audioService( 8223): Failed to handle method call
E/MethodChannel#ryanheise.com/audioService( 8223): java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v4.media.session.MediaControllerCompat.addQueueItem(android.support.v4.media.MediaDescriptionCompat, int)' on a null object reference
E/MethodChannel#ryanheise.com/audioService( 8223): at com.ryanheise.audioservice.AudioServicePlugin$ClientHandler.onMethodCall(AudioServicePlugin.java:392)
E/MethodChannel#ryanheise.com/audioService( 8223): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:201)
E/MethodChannel#ryanheise.com/audioService( 8223): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:88)
E/MethodChannel#ryanheise.com/audioService( 8223): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:202)
E/MethodChannel#ryanheise.com/audioService( 8223): at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#ryanheise.com/audioService( 8223): at android.os.MessageQueue.next(MessageQueue.java:329)
E/MethodChannel#ryanheise.com/audioService( 8223): at android.os.Looper.loop(Looper.java:142)
E/MethodChannel#ryanheise.com/audioService( 8223): at android.app.ActivityThread.main(ActivityThread.java:6375)
E/MethodChannel#ryanheise.com/audioService( 8223): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#ryanheise.com/audioService( 8223): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
E/MethodChannel#ryanheise.com/audioService( 8223): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802)
E/flutter ( 8223): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: PlatformException(error, Attempt to invoke virtual method 'void android.support.v4.media.session.MediaControllerCompat.addQueueItem(android.support.v4.media.MediaDescriptionCompat, int)' on a null object reference, null)
E/flutter ( 8223): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:564:7)
E/flutter ( 8223): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:302:33)
E/flutter ( 8223): <asynchronous suspension>
E/flutter ( 8223): #2 AudioService.addQueueItemAt (package:audio_service/audio_service.dart:481:10)
E/flutter ( 8223): <asynchronous suspension>
E/flutter ( 8223): #3 _MyAppState.initializeAndroidPlayer (package:audio_player_service_example/main.dart:159:18)
E/flutter ( 8223): <asynchronous suspension>
E/flutter ( 8223): #4 _MyAppState.initState (package:audio_player_service_example/main.dart:124:5)
E/flutter ( 8223): #5 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3851:58)
E/flutter ( 8223): #6 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3716:5)
E/flutter ( 8223): #7 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2960:14)
E/flutter ( 8223): #8 Element.updateChild (package:flutter/src/widgets/framework.dart:2763:12)
E/flutter ( 8223): #9 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4881:14)
E/flutter ( 8223): #10 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2960:14)
E/flutter ( 8223): #11 Element.updateChild (package:flutter/src/widgets/framework.dart:2763:12)
E/flutter ( 8223): #12 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3752:16)
E/flutter ( 8223): #13 Element.rebuild (package:flutter/src/widgets/framework.dart:3564:5)
E/flutter ( 8223): #14 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3721:5)
E/flutter ( 8223): #15 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3716:5)
E/flutter ( 8223): #16 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2960:14)
E/flutter ( 8223): #17 Element.updateChild (package:flutter/src/widgets/framework.dart:2763:12)
E/flutter ( 8223): #18 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4881:14)
E/flutter ( 8223): #19 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2960:14)
E/flutter ( 8223): #20 Element.updateChild (package:flutter/src/widgets/framework.dart:2763:12)
E/flutter ( 8223): #21 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4881:14)
E/flutter ( 8223): #22 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2960:14)
E/flutter ( 8223): #23 Element.updateChild (package:flutter/src/widgets/framework.dart:2763:12)
E/flutter ( 8223): #24 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4881:14)
E/flutter ( 8223): #25 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2960:14)
E/flutter ( 8223): #26 Element.updateChild (package:flutter/src/widgets/framework.dart:2763:12)
E/flutter ( 8223): #27 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4881:14)
E/flutter ( 8223): #28 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2960:14)
E/flutter ( 8223): #29 Element.updateChild (package:flutter/src/widgets/framework.dart:2763:12)
E/flutter ( 8223): #30 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3752:16)
E/flutter ( 8223): #31 Element.rebuild (package:flutter/src/widgets/framework.dart:3564:5)
E/flutter ( 8223): #32 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3721:5)
E/flutter ( 8223): #33 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3869:11)
E/flutter ( 8223): #34 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3716:5)
E/flutter ( 8223): #35 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2960:14)
E/flutter ( 8223): #36 Element.updateChild (package:flutter/src/widgets/framework.dart:2763:12)
E/flutter ( 8223): #37 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3752:16)
E/flutter ( 8223): #38 Element.rebuild (package:flutter/src/widgets/framework.dart:3564:5)
E/flutter ( 8223): #39 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3721:5)
E/flutter ( 8223): #40 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3716:5)
E/flutter ( 8223): #41 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2960:14)
E/flutter ( 8223): #42 Element.updateChild (package:flutter/src/widgets/f
E/flutter ( 8223): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: MissingPluginException(No implementation found for method initPlayerQueue on channel audio_player_service)
E/flutter ( 8223): #0 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:300:7)
E/flutter ( 8223): <asynchronous suspension>
E/flutter ( 8223): #1 AudioPlayer.initPlayerQueue (package:audio_player_service/audio_player.dart:250:19)
E/flutter ( 8223): <asynchronous suspension>
E/flutter ( 8223): #2 _MyAppState.initPlayer (package:audio_player_service_example/main.dart:148:23)
E/flutter ( 8223): <asynchronous suspension>
E/flutter ( 8223): #3 _MyAppState.initState (package:audio_player_service_example/main.dart:126:5)
E/flutter ( 8223): #4 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3851:58)
E/flutter ( 8223): #5 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3716:5)
E/flutter ( 8223): #6 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2960:14)
E/flutter ( 8223): #7 Element.updateChild (package:flutter/src/widgets/framework.dart:2763:12)
E/flutter ( 8223): #8 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4881:14)
E/flutter ( 8223): #9 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2960:14)
E/flutter ( 8223): #10 Element.updateChild (package:flutter/src/widgets/framework.dart:2763:12)
E/flutter ( 8223): #11 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3752:16)
E/flutter ( 8223): #12 Element.rebuild (package:flutter/src/widgets/framework.dart:3564:5)
E/flutter ( 8223): #13 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3721:5)
E/flutter ( 8223): #14 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3716:5)
E/flutter ( 8223): #15 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2960:14)
E/flutter ( 8223): #16 Element.updateChild (package:flutter/src/widgets/framework.dart:2763:12)
E/flutter ( 8223): #17 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4881:14)
E/flutter ( 8223): #18 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2960:14)
E/flutter ( 8223): #19 Element.updateChild (package:flutter/src/widgets/framework.dart:2763:12)
E/flutter ( 8223): #20 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4881:14)
E/flutter ( 8223): #21 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2960:14)
E/flutter ( 8223): #22 Element.updateChild (package:flutter/src/widgets/framework.dart:2763:12)
E/flutter ( 8223): #23 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4881:14)
E/flutter ( 8223): #24 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2960:14)
E/flutter ( 8223): #25 Element.updateChild (package:flutter/src/widgets/framework.dart:2763:12)
E/flutter ( 8223): #26 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4881:14)
E/flutter ( 8223): #27 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2960:14)
E/flutter ( 8223): #28 Element.updateChild (package:flutter/src/widgets/framework.dart:2763:12)
E/flutter ( 8223): #29 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3752:16)
E/flutter ( 8223): #30 Element.rebuild (package:flutter/src/widgets/framework.dart:3564:5)
E/flutter ( 8223): #31 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3721:5)
E/flutter ( 8223): #32 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3869:11)
E/flutter ( 8223): #33 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3716:5)
E/flutter ( 8223): #34 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2960:14)
E/flutter ( 8223): #35 Element.updateChild (package:flutter/src/widgets/framework.dart:2763:12)
E/flutter ( 8223): #36 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3752:16)
E/flutter ( 8223): #37 Element.rebuild (package:flutter/src/widgets/framework.dart:3564:5)
E/flutter ( 8223): #38 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3721:5)
E/flutter ( 8223): #39 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3716:5)
E/flutter ( 8223): #40 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2960:14)
E/flutter ( 8223): #41 Element.updateChild (package:flutter/src/widgets/framework.dart:2763:12)
E/flutter ( 8223): #42 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3752:16)
E/flutter ( 8223): #43 Element.rebuild (package:flutter/src/widgets/framework.dart:3564:5)
E/flutter ( 8223): #44 ComponentElement._firs
答案 0 :(得分:1)
只需将此文件添加到</application>
文件中的AndroidManifest.xml
之前即可。
<service android:name="com.ryanheise.audioservice.AudioService">
<intent-filter>
<action android:name="android.media.browse.MediaBrowserService" />
</intent-filter>
</service>
<receiver android:name="android.support.v4.media.session.MediaButtonReceiver" >
<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter>
</receiver>
答案 1 :(得分:1)
答案 2 :(得分:0)
我正在尝试相同的事情,当我将服务标签和接收者标签添加到AndroidManifest.xml时,出现错误,这可能是您遇到的相同问题:
在清单文件com.ryanheise.audioservice.AudioService中引用的类未在项目或库中/未解析的包“ audioservice”中找到
是的,我在pubspec.yaml中具有audio_service作为依赖项,是的,我做了Pub Get。
我不知道为什么会发生此错误,但我无法想象audio_service可以在没有此错误的情况下运行。