Commit 61ad6daf by tanghuan

audioPlay指令播放失败,toast提示

1 parent e939759f
......@@ -2,6 +2,8 @@ import 'package:appframe/bloc/web_cubit.dart';
import 'package:appframe/config/locator.dart';
import 'package:appframe/services/dispatcher.dart';
import 'package:appframe/services/player_service.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:uuid/uuid.dart';
class AudioPlayHandler extends MessageHandler {
......@@ -29,9 +31,17 @@ class AudioPlayHandler extends MessageHandler {
}
var playerService = getIt.get<PlayerService>();
var result = await playerService.playAudio(url, seek, playId, playRate);
var result = false;
try {
result = await playerService.playAudio(url, seek, playId, playRate);
} catch (e) {
// 播放异常(下载失败/音频损坏/播放器重建失败等):提示用户后继续上抛,保持 H5 的错误回调语义
_showPlayFailedToast();
rethrow;
}
if (!result) {
_showPlayFailedToast();
throw Exception('播放错误');
}
return {'playId': playId};
......@@ -45,6 +55,11 @@ class AudioPlayHandler extends MessageHandler {
this._webCubit = cubit;
}
/// 播放失败统一提示
void _showPlayFailedToast() {
Fluttertoast.showToast(msg: '无法播放该音频', gravity: ToastGravity.CENTER, backgroundColor: Colors.grey);
}
void _unfollowCubit() {
this._webCubit = null;
}
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!