Closed incafox closed 5 years ago
@incafox I recommend you try using audio_service
plugin together with the flutter_radio
. The audio_service
make audio in background. I will try, but today I work in another project.
@yagoliveira92 i tried that ..., dont waste your time, it doesn't work so i maked my own background service with java and exoplayer.
Hi @incafox, I got using flutter_radio
in audio_service
. If you still looking for help, send a message to me. =D
Basically, i put this code for audio_service
class
void _backgroundAudioPlayerTask() async {
CustomAudioPlayer player = CustomAudioPlayer();
AudioServiceBackground.run(
onStart: player.run,
onPlay: player.play,
onPause: player.pause,
onStop: player.stop,
onClick: (MediaButton button) => player.playPause(),
);
}
class CustomAudioPlayer {
bool _playing;
Completer _completer = Completer();
Future<void> run() async {
MediaItem mediaItem = MediaItem(
id: 'audio_1',
album: 'ABC Radio',
title: 'A rádio que não cansa vc');
AudioServiceBackground.setMediaItem(mediaItem);
audioStart();
play();
await _completer.future;
}
Future<void> audioStart() async {
await FlutterRadio.audioStart();
print('Audio Start OK');
}
void playPause() {
if (_playing)
pause();
else
play();
}
void play() {
FlutterRadio.play(url: streamUrl);
_playing = true;
AudioServiceBackground.setState(
controls: [pauseControl, stopControl],
basicState: BasicPlaybackState.playing);
buttonState = !buttonState;
}
void pause() {
FlutterRadio.playOrPause(url: streamUrl);
AudioServiceBackground.setState(
controls: [playControl, stopControl],
basicState: BasicPlaybackState.paused);
}
void stop() {
FlutterRadio.playOrPause(url: streamUrl);
AudioServiceBackground.setState(
controls: [], basicState: BasicPlaybackState.stopped);
buttonState = !buttonState;
}
}
@yagoliveira92 great job! looks like i wasted my time learning java and custom android services. lol
@yagoliveira92 can you please post complete code for this dart. i am having issues.
@hrjt I use flutter_radio with audio_service, the complete source code that you are seeking for is https://github.com/odrevet/bide-et-musique-flutter/blob/master/lib/player.dart
Good day to all,
Companion @yagoliveira92 , I see that you managed to solve the problem with Flutter_Radio, it is possible that you share the code I have problems using the two plugins.
Thank you for your kind collaboration.
@yagoliveira92 can you please post complete code for this dart. Thank you!.
Hey, i was trying to use this plugin to play in background, but i dont know how to that with flutter and dart, do you know how to use this plugin as an audio service? Do i need to tweak the native implementation in order to use the player as a service? Please help, im stuck 2 days in this problem.