I am working on an app that can record voice and play from storage. I have tried all these packages and get errors only on real iOS devices. On emulator side there is no issue on ios too. I am recording audio with flutter flutter_sound.
directory is
tempDir = await getTemporaryDirectory();
recording;
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,
);
}
Then i can not play this file from path netiher 3 packages audioplayers, 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();
}
I got error from flutter_sound only.
PlatformException (PlatformException(Audio Player, startPlayer failure, null, null))
The problem with path. iOS returns always different paths. They masks directory's path for 'security' I guess. If you are storing full path of a file you can get real path with the function, it is my case and substringing your path depends on your case, please mind your case;
where applicationDocumentDirectory saves file ; /Users/alperenbaskaya/Library/Developer/CoreSimulator/Devices/D3C845C6-D8CE-40FA-9060-1D8062E7F597/data/Containers/Data/Application/17501EFE-57A4-4C71-8C4C-58BBC57D1177/Documents/1661040154934.jpg
then my operation is that;
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;
}
}