Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I play system sound in flutter

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);
}
like image 850
Natthapol Maneechote Avatar asked Sep 02 '25 06:09

Natthapol Maneechote


1 Answers

> 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);
like image 178
Vithani Ravi Avatar answered Sep 04 '25 20:09

Vithani Ravi