import 'dart:async'; import 'package:halkyon_learn_flutter/src/core/asset/data/sound_player.dart'; /// A [SoundPlayer] that plays nothing and notes what it was asked to; a sound /// plays until stopped or [finish]ed. class FakeSoundPlayer() implements SoundPlayer { final _playing = StreamController.broadcast(); /// The paths it was asked to play, in order. final played = []; /// The file "playing" now. String? current; /// What playing throws, as for a file the platform can't decode; plays /// while null. Exception? failPlay; @override Stream get playing => _playing.stream; @override Future play(String path, {required String mimeType}) async { if (failPlay case final error?) { throw error; } played.add(path); _set(path); } @override Future stop() async => _set(null); /// Ends the sound playing, as when it reached its end. void finish() => _set(null); void _set(String? path) { current = path; _playing.add(path); } @override Future dispose() => _playing.close(); }