Windows10 IoT Core:視頻錄制移動(dòng)應(yīng)用程序
windows10 IoT Core的視頻錄制移動(dòng)應(yīng)用程序,是一個(gè)展示如何在windows10 IoT Core上創(chuàng)建視頻捕獲移動(dòng)應(yīng)用程序的實(shí)例,同時(shí)也支持在拍攝過(guò)程中預(yù)覽視頻。
需求組件:
1個(gè)USB攝像頭
1個(gè)USB鼠標(biāo)
1個(gè)HDMI顯示器和HDMI線
1個(gè)樹(shù)莓派2開(kāi)發(fā)板
建立示例移動(dòng)應(yīng)用程序:
連接USB攝像頭,USB鼠標(biāo),HDMI顯示器,以太網(wǎng)電纜(或者WiFi無(wú)線網(wǎng)絡(luò))到樹(shù)莓派2,然后打開(kāi)它
下載示例,構(gòu)建并部署到樹(shù)莓派2上
查看如何在樹(shù)莓派2上運(yùn)行
移動(dòng)應(yīng)用程序建立核心步驟:
1、 打開(kāi)VS2015,創(chuàng)建一個(gè)新的Windows通用空白應(yīng)用程序:
2、啟用package.appxmanifest功能,確保麥克風(fēng)和視頻庫(kù)(用于保存音頻文件)以及網(wǎng)絡(luò)攝像頭功能被選中:
在MainPage.xaml中,添加按鈕“開(kāi)始捕捉”,“結(jié)束捕捉”,“播放拍攝的視頻”,增加一個(gè)“捕捉元件”用于視頻預(yù)覽和一個(gè)“媒體元件”用于視頻播放
<Button x:Name="btn1" Content="Start Capturing" Click="startCapture" Margin="10,50,0,0"></Button> <Button x:Name="btn2" Content="End Capturing" Click="stopCapture" Margin="10, 20,0,0"/> <Button x:Name="btn3" Content="Play Captured Video" Click="playVideo" Margin="10, 20, 0,20"/> <TextBox Text="Video Preview Window:" Margin="10,10,0,5" TextAlignment="Center" BorderThickness="0"/> <CaptureElement Name="capturePreview" Height="300" Margin="10,10,0,10" Width="300"/> <TextBox Text="Video Review Window" Margin="10,10,0,5" TextAlignment="Center" BorderThickness="0"/> <MediaElement Name="media" AutoPlay="True" AreTransportControlsEnabled="False" Height="300" Width="300" Margin="10,10,0,10" > </MediaElement>
在MainPage.xaml.cs中,你將需要枚舉找到錄像機(jī)設(shè)備:
var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Devices.Enumeration.DeviceClass.VideoCapture);
設(shè)置“捕獲設(shè)置”:
captureInitSettings = new Windows.Media.Capture.MediaCaptureInitializationSettings();captureInitSettings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.AudioAndVideo;captureInitSettings.PhotoCaptureSource = Windows.Media.Capture.PhotoCaptureSource.VideoPreview;
初始化“媒體捕捉”:
mediaCapture = new Windows.Media.Capture.MediaCapture();await mediaCapture.InitializeAsync(captureInitSettings);
創(chuàng)建文件:
profile = Windows.Media.MediaProperties.MediaEncodingProfile.CreateMp4(Windows.Media.MediaProperties.VideoEncodingQuality.Qvga);
開(kāi)始錄制:
var storageFile = await Windows.Storage.KnownFolders.VideosLibrary.CreateFileAsync("cameraCapture.wmv", Windows.Storage.CreationCollisionOption.GenerateUniqueName); await mediaCapture.StartRecordToStorageFileAsync(profile, storageFile);
也可以在拍攝過(guò)程中啟動(dòng)預(yù)覽:
// start the preview capturePreview.Source=mediaCapture; await mediaCapture.StartPreviewAsync();
停止錄制和預(yù)覽:
private async void StopMediaCaptureSession() { await mediaCapture.StopRecordAsync(); recording = false; (App.Current as App).IsRecording = false; //stop the preview await mediaCapture.StopPreviewAsync(); }
播放錄像:
private async void playVideo(object sender, RoutedEventArgs e) { Windows.Storage.StorageFile storageFile = await Windows.Storage.KnownFolders.VideosLibrary.GetFileAsync(fileName); var stream = await storageFile.OpenAsync(Windows.Storage.FileAccessMode.Read); // mediaControl is a MediaElement defined in XAML if (null != stream) { media.Visibility = Visibility.Visible; media.SetSource(stream, storageFile.ContentType); media.Play(); } }
最新教程 更多
-
Win10家庭版怎么修改默認(rèn)安裝路徑?Win10家庭版修改默認(rèn)安裝路徑的方法
-
Win10無(wú)法連續(xù)敲擊鍵盤(pán)怎么辦?Win10無(wú)法連續(xù)敲擊鍵盤(pán)的解決方法
-
Win10玩不了warframe星際戰(zhàn)甲怎么辦?Win10玩不了warframe星際戰(zhàn)甲的解決方法
-
Win10系統(tǒng)如何徹底刪除360導(dǎo)航?Win10系統(tǒng)徹底刪除360導(dǎo)航的方法
-
Win10系統(tǒng)內(nèi)存完整性怎么關(guān)閉?Win10系統(tǒng)內(nèi)存完整性的關(guān)閉方法