2013-02-26 47 views
0

我被告知,當我允許用戶從我的應用內創建視頻時,應該自動生成.jpg縮略圖圖像。但是,使用Windows Phone電動工具,我可以看到只有視頻生成,沒有圖像。下面的代碼如下:創建WP8應用內視頻不會生成.jpg縮略圖

編輯:這裏的問題是如何從保存在獨立存儲中的給定視頻獲取縮略圖圖像?

 ' Set recording state: start recording. 
Private Async Sub StartVideoRecording() 
    Try 
     App.ViewModel.IsDataLoaded = False 

     'isoStore = Await ApplicationData.Current.LocalFolder.GetFolderAsync("IsolatedStore") 
     strVideoName = GenerateVideoName() 
     isoFile = Await isoVideoFolder.CreateFileAsync(strVideoName, CreationCollisionOption.ReplaceExisting) 
     thisAccessStream = Await isoFile.OpenAsync(FileAccessMode.ReadWrite) 
     Await avDevice.StartRecordingToStreamAsync(thisAccessStream) 

     'save the name of the video file into the list of video files in isolated storage settings 
     Dim videoList As New List(Of InfoViewModel) 

     isoSettings = IsolatedStorageSettings.ApplicationSettings 
     If isoSettings.Contains("ListOfVideos") Then 
      videoList = isoSettings("ListOfVideos") 
     Else 
      isoSettings.Add("ListOfVideos", videoList) 
     End If 
     videoList.Add(New InfoViewModel With {.Name = strVideoName, .DateRecorded = Date.Now}) 
     isoSettings("ListOfVideos") = videoList 
     isoSettings.Save() 
     isoSettings = Nothing 


     ' Set the button states and the message. 
     UpdateUI(ButtonState.Recording, "Recording...") 
    Catch e As Exception 
     ' If recording fails, display an error. 
     Me.Dispatcher.BeginInvoke(Sub() txtDebug.Text = "ERROR: " & e.Message.ToString()) 
    End Try 
End Sub 
+0

也許你應該堅持的官方文檔中提供的信息,不是來自互聯網的謠言? – 2013-03-24 00:28:51

+0

這是超級建設性和有益的,謝謝。我在這個網站上被多個人告知。如果這個網站上的信息是無關緊要的並且無用 - 正如你的嘲諷語氣所暗示的 - 那你爲什麼在這裏? – Jarrette 2013-03-24 05:15:51

+0

所以,我想windows phone沒有辦法從保存的視頻流製作縮略圖?因此,當列出一組視頻時,無法直觀地呈現每個視頻... – Jarrette 2013-03-24 05:19:50

回答

1

在的Windows Phone 7.0中使用的「官方」 SDK訪問比使用其他CameraCaptureTask相機是不可能的。但使用Microsoft.Phone.InteropServices庫可以在應用程序中創建自定義相機視圖。如果你使用這個VideoCamera班,它有一個事件叫做ThumbnailSavedToDisk,這可能是你聽說過的。但使用Microsoft.Phone.InteropServices的應用程序在Windows Phone Marketplace中從未被允許。你可以閱讀更多about it here


爲了從視頻文件中的一個解決方案是如何的MP4文件格式的作品讀了,並提取其中的一個框架和使用,作爲一個縮略圖的縮略圖。不幸的是,我還沒有找到任何可以做到這一點的圖書館。

另一個但並非最佳解決方案將是在MediaElement中播放視頻,然後將該控件呈現爲位圖。這可以用下面的代碼來完成(寫在XAML/C#,我不知道VB.net,但應該很容易端口):

<MediaElement 
    x:Name="VideoPlayer" 
    Width="640" 
    Height="480" 
    AutoPlay="True" 
    RenderTransformOrigin="0.5, 0.5" 
    VerticalAlignment="Center" 
    HorizontalAlignment="Center" 
    Stretch="Fill" 
    Canvas.Left="80"/> 

然後創建縮略圖:

// Set an event handler for when video has loaded 
VideoPlayer.MediaOpened += VideoPlayer_MediaOpened; 
// Read video from storage 
IsolatedStorageFileStream videoFile = new IsolatedStorageFileStream("MyVideo.mp4", FileMode.Open, FileAccess.Read, IsolatedStorageFile.GetUserStoreForApplication()); 
VideoPlayer.SetSource(videoFile); 
// Start playback 
VideoPlayer.Play(); 

,然後創建事件,其 「捕獲」 的縮略圖:

void VideoPlayer_MediaOpened(object sender, RoutedEventArgs e) 
{ 
    Thread.Sleep(100); // Wait for a short time to avoid black frame 
    WriteableBitmap wb = new WriteableBitmap(VideoPlayer, new TranslateTransform()); 
    thumbnailImageHolder.Source = wb; // Setting it to a Image in the XAML code to see it 
    VideoPlayer.Stop(); 
} 

下面是我t使用Video Recorder Sample的修改版本時看起來不錯。 (在右上角的藍色邊框的小圖像是錄製視頻的縮略圖。背後是相機瀏覽器。)

enter image description here

+1

微軟認可的合作伙伴可以使用Microsoft.Phone.InteropServices'。但是渲染到表面是推薦的方式,不管怎樣,假定您的應用程序已經在渲染視頻。 – 2013-03-26 21:19:38