J'essaie de mettre en place un flux de prévisualisation et une boucle d'enregistrement avec des boutons pour sauvegarder les 10 dernières minutes, 30 secondes, etc. Cela fonctionnait très bien jusqu'à ce que je commence à ajouter le code pour gérer la rotation.
C'est la ligne qui lance.
await _mediaCapture.SetEncodingPropertiesAsync(MediaStreamType.VideoPreview,
videoEncodingProperties, mediaPropertySet);
Voici la méthode complète
public async Task<MediaCapture> PrepareRecordingAsync() {
try {
_mediaCapture = new MediaCapture();
var allVideoDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
var desiredDevice = allVideoDevices.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == Panel.Back);
_cameraDevice = desiredDevice ?? allVideoDevices.FirstOrDefault();
_rotationHelper = new CameraRotationHelper(_cameraDevice.EnclosureLocation);
_mediaCapture.Failed += MediaCapture_Failed;
var settings = new MediaCaptureInitializationSettings { VideoDeviceId = _cameraDevice.Id };
await _mediaCapture.InitializeAsync(settings);
var encodingProfile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto);
var rotationAngle = CameraRotationHelper.ConvertSimpleOrientationToClockwiseDegrees(_rotationHelper.GetCameraCaptureOrientation());
Guid RotationKey = new Guid("C380465D-2271-428C-9B83-ECEA3B4A85C1");
encodingProfile.Video.Properties.Add(RotationKey, PropertyValue.CreateInt32(rotationAngle));
var videoEncodingProperties = _mediaCapture.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview);
MediaPropertySet mediaPropertySet = new MediaPropertySet();
await _mediaCapture.SetEncodingPropertiesAsync(MediaStreamType.VideoPreview, videoEncodingProperties, mediaPropertySet);
_ras = new InMemoryRandomAccessStream();
_recording = await _mediaCapture.PrepareLowLagRecordToStreamAsync(encodingProfile, _ras);
DisplayInformation.AutoRotationPreferences = DisplayOrientations.Portrait;
ConcurrentRecordAndPhotoSupported = _mediaCapture.MediaCaptureSettings.ConcurrentRecordAndPhotoSupported;
} catch (UnauthorizedAccessException) {
// This will be thrown if the user denied access to the camera in privacy settings
System.Diagnostics.Debug.WriteLine("The app was denied access to the camera");
} catch (Exception ex) {
System.Diagnostics.Debug.WriteLine("MediaCapture initialization failed. {0}", ex.Message);
}
return _mediaCapture;
}
Aucune des solutions trouvées via la recherche google n'est d'une quelconque aide.
Il s'agit essentiellement d'une modification des How-to's de MSDN.
EDIT : Si je remplace la ligne incriminée par la suivante, tout fonctionne bien.
_mediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);