📜  颤动按钮音效 - Dart 代码示例

📅  最后修改于: 2022-03-11 14:48:08.758000             🧑  作者: Mango

代码示例1
import 'package:soundpool/soundpool.dart';
import 'package:get/get.dart';

class PcmController extends GetxController {
  Soundpool _pool;
  int idMicUp;
  SoundpoolOptions _soundpoolOptions =
      SoundpoolOptions(streamType: StreamType.notification);


  @override
  void onInit() {
    _pool = Soundpool.fromOptions(options: _soundpoolOptions);
    _loadSounds();
    super.onInit();
  }

  _loadSounds() async {
    var asset = await rootBundle.load("assets/sounds/micUp.m4a");
    idMicUp = await _pool.load(asset);
  }

  playSound() async {
    await _pool.play(idMicUp);
  }
}