每次我在xamarin中保存记录时重命名记录文件
我正在使用以下代码保存记录:每次我在xamarin中保存记录时重命名记录文件,xamarin,xamarin.forms,Xamarin,Xamarin.forms,我正在使用以下代码保存记录: string path = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath; public string fileName { get; set; } fileName = Path.Combine(path, "sample.wav"); if (!recorder.IsRecording)
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();
}
我希望我的记录有一个特定的名称,并标有我的接收者
using (var streamReader = new StreamReader(fileName))
{
File.Move("sample.wav", RecEditor.Text + ".wav");
}
所以每次我点击保存按钮时,它都会将“sample.wav”重命名为“RecEditor text.wav”。
但是当我点击save时,它会给我这个记录
System.IO.FileNotFoundException: 'Could not find file '/sample.wav'.'
记录存储在/storage/simulated/0/sample.wav中
sample.wav是在我的设备中创建的,但我不知道为什么它会给我“找不到文件”/sample.wav“。错误。我做错了什么?我相信你看到的是这样的:
if(File.Exists(fileName))
{
var newFileName = Path.Combine(path, $"{RecEditor.Text}.wav");
File.Move(fileName, newFileName);
}
您不需要像现在这样打开一个新的流
。此外,您需要放置完整的文件路径,而不仅仅是文件名
在将其值用于newfileName
希望这有帮助。-这就是我要找的:D:D谢谢!