gpt4 book ai didi

c# - Windows Phone 8 中的视频文件到 Base64String 问题

转载 作者:太空宇宙 更新时间:2023-11-03 13:20:56 25 4
gpt4 key购买 nike

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

最佳答案

每个应用程序都可以完成 memory limit .

尝试释放资源。对流使用 using 是一种很好的做法。是这样的: 私有(private) IsolatedStorageFileStream isoVideoFile; string isoVideoFileName = "CameraMovie.mp4";

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

关于c# - Windows Phone 8 中的视频文件到 Base64String 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24237022/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com