cd32eb01
吴启风
feat:播放音乐防抖处理(课程环节页)
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
import 'package:flutter/material.dart';
import '../../utils/audio_player_util.dart';
/// action前播放音乐控制类,维护状态做防抖处理
/// todo 需要结合生命周期,尤其是在声明周期结束后及时中断,避免action泄漏
class ActionWithMusicController {
ActionWithMusicController._privateConstructor();
static final ActionWithMusicController _instance = ActionWithMusicController._privateConstructor();
factory ActionWithMusicController() {
return _instance;
}
bool _isPlaying = false;
Future<void> playMusicAndPerformAction(BuildContext context,
AudioPlayerUtilType audioType, Function action) async {
if (_isPlaying) return;
_isPlaying = true;
// Play the music
await AudioPlayerUtil.getInstance()
.playAudio(audioType);
action();
_isPlaying = false;
}
// void dispose() {
// _audioPlayer.dispose();
// }
}
|