[英]Flutter iOS Storage audio doesnt Play with audioplayer, fluttersound and just audio
我正在開發一個可以錄制語音並從存儲中播放的應用程序。 我已經嘗試了所有這些軟件包,並且僅在真正的 iOS 設備上出現錯誤。 在仿真器方面,ios 也沒有問題。 我正在用 flutter flutter_sound錄制音頻。
目錄是
tempDir = await getTemporaryDirectory();
記錄;
startRecorderx(
FlutterSoundRecorder flutterSoundRecorder, Directory? tempDir) async {
log(tempDir!.path.toString());
PermissionStatus status;
try {
status = await Permission.microphone.request();
} catch (e) {
throw e;
}
log(tempDir.path.toString());
if (status != PermissionStatus.granted)
throw RecordingPermissionException("You must give acces to mic");
pathToRecord =
"${tempDir.path}/${DateTime.now().millisecondsSinceEpoch.toString()}.aac";
await flutterSoundRecorder.startRecorder(
toFile: "$pathToRecord",
codec: Codec.aacADTS,
);
}
然后我無法從路徑 netiher 3 包音頻播放器flutter_sound播放此文件。
play(path) async {
File file = File(path);
Uint8List bytes = file.readAsBytesSync();
await audio.play(path);
//log(result.toString());
/* await flutterSoundPlayer.startPlayer(
//fromURI: "$path",
fromDataBuffer: bytes,
) ;*/
update();
}
我只收到來自flutter_sound的錯誤。
PlatformException (PlatformException(Audio Player, startPlayer failure, null, null))
路徑的問題。 iOS 總是返回不同的路徑。 我猜他們為“安全”掩蓋了目錄的路徑。 如果您要存儲文件的完整路徑,您可以使用 function 獲得真實路徑,這是我的情況,您的路徑的子串取決於您的情況,請注意您的情況;
applicationDocumentDirectory 保存文件的位置; /Users/alperenbaskaya/Library/Developer/CoreSimulator/Devices/D3C845C6-D8CE-40FA-9060-1D8062E7F597/data/Containers/Data/Application/17501EFE-57A4-4C71-8C4C-58BBC57D1177/Documents/1661040154934.jpg
那么我的操作就是這樣;
Future<String> getCurrentUrl(String url)async{
if(Platform.isIOS){
String a = url.substring(url.indexOf("Documents/") + 10, url.length) ;
Directory dir = await getApplicationDocumentsDirectory();
a = "${dir.path}/$a";
return a;
}
else{
return url;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.