Flutter iOS存储音频不与音频播放器,fluttersound和只是音频播放

jfgube3f  于 2023-10-21  发布在  iOS
关注(0)|答案(2)|浏览(178)

我正在开发一个可以录制语音并从存储中播放的应用程序。我已经尝试了所有这些软件包,只在真实的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))
dffbzjpn

dffbzjpn1#

路的问题。iOS总是返回不同的路径。我猜他们为了“安全”屏蔽了目录的路径。如果你存储的是一个文件的完整路径,你可以得到真实的路径与功能,这是我的情况和substrating你的路径取决于你的情况,请注意你的情况;
其中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;
    }
  }
ljo96ir5

ljo96ir52#

对于iOS,只需在目录路径之前添加file://
System. out. println();
String fullUrl =“file://${dir.path}/MP3-FILE-NAME”;

相关问题