Closed maker-jr closed 4 years ago
Minimal reproduction project Provide a link here using one of two options: "The example"
The example works fine according to my own tests.
To Reproduce (i.e. user steps, not code) Steps to reproduce the behavior:
1. Go to 'The list of songs'
There is no list of songs in the example, and according to my testing, it doesn't exhibit the behaviour you describe...
The playback controlled by this library should pause or stop when another audio playback from another application starts or when another application needs to use the phone's speaker
If I can clarify, this plugin is not intended to control playback itself, it merely provides the callbacks that you can override in your own app to do that sort of thing if you want to. If your app is not doing that, it is because you have not implemented the callbacks to do that.
Incidentally, I have shown how to implement the callbacks in the example to do just that.
Which API doesn't behave as documented, and how does it misbehave? The Audio playback is supposed to pause when another audio player starts playing or when a call comes in. But in this case the audio just continue playing regardless of whether you're on a call or started another player. You have to pause it manually which is a bad user experience.
I am not clear on which API and which documentation you are referring to here.
@ryanheise Am sorry, my bad. I just came across the callbacks you implemented. I was able to achieve the desired behaviour by overriding onAudioFocusLost
and onAudioFocusGained
.
@ryanheise please tell me where can I find these callback? I am facing same issue on getting phone call or other music app playing.
@maker-jr ?
You can use audio_session to handle phone call and other interruptions. just_audio also handles this automatically by using audio_session internally.
@ryanheise I am using just_audio with audio_service but it is not getting interrupted by other music app and call, I tried audiosession in onStart() and configure it to music() and start listening stream but it is also not getting InterruptEvent. This is my onStart() method:
@override
Future
unawaited(audioPlayer.play());
// Start loading something (will play when ready).
await audioPlayer.setUrl(queue.first.id);
// AudioServiceBackground.setQueue(queue);
//
}`
You need to call setActive
on the audio session. But note this is not the place, you can either ask on StackOverflow or consult the source code to see how I have done it within just_audio, and also how I have done it within the TTS audio_service example.
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.
Which API doesn't behave as documented, and how does it misbehave? The Audio playback is supposed to pause when another audio player starts playing or when a call comes in. But in this case the audio just continue playing regardless of whether you're on a call or started another player. You have to pause it manually which is a bad user experience.
Minimal reproduction project Provide a link here using one of two options: "The example"
To Reproduce (i.e. user steps, not code) Steps to reproduce the behavior:
Error messages
Expected behavior The playback controlled by this library should pause or stop when another audio playback from another application starts or when another application needs to use the phone's speaker
Screenshots
Runtime Environment (please complete the following information if relevant):
Flutter SDK version
Additional context