【发布时间】:2020-02-25 13:37:18
【问题描述】:
我正在使用此代码保存我的记录:
string path = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;
public string fileName { get; set; }
fileName = Path.Combine(path, "sample.wav");
if (!recorder.IsRecording)
{
recorder.StopRecordingOnSilence = TimeoutSwitch.IsToggled;
//Start recording
var audioRecordTask = await recorder.StartRecording();
BtnDoneRec.IsEnabled = false;
await audioRecordTask;
RecEditor.IsEnabled = true;
BtnDoneRec.IsEnabled = false;
PlayButton.IsEnabled = true;
var filePath = recorder.GetAudioFilePath();
if (filePath != null)
{
var stream = recorder.GetAudioFileStream();
using (var fileStream = new FileStream(fileName, FileMode.Create, FileAccess.Write))
{
stream.CopyTo(fileStream);
}
}
}
else
{
//stop recording ...
await recorder.StopRecording();
}
我希望我的记录有一个带有我的 RecEditor 标记的特定名称
using (var streamReader = new StreamReader(fileName))
{
File.Move("sample.wav", RecEditor.Text + ".wav");
}
因此,每次我单击保存按钮时,它都会将“sample.wav”重命名为“RecEditor text.wav”。 但是当我点击保存时,它给了我这条记录
System.IO.FileNotFoundException: 'Could not find file '/sample.wav'.'
记录存储在/storage/emulated/0/sample.wav
sample.wav 是在我的设备中创建的,但我不知道为什么它给我“找不到文件 '/sample.wav'。”错误。我在这里做错了什么?
【问题讨论】:
标签: xamarin xamarin.forms