|
|
@ -17,6 +17,14 @@ typedef CreateAudioPool = Future<AudioPool> Function(
|
|
|
|
/// audio
|
|
|
|
/// audio
|
|
|
|
typedef PlaySingleAudio = Future<void> Function(String);
|
|
|
|
typedef PlaySingleAudio = Future<void> Function(String);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Function that defines the contract for looping a single
|
|
|
|
|
|
|
|
/// audio
|
|
|
|
|
|
|
|
typedef LoopSingleAudio = Future<void> Function(String);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Function that defines the contract for pre fetching an
|
|
|
|
|
|
|
|
/// audio
|
|
|
|
|
|
|
|
typedef PreCacheSingleAudio = Future<void> Function(String);
|
|
|
|
|
|
|
|
|
|
|
|
/// Function that defines the contract for configuring
|
|
|
|
/// Function that defines the contract for configuring
|
|
|
|
/// an [AudioCache] instance
|
|
|
|
/// an [AudioCache] instance
|
|
|
|
typedef ConfigureAudioCache = void Function(AudioCache);
|
|
|
|
typedef ConfigureAudioCache = void Function(AudioCache);
|
|
|
@ -29,9 +37,14 @@ class PinballAudio {
|
|
|
|
PinballAudio({
|
|
|
|
PinballAudio({
|
|
|
|
CreateAudioPool? createAudioPool,
|
|
|
|
CreateAudioPool? createAudioPool,
|
|
|
|
PlaySingleAudio? playSingleAudio,
|
|
|
|
PlaySingleAudio? playSingleAudio,
|
|
|
|
|
|
|
|
LoopSingleAudio? loopSingleAudio,
|
|
|
|
|
|
|
|
PreCacheSingleAudio? preCacheSingleAudio,
|
|
|
|
ConfigureAudioCache? configureAudioCache,
|
|
|
|
ConfigureAudioCache? configureAudioCache,
|
|
|
|
}) : _createAudioPool = createAudioPool ?? AudioPool.create,
|
|
|
|
}) : _createAudioPool = createAudioPool ?? AudioPool.create,
|
|
|
|
_playSingleAudio = playSingleAudio ?? FlameAudio.audioCache.play,
|
|
|
|
_playSingleAudio = playSingleAudio ?? FlameAudio.audioCache.play,
|
|
|
|
|
|
|
|
_loopSingleAudio = loopSingleAudio ?? FlameAudio.audioCache.loop,
|
|
|
|
|
|
|
|
_preCacheSingleAudio =
|
|
|
|
|
|
|
|
preCacheSingleAudio ?? FlameAudio.audioCache.load,
|
|
|
|
_configureAudioCache = configureAudioCache ??
|
|
|
|
_configureAudioCache = configureAudioCache ??
|
|
|
|
((AudioCache a) {
|
|
|
|
((AudioCache a) {
|
|
|
|
a.prefix = '';
|
|
|
|
a.prefix = '';
|
|
|
@ -41,6 +54,10 @@ class PinballAudio {
|
|
|
|
|
|
|
|
|
|
|
|
final PlaySingleAudio _playSingleAudio;
|
|
|
|
final PlaySingleAudio _playSingleAudio;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final LoopSingleAudio _loopSingleAudio;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final PreCacheSingleAudio _preCacheSingleAudio;
|
|
|
|
|
|
|
|
|
|
|
|
final ConfigureAudioCache _configureAudioCache;
|
|
|
|
final ConfigureAudioCache _configureAudioCache;
|
|
|
|
|
|
|
|
|
|
|
|
late AudioPool _scorePool;
|
|
|
|
late AudioPool _scorePool;
|
|
|
@ -48,11 +65,17 @@ class PinballAudio {
|
|
|
|
/// Loads the sounds effects into the memory
|
|
|
|
/// Loads the sounds effects into the memory
|
|
|
|
Future<void> load() async {
|
|
|
|
Future<void> load() async {
|
|
|
|
_configureAudioCache(FlameAudio.audioCache);
|
|
|
|
_configureAudioCache(FlameAudio.audioCache);
|
|
|
|
|
|
|
|
|
|
|
|
_scorePool = await _createAudioPool(
|
|
|
|
_scorePool = await _createAudioPool(
|
|
|
|
_prefixFile(Assets.sfx.plim),
|
|
|
|
_prefixFile(Assets.sfx.plim),
|
|
|
|
maxPlayers: 4,
|
|
|
|
maxPlayers: 4,
|
|
|
|
prefix: '',
|
|
|
|
prefix: '',
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await Future.wait([
|
|
|
|
|
|
|
|
_preCacheSingleAudio(_prefixFile(Assets.sfx.google)),
|
|
|
|
|
|
|
|
_preCacheSingleAudio(_prefixFile(Assets.music.background)),
|
|
|
|
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Plays the basic score sound
|
|
|
|
/// Plays the basic score sound
|
|
|
@ -65,6 +88,11 @@ class PinballAudio {
|
|
|
|
_playSingleAudio(_prefixFile(Assets.sfx.google));
|
|
|
|
_playSingleAudio(_prefixFile(Assets.sfx.google));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Plays the background music
|
|
|
|
|
|
|
|
void backgroundMusic() {
|
|
|
|
|
|
|
|
_loopSingleAudio(_prefixFile(Assets.music.background));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String _prefixFile(String file) {
|
|
|
|
String _prefixFile(String file) {
|
|
|
|
return 'packages/pinball_audio/$file';
|
|
|
|
return 'packages/pinball_audio/$file';
|
|
|
|
}
|
|
|
|
}
|
|
|
|