Metronome
Efficient, accurate, cross-platform metronome; supports volume, BPM, time signature and audio source settings.
Version 2.0 refactored most of the code, with better performance (BPM>600), less resource usage, and more accurate time signature callback.

Demo
TODO
xAdd support for time signature #2xAdd windows supportxAdd tickCallback for web
Quick Start
Init
final metronome = Metronome();
metronome.init(
'assets/audio/snare.wav',
accentedPath: 'assets/audio/claves44_wav.wav',
bpm: 120,
//0 ~ 100
volume: 50,
enableTickCallback: true,
// The time signature is the number of beats per measure,default is 4
timeSignature: 4,
sampleRate: 44100,
// iOS only. Keep true unless the host app manages AVAudioSession.
manageAudioSession: true,
);
iOS audio session management
manageAudioSession controls whether the plugin configures and activates the shared AVAudioSession during initialization.
The default value is true, which preserves the existing behavior. The plugin uses the playAndRecord category, videoRecording mode, and activates the audio session.
Set it to false when the host application already manages AVAudioSession, for example through the Flutter audio_session package. The host application must configure and activate its audio session before starting audio playback:
await metronome.init(
'assets/audio/snare.wav',
manageAudioSession: false,
);
This parameter only affects iOS. It does not change audio session behavior on Android, macOS, Windows, or Web.
Play
metronome.play();
Pause
metronome.pause();
Stop
metronome.stop();
Volume
metronome.getVolume();
metronome.setVolume(50);
BPM
metronome.setBPM(120);
metronome.getBPM();
TimeSignature
Disable accents when less than 2
metronome.setTimeSignature(4);
metronome.getTimeSignature();
isPlaying
Get play state
metronome.isPlaying();
isInitialized
Getter that returns true if the metronome has completed initialization. After init is called.
Not platform dependant.
metronome.isInitialized;
setAudioFile
main, accent can be set at the same time or individually
metronome.setAudioFile(
mainPath:'assets/audio/snare.wav',
accentedPath:'assets/audio/claves.wav'
);
metronome.setAudioFile(
mainPath:'assets/audio/snare.wav',
);
destroy
metronome.destroy();
Tick callback
enableTickCallback must be set to true in init
metronome.tickStream.listen((int tick) {
print("tick: $tick");
});