我在Windows Phone 8中创建了一个视频录制功能,并将字节数组转换为base-64字符串。我如何获得录音的持续时间?我的字节数组内存大小太大,因此base64String也太大了,所以我得到这样的错误:
"System.OutOfMemoryException"
有关详细信息,请参阅下面的代码:
private IsolatedStorageFileStream isoVideoFile;
string isoVideoFileName = "CameraMovie.mp4";
isoVideoFile = new IsolatedStorageFileStream(isoVideoFileName,
FileMode.OpenOrCreate, FileAccess.ReadWrite,
IsolatedStorageFile.GetUserStoreForApplication());
MemoryStream stream = new MemoryStream();
isoVideoFile.Write(stream.GetBuffer(), 0, (int)stream.Position);
byte[] binaryData = new Byte[isoVideoFile.Length];
long bytesRead = isoVideoFile.Read(binaryData, 0, (int)isoVideoFile.Length);
string videofile = Convert.ToBase64String(binaryData, 0, binaryData.Length);
视频长度:
private void Element_MediaOpened1(object sender, RoutedEventArgs e)
{
if (mediaElement_1.NaturalDuration.HasTimeSpan)
timelineSlider.Maximum = mediaElement_1.NaturalDuration.TimeSpan.TotalSeconds;
}
答案 0 :(得分:1)
你可以通过每个应用memory limit来克服。
尝试处置资源。将using
与流一起使用是一种很好的做法。像这样的东西:
private IsolatedStorageFileStream isoVideoFile;
string isoVideoFileName =" CameraMovie.mp4&#34 ;;
using(isoVideoFile = new IsolatedStorageFileStream(isoVideoFileName,
FileMode.OpenOrCreate, FileAccess.ReadWrite,
IsolatedStorageFile.GetUserStoreForApplication()))
{
using(MemoryStream stream = new MemoryStream())
{
isoVideoFile.Write(stream.GetBuffer(), 0, (int)stream.Position);
}
byte[] binaryData = new Byte[isoVideoFile.Length];
long bytesRead = isoVideoFile.Read(binaryData, 0, (int)isoVideoFile.Length);
string videofile = Convert.ToBase64String(binaryData, 0, binaryData.Length);
}
视频时长怎么样,这里是thread on msdn forums