3

I want to play a "beep" sound from flutter. I did try to use SystemSound.play but it doesn't seem to work. Please help!.thank in advance.

Future<void> play(SystemSoundType type) async {
    await SystemChannels.platform.invokeMethod<void>(
      "SystemSound.play",
      type.toString(),
    );
}
void main() {
    play(SystemSoundType.click);
}
fixatd
  • 1,394
  • 1
  • 11
  • 19

1 Answers1

3

> 1.use this

soundpool: ^0.5.3 lib in pubspec.yaml

> 2.import this

import 'package:soundpool/soundpool.dart';

> 3.example

Soundpool pool = Soundpool(streamType: StreamType.notification);

int soundId = await rootBundle.load("sounds/dices.m4a").then((ByteData soundData) {
              return pool.load(soundData);
            }); int streamId = await pool.play(soundId);
Vithani Ravi
  • 1,807
  • 3
  • 13
  • 19