2014-06-16 93 views
2

我在Windows Phone 8中創建了一個視頻錄製功能,並將字節數組轉換爲base-64字符串。我如何獲得錄音的持續時間?我的字節數組的內存大小變得過大,因此base64String也太大了,所以我得到的錯誤是這樣的:在Windows Phone 8中將視頻文件轉換爲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; 
    } 

回答

1

您已經完成每個應用程序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

+0

ad1Dima,我該感謝的人,我檢查它,以及如何獲得視頻持續時間?日Thnx –

+0

@NiteshKothari看到我的編輯。 – ad1Dima

+0

ad1Dima,我仍然收到錯誤兄弟:「在未知模塊中發生未處理的類型'System.ExecutionEngineException'異常。」 –

相關問題