Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AudioService.addToQueue generates exception: "This session doesn't support queue management operations". #9

Closed
BeMacized opened this issue Jan 1, 2019 · 6 comments
Assignees

Comments

@BeMacized
Copy link
Contributor

Hello!

While experimenting with this plugin, I ran into the issue that whenever I call AudioService.addQueueItem, the following exception is thrown:

E/MethodChannel#ryanheise.com/audioService(11872): Failed to handle method call
E/MethodChannel#ryanheise.com/audioService(11872): java.lang.UnsupportedOperationException: This session doesn't support queue management operations
E/MethodChannel#ryanheise.com/audioService(11872): 	at android.support.v4.media.session.MediaControllerCompat$MediaControllerImplApi21.addQueueItem(MediaControllerCompat.java:1988)
E/MethodChannel#ryanheise.com/audioService(11872): 	at android.support.v4.media.session.MediaControllerCompat.addQueueItem(MediaControllerCompat.java:316)
E/MethodChannel#ryanheise.com/audioService(11872): 	at com.ryanheise.audioservice.AudioServicePlugin$ClientHandler.onMethodCall(AudioServicePlugin.java:316)
E/MethodChannel#ryanheise.com/audioService(11872): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:200)
E/MethodChannel#ryanheise.com/audioService(11872): 	at io.flutter.view.FlutterNativeView.handlePlatformMessage(FlutterNativeView.java:163)
E/MethodChannel#ryanheise.com/audioService(11872): 	at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#ryanheise.com/audioService(11872): 	at android.os.MessageQueue.next(MessageQueue.java:326)
E/MethodChannel#ryanheise.com/audioService(11872): 	at android.os.Looper.loop(Looper.java:160)
E/MethodChannel#ryanheise.com/audioService(11872): 	at android.app.ActivityThread.main(ActivityThread.java:6863)
E/MethodChannel#ryanheise.com/audioService(11872): 	at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#ryanheise.com/audioService(11872): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
E/MethodChannel#ryanheise.com/audioService(11872): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

This error was produced with the following code, based off the example in this repo:
https://gist.github.com/BeMacized/5ccc11f43c4b18bd1e40a1e539082721

Any idea what might cause this?

@BeMacized BeMacized changed the title AudioSerivce.addToQueue generates exception: "This session doesn't support queue management operations". AudioService.addToQueue generates exception: "This session doesn't support queue management operations". Jan 1, 2019
@ryanheise ryanheise self-assigned this Jan 2, 2019
@ryanheise
Copy link
Owner

I've just published release 0.0.9 which should now support queue/playlist management. Just an important point about the way it works, this will only be enabled if you implement one or more of the queue callbacks passed into AudioServiceBackground.run. In your case, you would want to implement onAddToQueue. In here, you should then call setQueue to actually update the queue.

@BeMacized
Copy link
Contributor Author

Thank you very much for the help!

I have tried the new update, and I could sort of get it to work. However, I am running into trouble when I try to queue items immediately after starting the audio service. Currently, awaiting AudioService.start, does not wait for the background task to start (and therefore queue management to be enabled).

Therefore, the following snippet still throws the same exception as before:

MediaItem mediaItem = MediaItem(
    id: 'audio_1', album: 'Sample Album', title: 'Sample Title');

await AudioService.start(
    backgroundTask: backgroundTask,
    resumeOnClick: true,
    notificationChannelName: 'Audio Service Demo',
    notificationColor: 0xFF2196f3,
    androidNotificationIcon: 'mipmap/ic_launcher',
);

// Uncomment delay to "fix".
// await Future.delayed(Duration(seconds: 5));

await AudioService.addQueueItem(mediaItem);

However, when uncommenting the delay line, as a crude way of waiting for the background task to start, everything works as it should.

Is there maybe some way to await the background task being started?

@ryanheise
Copy link
Owner

I like that idea. I've implemented and committed it if you want to try it out. I haven't published a new release to the package server since I notice a pull request which I want to get to first.

@ryanheise
Copy link
Owner

This fix and your pull request are now included in release 0.0.10.

@BeMacized
Copy link
Contributor Author

Seems to work fine, thank you!

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs, or use StackOverflow if you need help with audio_service.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants