1
This commit is contained in:
@@ -6,7 +6,9 @@ import 'package:vibration/vibration.dart';
|
||||
/// 提醒:同类目标 10s 内只提醒一次。
|
||||
/// 震动/提示音默认开启,不提供关闭入口。
|
||||
class Reminder {
|
||||
final AudioPlayer _player = AudioPlayer();
|
||||
// 惰性创建:AudioPlayer 构造即发起平台初始化(无插件环境下未处理错误会
|
||||
// 泄漏为 unhandled async error),首响时才建
|
||||
AudioPlayer? _player;
|
||||
String? _lastAlertLabel;
|
||||
int _lastAlertAt = 0;
|
||||
|
||||
@@ -24,11 +26,12 @@ class Reminder {
|
||||
void _vibrate() => Vibration.vibrate(duration: 200);
|
||||
|
||||
Future<void> _playTone() async {
|
||||
await _player.stop();
|
||||
await _player.play(AssetSource('beep.wav'));
|
||||
final p = _player ??= AudioPlayer();
|
||||
await p.stop();
|
||||
await p.play(AssetSource('beep.wav'));
|
||||
}
|
||||
|
||||
void release() {
|
||||
_player.dispose();
|
||||
_player?.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user