I am not able to control audio playback(play/pause/seek_next/seek_prev) from the buttons on the home_screen widget in flutter (android).
not being able to control playback from buttons on Home_widget means that the callback that I am registering in the main method by using:
HomeWidget.registerBackgroundCallback(homeScreenWidgetCallback);
has these lines of code
dynamic homeScreenWidgetCallback(Uri? uri) async {
print(uri?.host);
if(uri?.host == 'seek_prev'){
if((player.position.inMilliseconds ?? 0) >= 2100 || player.currentIndex == 0){
player.seek(Duration(seconds: 0));
}else{
player.seekToPrevious();
player.play();
}
}else if (uri?.host == 'play_pause') {
if(!player.playing){
player.play();
}else{
player.pause();
}
}else{
if(player.nextIndex != null){
player.seekToNext();
player.play();
}else{
player.pause();
player.seek(Duration.zero, index: player.currentIndex);
}
}
await HomeWidget.updateWidget(name: 'AppWidgetProvider', iOSName: 'AppWidgetProvider');
}
but the player method Im using don't actually stop the music or change its state though they do one thing on click that is:
if some other application is playing audio and I press any of these audio control buttons on my home widget the music stops from the other app.
Player is a AudioPlayer from the library "just_audio" HomeWidget comes from the library "home_widget"
Im also using the library "just_audio_background" for media control from notification
I think I might be missing some service element or receiver element in the android manifest but I tried a lot of stuff and nothing really worked out. Any help is greatly appreciated