Flutter iOS 存储音频无法使用音频播放器、fluttersound 和仅音频播放
我正在开发一个可以录制语音并从存储中播放的应用程序。我已经尝试了所有这些软件包,但仅在真实的 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 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();
}
我仅从 flutter_sound 收到错误。
PlatformException (PlatformException(Audio Player, startPlayer failure, null, null))
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))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
路径的问题。 iOS返回总是不同的路径。我想他们掩盖了目录目录的“安全”路径。如果您要存储文件的完整路径,则可以通过该功能获得真正的路径,这是我的情况,并且串起您的路径取决于您的情况,请注意您的情况;
applicationDocumentDirectory在哪里保存文件;
/用户/alperenbaskaya/library/
developer/coreSimulator/devices/d3c845c6-d8ce-40fa-9060-1d8062e7f597/data/data/data/data/data/application/application/application/application/17501EFE-57A4-4C71-4C71-8C4C4C-58BBC5117DOUMTION 934.jpg,我的操作是那;
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;
对于iOS,只需添加文件://目录路径目录
dir dir =等待getApplicationDocumentsDirectory();
字符串fullurl =“ file:// $ {dir.path}/mp3-file-name”;
For iOS just add file:// before directory path
Directory dir = await getApplicationDocumentsDirectory();
String fullUrl = "file://${dir.path}/MP3-FILE-NAME";