onStateChanged method
onStateChanged
- Restores BGM (via onRestore) when voice completes or is stopped, but only if withDucking is enabled.
- Invokes onCompleted when the voice completes.
Implementation
@override
void onStateChanged(PlayerState state) {
if (state == PlayerState.completed || state == PlayerState.stopped) {
if (withDucking && onRestore != null) {
onRestore!();
}
if (state == PlayerState.completed && onCompleted != null) {
onCompleted!();
}
}
}