I am building a music player application, everything works fine, but when the phone screen is locked, the notification is disabled enter image description here
getSongs() async {
List<SongInfo> artists =
await audioQuery.getSongs(sortType: SongSortType.RECENT_YEAR);
for (var i = 0; i < artists.length; i++) {
int rr = math.Random().nextInt(9);
songs.add(Audio.file(artists[i].filePath,
metas: Metas(
title: artists[i].title,
artist: artists[i].artist,
image: MetasImage.file(artists[i].albumArtwork),
onImageLoadFail: MetasImage.asset('assets/$rr.jpg'))));
infos.add(artists[i]);
}
assetsAudioPlayer.open(Playlist(audios: songs),
showNotification: true,
autoStart: false,
loopMode: LoopMode.playlist,
playInBackground: PlayInBackground.enabled,
forceOpen: true,
notificationSettings: NotificationSettings(
playPauseEnabled: true,
nextEnabled: true,
prevEnabled: true,
stopEnabled: true,
seekBarEnabled: true,
)
// headPhoneStrategy: HeadPhoneStrategy.pauseOnUnplug,
);
}
i use assets_audio_player package
This problem is only in Android 9 and above
Please help me what is the solution?