void ExposureDurationChanged (NSObservedChange obj)
{
var newValue = obj.NewValue;
var oldValue = obj.OldValue;
if (newValue != null && newValue != NSNull.Null) {
double newDurationSeconds = newValue.AsCMTime ().Seconds;
AVCaptureExposureMode exposureMode = VideoDevice.ExposureMode;
double minDurationSeconds = Math.Max (VideoDevice.ActiveFormat.MinExposureDuration.Seconds, ExposureMinDuration);
double maxDurationSeconds = VideoDevice.ActiveFormat.MaxExposureDuration.Seconds;
// Map from duration to non-linear UI range 0-1
double p = (newDurationSeconds - minDurationSeconds) / (maxDurationSeconds - minDurationSeconds); // Scale to 0-1
DispatchQueue.MainQueue.DispatchAsync (() => {
if (exposureMode != AVCaptureExposureMode.Custom)
ExposureDurationSlider.Value = (float)Math.Pow(p ,1 / ExposureDurationPower); // Apply inverse power
ExposureDurationValueLabel.Text = FormatDuration (newDurationSeconds);
});
}
}