Files
flame/lib/flame_audio.dart
Renan Araujo f43320f957 comment format
2019-04-19 12:16:05 -03:00

57 lines
1.7 KiB
Dart

import 'package:audioplayers/audioplayers.dart';
import 'package:audioplayers/audio_cache.dart';
/// Handles flame audio functions
class FlameAudio {
AudioCache audioCache = AudioCache(prefix: 'audio/');
/// Plays a single run of the given [file]
Future<AudioPlayer> play(String file, {volume = 1.0}) {
return audioCache.play(file, volume: volume, mode: PlayerMode.LOW_LATENCY);
}
/// Plays, and keep looping the given [file]
Future<AudioPlayer> loop(String file, {volume = 1.0}) {
return audioCache.loop(file, volume: volume, mode: PlayerMode.LOW_LATENCY);
}
/// Plays a single run of the given file [file]
/// This method supports long audio files
Future<AudioPlayer> playLongAudio(String file, {volume = 1.0}) {
return audioCache.play(file, volume: volume);
}
/// Plays, and keep looping the given [file]
/// This method supports long audio files
///
/// NOTE: Length audio files on Android have an audio gap between loop iterations, this happens due to limitations on Android's native media player features, if you need a gapless loop, prefer the loop method
Future<AudioPlayer> loopLongAudio(String file, {volume = 1.0}) {
return audioCache.play(file, volume: volume);
}
/// Prefetch an audio in the cache
Future<void> load(String file) async {
await audioCache.load(file);
}
/// Prefetch a list of audios in the cache
Future<void> loadAll(List<String> files) async {
await audioCache.loadAll(files);
}
/// Clears the file in the cache
void clear(String file) {
audioCache.clear(file);
}
/// Clears all the audios in the cache
void clearAll() {
audioCache.clearCache();
}
/// Disables audio related logs
void disableLog() {
audioCache.disableLog();
}
}