Windows Phone 8的视频文件到Base64String的问题

本文关键字:Base64String 问题 文件 Phone 的视频 Windows | 更新日期: 2023-09-27 18:08:40

我在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;
    }

Windows Phone 8的视频文件到Base64String的问题

超过每个应用程序的内存限制。

尝试释放资源。将using与流一起使用是一个很好的实践。像这样:private IsolatedStorageFileStream isoVideoFile;

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);
}

关于视频持续时间,这里是msdn论坛的主题