本文整理汇总了C#中Windows.Media.Capture.MediaCapture.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# MediaCapture.Dispose方法的具体用法?C# MediaCapture.Dispose怎么用?C# MediaCapture.Dispose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Media.Capture.MediaCapture
的用法示例。
在下文中一共展示了MediaCapture.Dispose方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StartAsync
public async Task<RecordingToken> StartAsync()
{
var capture = new MediaCapture();
var initSettings = new MediaCaptureInitializationSettings();
initSettings.StreamingCaptureMode = StreamingCaptureMode.Audio;
await capture.InitializeAsync(initSettings);
var fileName = DateTimeOffset.Now.TimeOfDay.ToString().Replace(':', '_') + ".wav";
var file = await ApplicationData.Current.LocalFolder.CreateFileAsync(fileName);
var profile = MediaEncodingProfile.CreateWav(AudioEncodingQuality.Medium);
await capture.StartRecordToStorageFileAsync(profile, file);
return new RecordingToken(file.Path, async () =>
{
await capture.StopRecordAsync();
// It's important to dispose the capture device here to avoid application crash when using FileSavePicker afterwards
capture.Dispose();
});
}
示例2: DisposeCaptureAsync
// Must be called on the UI thread
private async Task DisposeCaptureAsync()
{
Preview.Source = null;
if (autoFocus != null)
{
autoFocus.Dispose();
autoFocus = null;
}
MediaCapture mediaCapture;
lock (this)
{
mediaCapture = this.mediaCapture;
this.mediaCapture = null;
}
if (mediaCapture != null)
{
mediaCapture.Failed -= OnMediaCaptureFailed;
await mediaCapture.StopPreviewAsync();
mediaCapture.Dispose();
}
}
示例3: IsMicrophoneAvailable
private async Task<bool> IsMicrophoneAvailable()
{
// Error messages from: https://msdn.microsoft.com/en-us/library/windows/apps/hh768223.aspx#additional_usage_guidance
try
{
// We do this initialization (and tear down immediately after) just to check if we have access to a microphone.
// We'll do the actual work with NAudio, since MediaCapture doesn't supply raw PCM data that we need.
var mediaCapture = new MediaCapture();
await mediaCapture.InitializeAsync();
mediaCapture.Dispose();
return true;
}
catch (UnauthorizedAccessException)
{
RaiseMicrophoneIsNotAvailable(
"Your microphone is currently turned off. To change your microphone setting, open the settings charm and tap permissions. " +
"Then tap the mute button to start using microphone again.");
return false;
}
catch (Exception)
{
RaiseMicrophoneIsNotAvailable(
"You do not have the required microphone present on your system.");
return false;
}
}
示例4: Capture_Click
public async void Capture_Click(object sender, RoutedEventArgs e)
{
MediaCapture mediaCapture = new MediaCapture();
await mediaCapture.InitializeAsync();
if (mediaCapture.VideoDeviceController.LowLagPhotoSequence.Supported)
{
mediaCapture.Dispose();
Frame.Navigate(typeof(SequenceCapturePage));
}
else
{
mediaCapture.Dispose();
Frame.Navigate(typeof(VideoPreviewCapturePage));
}
}