Flutter-AssetsAudioPlayer icon indicating copy to clipboard operation
Flutter-AssetsAudioPlayer copied to clipboard

Remove multiple instance of network audio playing at the same time

Open visionxStudio opened this issue 1 year ago • 2 comments

Flutter version :- 3.3.1 Tools • Dart 2.18.0 • DevTools 2.15.0 assets_audio_player : latest_version

The problem that I am facing while playing network audio is that it is playing sometimes the multiple instance of songs or audio at the same time , one of the audio being controllable and the other is not. It just keeps playing in the background and there is no way to stop it rather than closing the app itself.

I guess if there is some way to check if multiple instances are running or how to disable multiple audio playback.

It would be great if there was an option to select if it is multiple playback or single playback of song.

I have this at audio_service.dart

final audio_player.AssetsAudioPlayer audioPlayer = audio_player.AssetsAudioPlayer.withId('musicplayer');

@override Future playAtIndex(int index) async { if (audioPlayer.isPlaying.value) { log("Stopping player"); await _player.stop(); } await audioPlayer.open( audio_player.Playlist( audios: audios, startIndex: index, ), showNotification: false, audioFocusStrategy: const AudioFocusStrategy.request( resumeAfterInterruption: true, resumeOthersPlayersAfterDone: true, ), ); }

visionxStudio avatar Mar 15 '23 22:03 visionxStudio

Flutter version :- 3.3.1 Tools • Dart 2.18.0 • DevTools 2.15.0 assets_audio_player : latest_version

The problem that I am facing while playing network audio is that it is playing sometimes the multiple instance of songs or audio at the same time , one of the audio being controllable and the other is not. It just keeps playing in the background and there is no way to stop it rather than closing the app itself.

I guess if there is some way to check if multiple instances are running or how to disable multiple audio playback.

It would be great if there was an option to select if it is multiple playback or single playback of song.

I have this at audio_service.dart

final audio_player.AssetsAudioPlayer audioPlayer = audio_player.AssetsAudioPlayer.withId('musicplayer');

@OverRide Future playAtIndex(int index) async { if (audioPlayer.isPlaying.value) { log("Stopping player"); await _player.stop(); } await audioPlayer.open( audio_player.Playlist( audios: audios, startIndex: index, ), showNotification: false, audioFocusStrategy: const AudioFocusStrategy.request( resumeAfterInterruption: true, resumeOthersPlayersAfterDone: true, ), ); }

Does the song keep playing in the background? Even when exiting the app by clicking the back button? Please do reply.

ghost avatar Mar 22 '23 08:03 ghost

yes I'm also getting this error while playing network audio

Raj-impetrosys avatar Jul 10 '23 11:07 Raj-impetrosys