gpt4 book ai didi

c# - Windows Phone 8.1 中的录像机应用程序

转载 作者:太空宇宙 更新时间:2023-11-03 10:32:16 24 4
gpt4 key购买 nike

我打算在 Windows Phone 8.1 (RT) 中编写一个Video Recorder 应用

我使用了 Windows 引用中提供的示例

 public sealed partial class CamcorderMainPage : Page
{
StatusBar StatusBarObject = Windows.UI.ViewManagement.StatusBar.GetForCurrentView();
string StatusBarHeader = "Firefly Moments";
MediaCaptureInitializationSettings _captureInitSettings;
List<Windows.Devices.Enumeration.DeviceInformation> _deviceList;
Windows.Media.MediaProperties.MediaEncodingProfile _profile;
Windows.Media.Capture.MediaCapture _mediaCapture;
bool _recording = false;
bool _previewing = false;
string NoCameraError = "No camera device is found ";

public CamcorderMainPage()
{
this.InitializeComponent();
this.Loaded += CamcorderMainPage_Loaded;
}

void CamcorderMainPage_Loaded(object sender, RoutedEventArgs e)
{
//throw new NotImplementedException();
EnumerateCameras();
}


private async void EnumerateCameras()
{
var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(
Windows.Devices.Enumeration.DeviceClass.VideoCapture);

_deviceList = new List<Windows.Devices.Enumeration.DeviceInformation>();

// Add the devices to deviceList
if (devices.Count > 0)
{

for (var i = 0; i < devices.Count; i++)
{
_deviceList.Add(devices[i]);
}

InitCaptureSettings();
InitMediaCapture();
// rootPage.NotifyUser("Initialization complete.", NotifyType.StatusMessage);

}
else
{
StatusBarObject.ProgressIndicator.Text = NoCameraError;
//rootPage.NotifyUser("No camera device is found ", NotifyType.ErrorMessage);
}
}


private void InitCaptureSettings()
{
_captureInitSettings = null;
_captureInitSettings = new Windows.Media.Capture.MediaCaptureInitializationSettings();
_captureInitSettings.AudioDeviceId = "";
_captureInitSettings.VideoDeviceId = "";
_captureInitSettings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.AudioAndVideo;
_captureInitSettings.PhotoCaptureSource = Windows.Media.Capture.PhotoCaptureSource.VideoPreview;

if (_deviceList.Count > 0)
_captureInitSettings.VideoDeviceId = _deviceList[0].Id;
}

// Create a profile.
private void CreateProfile()
{
_profile = Windows.Media.MediaProperties.MediaEncodingProfile.CreateMp4(
Windows.Media.MediaProperties.VideoEncodingQuality.Qvga);
}

// Create and initialze the MediaCapture object.
public async void InitMediaCapture()
{
_mediaCapture = null;
_mediaCapture = new Windows.Media.Capture.MediaCapture();

// Set the MediaCapture to a variable in App.xaml.cs to handle suspension.
(App.Current as App).MediaCapture = _mediaCapture;

await _mediaCapture.InitializeAsync(_captureInitSettings);

CreateProfile();
}

// Start the video capture.
private async void StartMediaCaptureSession()
{
var storageFile = await Windows.Storage.KnownFolders.VideosLibrary.CreateFileAsync(
"cameraCapture.mp4", Windows.Storage.CreationCollisionOption.GenerateUniqueName);

await _mediaCapture.StartRecordToStorageFileAsync(_profile, storageFile);
_recording = true;
}

// Stop the video capture.
private async void StopMediaCaptureSession()
{
await _mediaCapture.StopRecordAsync();
_recording = false;
(App.Current as App).IsRecording = false;
}


private async void ShowFireFlyStatusBar()
{
//this will show the Status Bar


Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().SetDesiredBoundsMode(ApplicationViewBoundsMode.UseVisible);
StatusBarObject.ProgressIndicator.Text = StatusBarHeader;
StatusBarObject.ProgressIndicator.ProgressValue = 0;

StatusBarObject.ForegroundColor = Colors.MintCream;
StatusBarObject.BackgroundColor = Color.FromArgb(255, 166, 62, 59);
StatusBarObject.BackgroundOpacity = .6;
await StatusBarObject.ProgressIndicator.ShowAsync();


}

/// <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.
/// This parameter is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
ShowFireFlyStatusBar();
}

private void Camcorder_StartCapture_Click(object sender, RoutedEventArgs e)
{
StartMediaCaptureSession();
}

private void Camcorder_StopCapture_Click(object sender, RoutedEventArgs e)
{
StopMediaCaptureSession();
}
}

它工作正常,因为我正在从照片应用程序获取视频文件。

现在如何在应用程序中录制时启用实时预览?使用哪个控件?

最佳答案

您正在寻找 CaptureElement .将其添加到 XAML 后,将其连接到 MediaCapture 对象并开始预览,如下所示:

PreviewControl.Source = _mediaCapture;
await _mediaCapture.StartPreviewAsync();

看看 UniversalCameraSample发布在 Microsoft github 页面上以获取更多信息。它针对 Windows 10,但大多数模式也应该适用于 8/8.1。

关于c# - Windows Phone 8.1 中的录像机应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29598357/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com