|
|
@@ -23,6 +23,7 @@ import '../../dialog/alert_dialog.dart';
|
|
|
import '../../utils/toast_util.dart';
|
|
|
import '../record/controller.dart';
|
|
|
import 'original/view.dart';
|
|
|
+import 'package:just_audio/just_audio.dart';
|
|
|
|
|
|
class TalkController extends BaseController {
|
|
|
final String uploadNoPrompts = "UPLOAD_NO_PROMPTS";
|
|
|
@@ -31,10 +32,16 @@ class TalkController extends BaseController {
|
|
|
|
|
|
final isShowElectricLow = false.obs;
|
|
|
|
|
|
+ bool isAudioLoading = false;
|
|
|
+
|
|
|
+ final double sliderMax = 1;
|
|
|
+
|
|
|
final isAudioPlaying = false.obs;
|
|
|
|
|
|
final audioProgressValue = 0.0.obs;
|
|
|
|
|
|
+ final audioDuration = Duration.zero.obs;
|
|
|
+
|
|
|
final agendaAllList = <AgendaListAllBean>[].obs;
|
|
|
|
|
|
final List<String> tabBeans = [
|
|
|
@@ -43,6 +50,8 @@ class TalkController extends BaseController {
|
|
|
StringName.talkTabOriginal.tr
|
|
|
];
|
|
|
|
|
|
+ final _audioPlayer = AudioPlayer();
|
|
|
+
|
|
|
StreamSubscription? _talkBeanListener;
|
|
|
|
|
|
final pages = [const SummaryView(), const TodoView(), const OriginalView()];
|
|
|
@@ -50,17 +59,66 @@ class TalkController extends BaseController {
|
|
|
@override
|
|
|
void onReady() {
|
|
|
super.onReady();
|
|
|
+ _initAudioPlayer();
|
|
|
_initListener();
|
|
|
_getArguments();
|
|
|
}
|
|
|
|
|
|
+ void _initAudioPlayer() {
|
|
|
+ _audioPlayer.playerStateStream.listen((playerState) {
|
|
|
+ if (playerState.processingState == ProcessingState.loading ||
|
|
|
+ playerState.processingState == ProcessingState.buffering) {
|
|
|
+ isAudioLoading = true;
|
|
|
+ debugPrint('音频load = true');
|
|
|
+ } else {
|
|
|
+ debugPrint('音频load = false');
|
|
|
+ isAudioLoading = false;
|
|
|
+ if (playerState.processingState == ProcessingState.completed) {
|
|
|
+ _audioPlayer.stop();
|
|
|
+ _audioPlayer.seek(Duration.zero);
|
|
|
+ isAudioPlaying.value = false;
|
|
|
+ debugPrint('音频 播放结束了');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ isAudioPlaying.value = playerState.playing;
|
|
|
+ }, onError: (Object e, StackTrace stackTrace) {
|
|
|
+ debugPrint('音频加载异常 == $e');
|
|
|
+ });
|
|
|
+
|
|
|
+ _audioPlayer.durationStream.listen((duration) {
|
|
|
+ if (duration != null) {
|
|
|
+ debugPrint('音频总播放时长 == ${duration.inMilliseconds}');
|
|
|
+ audioDuration.value = duration;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ _audioPlayer.positionStream.listen((position) {
|
|
|
+ if (audioDuration.value.inMilliseconds > 0) {
|
|
|
+ audioProgressValue.value =
|
|
|
+ (position.inMilliseconds / audioDuration.value.inMilliseconds)
|
|
|
+ .clamp(0.0, sliderMax);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
void _initListener() {
|
|
|
_talkBeanListener = talkBean.listen((bean) {
|
|
|
_dealTalkUpdate(bean);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- void _dealTalkUpdate(TalkBean? bean) {}
|
|
|
+ void _dealTalkUpdate(TalkBean? bean) async {
|
|
|
+ String? id = talkBean.value?.id;
|
|
|
+ if (id == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ File file = await RecordController.getRecordFile(id);
|
|
|
+ await _audioPlayer.setAudioSource(AudioSource.uri(file.uri));
|
|
|
+ } catch (e) {
|
|
|
+ debugPrint('音频设置异常 == $e');
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
void _getArguments() {
|
|
|
if (Get.arguments is TalkBean) {
|
|
|
@@ -68,6 +126,26 @@ class TalkController extends BaseController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ void updateProgress(double value) {
|
|
|
+ final newPosition = Duration(
|
|
|
+ milliseconds: (value * audioDuration.value.inMilliseconds).toInt());
|
|
|
+ _audioPlayer.seek(newPosition);
|
|
|
+ }
|
|
|
+
|
|
|
+ void clickPlayAudio() {
|
|
|
+ if (isAudioLoading) {
|
|
|
+ ToastUtil.showToast(StringName.talkAudioLoading.tr);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (_audioPlayer.playing) {
|
|
|
+ _audioPlayer.pause();
|
|
|
+ isAudioPlaying.value = false;
|
|
|
+ } else {
|
|
|
+ _audioPlayer.play();
|
|
|
+ isAudioPlaying.value = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
void _checkFileSizeAndNet() async {
|
|
|
String? id = talkBean.value?.id;
|
|
|
if (id == null) {
|
|
|
@@ -211,9 +289,6 @@ class TalkController extends BaseController {
|
|
|
void onClose() {
|
|
|
super.onClose();
|
|
|
_talkBeanListener?.cancel();
|
|
|
- }
|
|
|
-
|
|
|
- void updateProgress(double value) {
|
|
|
- audioProgressValue.value = value;
|
|
|
+ _audioPlayer.dispose();
|
|
|
}
|
|
|
}
|