hyzp_ybqx-Commit124:使用AudioPlayer cache优化播放逻辑,解决多次播放后报错无法播放问题
This commit is contained in:
Binary file not shown.
@@ -6,8 +6,8 @@ import 'dart:math';
|
|||||||
|
|
||||||
import 'package:ai_save_account/ai_save_account.dart';
|
import 'package:ai_save_account/ai_save_account.dart';
|
||||||
import 'package:audioplayers/audio_cache.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:camera/camera.dart';
|
||||||
import 'package:convert/convert.dart';
|
import 'package:convert/convert.dart';
|
||||||
import 'package:crypto/crypto.dart' as crypto;
|
import 'package:crypto/crypto.dart' as crypto;
|
||||||
@@ -16,30 +16,49 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_screenutil/flutter_screenutil.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:fluttertoast/fluttertoast.dart';
|
||||||
import 'package:hyzp_ybqx/provider/player_region.dart';
|
import 'package:hyzp_ybqx/provider/player_region.dart';
|
||||||
// import 'package:just_audio/just_audio.dart';
|
|
||||||
|
|
||||||
import 'UserInfo.dart';
|
import 'UserInfo.dart';
|
||||||
import 'dioFun.dart';
|
import 'dioFun.dart';
|
||||||
|
|
||||||
// final myPlayer = AudioPlayer();
|
////////////////////////////////////////////
|
||||||
final myPlayer = AudioCache();
|
AudioPlayer playerClick;
|
||||||
|
AudioPlayer playerClacks;
|
||||||
|
AudioPlayer playerVoiceRemind;
|
||||||
|
|
||||||
// myPlayMp3({String asset = 'assets/audio/yinxiao1064.mp3'}) {
|
myPlayClick() async {
|
||||||
// // myPlayer.setAsset(asset, preload: true).then((value) {
|
if (null == playerClick) {
|
||||||
// // myPlayer.play();
|
print("myPlayClick first by load mp3 file");
|
||||||
// // });
|
playerClick = await AudioCache().play('audio/click.mp3');
|
||||||
// // myPlayer.setAsset(asset).then((value) {
|
} else {
|
||||||
// // myPlayer.play();
|
print("myPlayClick resume() from cache");
|
||||||
// // });
|
playerClick.seek(Duration(milliseconds: 0));
|
||||||
// }
|
playerClick.resume();
|
||||||
|
}
|
||||||
myPlayMp3({String asset = 'audio/语音提醒.mp3'}) {
|
|
||||||
myPlayer.play(asset);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
// begin hyzp_ybqx-Commit022-区县切换新方法-OK
|
||||||
@@ -133,7 +152,7 @@ Future doRemind() async {
|
|||||||
// print("播放:语音提醒.mp3");
|
// print("播放:语音提醒.mp3");
|
||||||
if (listReviewed.length > 0) {
|
if (listReviewed.length > 0) {
|
||||||
// AudioCache().play(File('audio/语音提醒.mp3').path); //语音提醒
|
// 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), () {
|
await Future.delayed(Duration(milliseconds: 1000), () {
|
||||||
print('开始拍照...');
|
print('开始拍照...');
|
||||||
// AudioCache().play(File('audio/yinxiao1064.mp3').path); //播放咔嚓声
|
// AudioCache().play(File('audio/yinxiao1064.mp3').path); //播放咔嚓声
|
||||||
myPlayMp3(asset: 'assets/audio/yinxiao1064.mp3'); //播放咔嚓声
|
myPlayClacks(); //播放咔嚓声
|
||||||
onTakePictureButtonPressed();
|
onTakePictureButtonPressed();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ class _LoginPageState extends State<page7_setRemind> {
|
|||||||
if (bVoiceRemind) {
|
if (bVoiceRemind) {
|
||||||
print("播放语音提醒");
|
print("播放语音提醒");
|
||||||
// AudioCache().play(File('audio/语音提醒.mp3').path); //语音提醒
|
// AudioCache().play(File('audio/语音提醒.mp3').path); //语音提醒
|
||||||
myPlayMp3(asset: 'audio/语音提醒.mp3');
|
myPlayVoiceRemind();
|
||||||
}
|
}
|
||||||
getListView();
|
getListView();
|
||||||
});
|
});
|
||||||
@@ -164,7 +164,7 @@ class _LoginPageState extends State<page7_setRemind> {
|
|||||||
setRemindTimer(enable: g_bVoiceRemind);
|
setRemindTimer(enable: g_bVoiceRemind);
|
||||||
|
|
||||||
// AudioCache().play(File('audio/yinxiao1064.mp3').path); //音效提醒
|
// AudioCache().play(File('audio/yinxiao1064.mp3').path); //音效提醒
|
||||||
myPlayMp3(asset: 'assets/audio/yinxiao1064.mp3'); //音效提醒
|
myPlayClacks(); //音效提醒
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -100,16 +100,6 @@ dependencies:
|
|||||||
audioplayers: ^0.16.2
|
audioplayers: ^0.16.2
|
||||||
flutter_background_service: ^0.0.1+21
|
flutter_background_service: ^0.0.1+21
|
||||||
|
|
||||||
# just_audio: ^0.4.0 # 报错
|
|
||||||
# just_audio: ^0.3.4 # OK,不支持中文路径
|
|
||||||
# just_audio: ^0.3.0 # OK
|
|
||||||
# just_audio: ^0.1.0 # OK
|
|
||||||
|
|
||||||
# just_audio: ^0.6.15+1 # 引入该插件编译时报错如下
|
|
||||||
# Could not determine the dependencies of task ':app:processDebugResources'.
|
|
||||||
# > Could not resolve all task dependencies for configuration ':app:debugRuntimeClasspath'.
|
|
||||||
# > Could not resolve androidx.media2:media2-common:[1.1.0-alpha01].
|
|
||||||
|
|
||||||
encrypt: ^4.1.0
|
encrypt: ^4.1.0
|
||||||
device_info: ^1.0.0
|
device_info: ^1.0.0
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user