Skip to content

When the app was bought to the background and brought back to foreground, the audioPlayer.onPlayerComplete.listen sometimes will not be called. #1938

@zhushuihua

Description

@zhushuihua

Checklist

  • I read the troubleshooting guide before raising this issue
  • I made sure that the issue I am raising doesn't already exist

Current bug behaviour

When the app was bought to the background, the audioPlayer.onPlayerComplete.listen will not be called after the app was brought to foreground again.

Expected behaviour

audioPlyaer.onPlayerComplete listen should always be triggered.

import 'package:uma_abacus/audio/audio_service/abstract_audio_player.dart';
import 'package:audioplayers/audioplayers.dart';

class AudioPlayersPlayer extends AbstractAudioPlayer {
static AudioPlayer? prev;
late final AudioPlayer _audioPlayer = AudioPlayer()
..setVolume(1)
..setPlayerMode(PlayerMode.mediaPlayer);
final void Function() finishCallback;
AudioPlayersPlayer(this.finishCallback) {
//to dispose previous audio player to save resource//
prev?.dispose();
prev = _audioPlayer;
audioPlayer.onPlayerComplete.listen(() {
finishCallback();
});
}

@OverRide
Future play(String path) async {
await _audioPlayer.stop();
// await _audioPlayer.release();
_audioPlayer.play;
await _audioPlayer.setSource(AssetSource(path));
await _audioPlayer.resume();
// final duration = await _audioPlayer.getDuration();
// if (duration != null) {
// await Future.delayed(duration);
// finishCallback();
// }
// await _audioPlayer.setVolume(1);
}

@OverRide
Future stop() async {
await _audioPlayer.stop();
}
}

Steps to reproduce

  1. Execute flutter run on the code sample
  2. ...
  3. ...

Code sample

Code sample
void main() {
}

Affected platforms

iOS

Platform details

Tried on iPad 12.5.8 and Latest iPhone 18.5

AudioPlayers Version

6.50

Build mode

release

Audio Files/URLs/Sources

No response

Screenshots

No response

Logs

my relevant logs
Full Logs
my full logs or a link to a gist

Flutter doctor:

Output of: flutter doctor -v

Related issues / more information

No response

Working on PR

no way

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions