我正在開發一個Windows Phone 8.1應用程序,它使用MediaCapture類來錄製視頻。我想讓用戶自由地通過旋轉設備來以縱向或水平方式錄製視頻。請注意我的應用有固定的縱向方向。由於固定方向,我使用SimpleOrientationSensor類的OrientationChanged事件。如何以縱向方向錄製視頻?
現在我已經注意到,在默認相機應用程序和我的應用程序中錄製的portait視頻有一些差異。您可以在下面給出的圖像中看到不同之處。所有的視頻都是720p分辨率。播放器圖像是肖像鎖定方向。代碼也在下面給出。任何人都可以解釋我的代碼記錄縱向視頻時出了什麼問題嗎?謝謝!
MediaCaptureInitializationSettings set;
MediaCapture _camCapture;
VideoRotation videoRotation = VideoRotation.None;
bool _isRecording = false;
// Camera resource disposal is handled properly
private async Task InitializeCamera()
{
try
{
if (set == null)
{
set = new MediaCaptureInitializationSettings();
DeviceInformation deviceID = (await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture))
.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back);
if (deviceID != null)
{
set.VideoDeviceId = deviceID.Id;
}
}
_camCapture = new MediaCapture();
await _camCapture.InitializeAsync(set);
VideoView.Source = _camCapture; //VideoView is CaptureElement object in XAML
_camCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
await _camCapture.StartPreviewAsync();
}
catch (Exception ex)
{
}
}
private async void OrientationChanged(object sender, SimpleOrientationSensorOrientationChangedEventArgs e)
{
try
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal,() =>
{
DetectCurrentOrintation(e.Orientation);
});
}
catch (Exception ex)
{
}
}
private void DetectCurrentOrintation(SimpleOrientation orientation)
{
try
{
switch (orientation)
{
case SimpleOrientation.NotRotated:
videoRotation = VideoRotation.Clockwise90Degrees;
break;
case SimpleOrientation.Rotated90DegreesCounterclockwise:
videoRotation = VideoRotation.None;
break;
case SimpleOrientation.Rotated180DegreesCounterclockwise:
videoRotation = VideoRotation.Clockwise270Degrees;
break;
case SimpleOrientation.Rotated270DegreesCounterclockwise:
videoRotation = VideoRotation.Clockwise180Degrees;
break;
default:
break;
}
}
catch (Exception ex)
{
}
}
private async void btnRecordVideo_Click(object sender, RoutedEventArgs e)
{
try
{
if (!_isRecording)
{
var _videoRecording = await MyFolderInLocalFolder.CreateFileAsync("testRecord.mp4", CreationCollisionOption.GenerateUniqueName);
MediaEncodingProfile mEncode = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto);
_isRecording = true;
//Two videos are with SetRecordRotation(value) and
//for two other I commeted out the line.
_camCapture.SetRecordRotation(videoRotation);
await _camCapture.StartRecordToStorageFileAsync(mEncode, _videoRecording);
}
else
{
await _camCapture.StopRecordAsync();
_isRecording = false;
}
}
catch (Exception ex)
{
}
}
問題與主要問題完全更新。 – Xyroid