【问题标题】:video capture in metro app地铁应用程序中的视频捕获
【发布时间】:2013-09-28 11:59:48
【问题描述】:

我目前正在使用 Visual Studio Express for Windows 8 IDE 为 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");

     }


}

【问题讨论】:

    标签: c# microsoft-metro


    【解决方案1】:

    我已经尝试了下面的代码,它对我来说工作正常。仅在事件中添加代码。

    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");
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-08
      • 1970-01-01
      相关资源
      最近更新 更多