hyzp_ybqx-Commit124:使用AudioPlayer cache优化播放逻辑,解决多次播放后报错无法播放问题
This commit is contained in:
@@ -6,8 +6,8 @@ import 'dart:math';
|
||||
|
||||
import 'package:ai_save_account/ai_save_account.dart';
|
||||
import 'package:audioplayers/audio_cache.dart';
|
||||
import 'package:audioplayers/audioplayers.dart';
|
||||
|
||||
// import 'package:audioplayers/audio_cache.dart';
|
||||
import 'package:camera/camera.dart';
|
||||
import 'package:convert/convert.dart';
|
||||
import 'package:crypto/crypto.dart' as crypto;
|
||||
@@ -16,30 +16,49 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
|
||||
//import '../my_wechat_assets_picker_fix/my_asset_picker_1.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
import 'package:hyzp_ybqx/provider/player_region.dart';
|
||||
// import 'package:just_audio/just_audio.dart';
|
||||
|
||||
import 'UserInfo.dart';
|
||||
import 'dioFun.dart';
|
||||
|
||||
// final myPlayer = AudioPlayer();
|
||||
final myPlayer = AudioCache();
|
||||
////////////////////////////////////////////
|
||||
AudioPlayer playerClick;
|
||||
AudioPlayer playerClacks;
|
||||
AudioPlayer playerVoiceRemind;
|
||||
|
||||
// myPlayMp3({String asset = 'assets/audio/yinxiao1064.mp3'}) {
|
||||
// // myPlayer.setAsset(asset, preload: true).then((value) {
|
||||
// // myPlayer.play();
|
||||
// // });
|
||||
// // myPlayer.setAsset(asset).then((value) {
|
||||
// // myPlayer.play();
|
||||
// // });
|
||||
// }
|
||||
|
||||
myPlayMp3({String asset = 'audio/语音提醒.mp3'}) {
|
||||
myPlayer.play(asset);
|
||||
myPlayClick() async {
|
||||
if (null == playerClick) {
|
||||
print("myPlayClick first by load mp3 file");
|
||||
playerClick = await AudioCache().play('audio/click.mp3');
|
||||
} else {
|
||||
print("myPlayClick resume() from cache");
|
||||
playerClick.seek(Duration(milliseconds: 0));
|
||||
playerClick.resume();
|
||||
}
|
||||
}
|
||||
|
||||
myPlayClacks() async {
|
||||
if (null == playerClick) {
|
||||
print("myPlayClick first by load mp3 file");
|
||||
playerClick = await AudioCache().play('audio/clacks.mp3');
|
||||
} else {
|
||||
print("myPlayClick resume() from cache");
|
||||
playerClick.seek(Duration(milliseconds: 0));
|
||||
playerClick.resume();
|
||||
}
|
||||
}
|
||||
|
||||
myPlayVoiceRemind() async {
|
||||
if (null == playerVoiceRemind) {
|
||||
print("myPlayVoiceRemind first by load mp3 file");
|
||||
playerVoiceRemind = await AudioCache().play('audio/语音提醒.mp3');
|
||||
} else {
|
||||
print("myPlayVoiceRemind resume() from cache");
|
||||
playerVoiceRemind.seek(Duration(milliseconds: 0));
|
||||
playerVoiceRemind.resume();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////
|
||||
// begin hyzp_ybqx-Commit022-区县切换新方法-OK
|
||||
@@ -133,7 +152,7 @@ Future doRemind() async {
|
||||
// print("播放:语音提醒.mp3");
|
||||
if (listReviewed.length > 0) {
|
||||
// AudioCache().play(File('audio/语音提醒.mp3').path); //语音提醒
|
||||
myPlayMp3(asset: 'audio/语音提醒.mp3');
|
||||
myPlayVoiceRemind();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ class _TakePictuerState extends State<TakePictuer> {
|
||||
await Future.delayed(Duration(milliseconds: 1000), () {
|
||||
print('开始拍照...');
|
||||
// AudioCache().play(File('audio/yinxiao1064.mp3').path); //播放咔嚓声
|
||||
myPlayMp3(asset: 'assets/audio/yinxiao1064.mp3'); //播放咔嚓声
|
||||
myPlayClacks(); //播放咔嚓声
|
||||
onTakePictureButtonPressed();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ class _LoginPageState extends State<page7_setRemind> {
|
||||
if (bVoiceRemind) {
|
||||
print("播放语音提醒");
|
||||
// AudioCache().play(File('audio/语音提醒.mp3').path); //语音提醒
|
||||
myPlayMp3(asset: 'audio/语音提醒.mp3');
|
||||
myPlayVoiceRemind();
|
||||
}
|
||||
getListView();
|
||||
});
|
||||
@@ -164,7 +164,7 @@ class _LoginPageState extends State<page7_setRemind> {
|
||||
setRemindTimer(enable: g_bVoiceRemind);
|
||||
|
||||
// AudioCache().play(File('audio/yinxiao1064.mp3').path); //音效提醒
|
||||
myPlayMp3(asset: 'assets/audio/yinxiao1064.mp3'); //音效提醒
|
||||
myPlayClacks(); //音效提醒
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user