Reputation: 888
I have created a video recording feature in Windows Phone 8, and am converting byte array to a base-64 string. How do I get the duration of the recording? My byte array memory size becomes too large and therefore the base64String is also too big, so I am getting error like this:
"System.OutOfMemoryException"
for more information see my code below:
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);
For video length:
private void Element_MediaOpened1(object sender, RoutedEventArgs e)
{
if (mediaElement_1.NaturalDuration.HasTimeSpan)
timelineSlider.Maximum = mediaElement_1.NaturalDuration.TimeSpan.TotalSeconds;
}
Upvotes: 2
Views: 180
Reputation: 3197
You get over per app memory limit.
Try to dispose resources. It's good practice to use using
with streams. Something like this:
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);
}
And what about video duration, here is thread on msdn forums
Upvotes: 1