2013-09-27 34 views
1

我目前正在爲使用Windows 8 IDE的Visual Studio Express開發Windows 8平板電腦Windows 8平板電腦的視頻聊天應用程序。我無法使用MediaCapture捕獲流。我想在CaptureElement中捕捉視頻,然後用於測試目的將其顯示在mediaelement中。我基本上想要將IRandomAccessStream轉換爲字節,然後在mediaelement中反過來。以下是我的代碼:地鐵應用程序中的視頻截圖

public sealed partial class MainPage : Page 
{ 

    MediaCapture mediaCapture; 
    IRandomAccessStream randomAccessStream; 


    public MainPage() 
    { 
     this.InitializeComponent(); 
     mediaCapture = new MediaCapture(); 
     randomAccessStream = new InMemoryRandomAccessStream(); 

    } 


    /// property is typically used to configure the page.</param> 
    protected override void OnNavigatedTo(NavigationEventArgs e) 
    { 

    } 


    async private void startCapture(object sender, RoutedEventArgs e) 
    { 

     await mediaCapture.InitializeAsync(); 
     capturePreview.Source = mediaCapture; 

     MediaEncodingProfile profile = MediaEncodingProfile.CreateWmv(VideoEncodingQuality.Auto); 
      await mediaCapture.StartRecordToStreamAsync(profile, randomAccessStream); 



    } 

    async private void stopCapture(object sender, RoutedEventArgs e) 
    { 
     await mediaCapture.StopRecordAsync(); 
     await randomAccessStream.FlushAsync(); 

     randomAccessStream.Seek(0); 

     // want to convert this randomAccessStream into byte[] 
     mediaElement.SetSource(randomAccessStream, "video/x-ms-wmv"); 

    } 


} 

回答

0

我已經嘗試了下面的代碼,它對我的​​工作很好。只在事件中添加代碼。

public sealed partial class MainPage : Page 
{ 
    MediaCapture mediaCapture; 
    IRandomAccessStream randomAccessStream; 
    public MainPage() 
    { 
     this.InitializeComponent(); 

     mediaCapture = new MediaCapture(); 
     randomAccessStream = new InMemoryRandomAccessStream(); 
    } 

    /// <summary> 
    /// Invoked when this page is about to be displayed in a Frame. 
    /// </summary> 
    /// <param name="e">Event data that describes how this page was reached. The Parameter 
    /// property is typically used to configure the page.</param> 
    protected override void OnNavigatedTo(NavigationEventArgs e) 
    { 
    } 

    private async void StartButton_Click(object sender, RoutedEventArgs e) 
    { 
     await mediaCapture.InitializeAsync(); 

     MediaEncodingProfile profile = MediaEncodingProfile.CreateWmv(VideoEncodingQuality.Auto); 
     await mediaCapture.StartRecordToStreamAsync(profile, randomAccessStream); 
    } 

    private async void StropButton_Click(object sender, RoutedEventArgs e) 
    { 
     await mediaCapture.StopRecordAsync(); 
     await randomAccessStream.FlushAsync(); 

     randomAccessStream.Seek(0); 

     // want to convert this randomAccessStream into byte[] 
     mediaElement.SetSource(randomAccessStream, "video/x-ms-wmv"); 
    } 
} 
相關問題