【发布时间】:2014-07-23 14:48:54
【问题描述】:
在我的应用程序中,我可以录制 3 次我的声音,还可以收听录制的声音。听完之后,通过另一个功能,我将它们从隔离存储中删除。但问题是,我听过的最后一个声音,留在隔离存储中并删除隔离存储的方法无法删除最后一次播放。下次我想录制声音时,我会出错。我该如何解决这个问题?
错误:
录音代码:
private void SaveTempAudio(MemoryStream buffer)
{
using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication())
{
var bytes = buffer.GetWavAsByteArray(_recorder.SampleRate);
var tempFileName = "tempwave_" + _counter +".wav" ;
using (var audioStream = isoStore.CreateFile(tempFileName))
{
audioStream.Write(bytes, 0, bytes.Length);
_counter++;
}
}
}
用于播放和收听录制声音的代码;
private void PlayBackSound( string fileName)
{
using (var isoStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!isoStorage.FileExists(fileName))
return;
using (var fileStream = isoStorage.OpenFile(fileName, FileMode.Open, FileAccess.Read))
{
SoundPlayer.SetSource(fileStream);
SoundPlayer.Play();
}
}
}
用于删除我使用的文件:
using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication())
{
isoStore.Remove();
}
【问题讨论】:
标签: windows-phone-8 windows-phone isolatedstorage