本文整理汇总了C#中Windows.Media.Capture.MediaCapture.StartRecordToStorageFileAsync方法的典型用法代码示例。如果您正苦于以下问题:C# MediaCapture.StartRecordToStorageFileAsync方法的具体用法?C# MediaCapture.StartRecordToStorageFileAsync怎么用?C# MediaCapture.StartRecordToStorageFileAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Media.Capture.MediaCapture
的用法示例。
在下文中一共展示了MediaCapture.StartRecordToStorageFileAsync方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btnRecord_Click
//Record the Screen
private async void btnRecord_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
if (btnRecord.IsChecked.HasValue && btnRecord.IsChecked.Value)
{
// Initialization - Set the current screen as input
var scrCaptre = ScreenCapture.GetForCurrentView();
mCap = new MediaCapture();
await mCap.InitializeAsync(new MediaCaptureInitializationSettings
{
VideoSource = scrCaptre.VideoSource,
AudioSource = scrCaptre.AudioSource,
});
// Start Recording to a File and set the Video Encoding Quality
var file = await GetScreenRecVdo();
await mCap.StartRecordToStorageFileAsync(MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto), file);
}
else
{
// Stop recording and start playback of the file
await StopRecording();
//If Media Element is taken on XAML
//var file = await GetScreenRecVdo(CreationCollisionOption.OpenIfExists);
//OutPutScreen.SetSource(await file.OpenReadAsync(), file.ContentType);
}
}
示例2: 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();
});
}
示例3: RecordSound
public async void RecordSound()
{
_recordMediaCapture = new MediaCapture();
var settings = new MediaCaptureInitializationSettings
{
StreamingCaptureMode = StreamingCaptureMode.Audio,
MediaCategory = MediaCategory.Other,
AudioProcessing = AudioProcessing.Default
};
await _recordMediaCapture.InitializeAsync(settings);
_url = string.Format("Sound_{0}.{1}", Guid.NewGuid(), "aac");
var path = Path.Combine(StorageService.SoundPath);
var folder = await StorageFolder.GetFolderFromPathAsync(path);
_recordStorageFile = await folder.CreateFileAsync(_url);
MediaEncodingProfile profil = MediaEncodingProfile.CreateM4a(AudioEncodingQuality.Auto);
await _recordMediaCapture.StartRecordToStorageFileAsync(profil, _recordStorageFile);
}
示例4: StartRecording
private async void StartRecording()
{
try
{
// Get instance of the ScreenCapture object
var screenCapture = Windows.Media.Capture.ScreenCapture.GetForCurrentView();
// Set the MediaCaptureInitializationSettings to use the ScreenCapture as the
// audio and video source.
var mcis = new Windows.Media.Capture.MediaCaptureInitializationSettings();
mcis.VideoSource = screenCapture.VideoSource;
mcis.AudioSource = screenCapture.AudioSource;
mcis.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.AudioAndVideo;
// Initialize the MediaCapture with the initialization settings.
_mediaCapture = new MediaCapture();
await _mediaCapture.InitializeAsync(mcis);
// Set the MediaCapture to a variable in App.xaml.cs to handle suspension.
(App.Current as App).MediaCapture = _mediaCapture;
// Hook up events for the Failed, RecordingLimitationExceeded, and SourceSuspensionChanged events
_mediaCapture.Failed += new Windows.Media.Capture.MediaCaptureFailedEventHandler(RecordingFailed);
_mediaCapture.RecordLimitationExceeded +=
new Windows.Media.Capture.RecordLimitationExceededEventHandler(RecordingReachedLimit);
screenCapture.SourceSuspensionChanged +=
new Windows.Foundation.TypedEventHandler<ScreenCapture, SourceSuspensionChangedEventArgs>(SourceSuspensionChanged);
// Create a file to record to.
var videoFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("recording.mp4", CreationCollisionOption.ReplaceExisting);
// Create an encoding profile to use.
var profile = Windows.Media.MediaProperties.MediaEncodingProfile.CreateMp4(Windows.Media.MediaProperties.VideoEncodingQuality.HD1080p);
// Start recording
var start_action = _mediaCapture.StartRecordToStorageFileAsync(profile, videoFile);
start_action.Completed += CompletedStart;
// Set a tracking variable for recording state in App.xaml.cs
(App.Current as App).IsRecording = true;
}
catch (Exception ex)
{
NotifyUser("StartRecord Exception: " + ex.Message, NotifyType.ErrorMessage);
}
}
示例5: StartMediaCaptureRecord_Click
private async void StartMediaCaptureRecord_Click(object sender, RoutedEventArgs e)
{
StartCaptureElementRecord.IsEnabled = false;
// Skip if no camera
var devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
if (devices.Count == 0)
{
return;
}
StorageFile destination = await KnownFolders.VideosLibrary.CreateFileAsync("VideoEffectsTestApp.MediaCapture.mp4", CreationCollisionOption.ReplaceExisting);
var capture = new MediaCapture();
await capture.InitializeAsync(new MediaCaptureInitializationSettings
{
StreamingCaptureMode = StreamingCaptureMode.Video
});
var definition = await CreateEffectDefinitionAsync(
(VideoEncodingProperties)capture.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoRecord)
);
await capture.AddEffectAsync(MediaStreamType.VideoRecord, definition.ActivatableClassId, definition.Properties);
await capture.StartRecordToStorageFileAsync(MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Qvga), destination);
await Task.Delay(3000);
await capture.StopRecordAsync();
StartCaptureElementRecord.IsEnabled = true;
}
示例6: record_Tapped
//录音初始化
private async void record_Tapped(object sender, TappedRoutedEventArgs e)
{
try
{
_mediaCaptureManager = new MediaCapture();
var settings = new MediaCaptureInitializationSettings();
settings.StreamingCaptureMode = StreamingCaptureMode.Audio;//设置为音频
await _mediaCaptureManager.InitializeAsync(settings);
gridRecord.Visibility = Visibility.Visible;
myChat.Visibility = Visibility.Collapsed;
record.IsTapEnabled = false;
storyboard.Begin();
String fileName = "1.aac";
_recordStorageFile = await KnownFolders.MusicLibrary.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
MediaEncodingProfile recordProfile = MediaEncodingProfile.CreateM4a(AudioEncodingQuality.Auto);//录音
await _mediaCaptureManager.StartRecordToStorageFileAsync(recordProfile, this._recordStorageFile);//将录音保存到视频库
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message.ToString());
}
}
示例7: Initialize
private async void Initialize()
{
try
{
var mediaCapture = new MediaCapture();
await mediaCapture.InitializeAsync();
var file = await ApplicationData.Current.LocalFolder.CreateFileAsync(Guid.NewGuid() + ".mp4",
CreationCollisionOption.ReplaceExisting);
await mediaCapture.StartRecordToStorageFileAsync(MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Wvga), file);
var videoDev = mediaCapture.VideoDeviceController;
videoDev.TorchControl.Enabled = true;
_torchControl = videoDev.TorchControl;
TorchSupported = _torchControl.Supported;
TorchPowerSupported = _torchControl.PowerSupported;
if (TorchPowerSupported)
_torchControl.PowerPercent = PercentValue;
if (TorchSupported)
_torchControl.Enabled = IsOn;
_isInitialized = true;
_toggleTorchCommand.RaiseCanExecuteChanged();
}
catch (Exception ex)
{
ErrorMessage = "Etwas unerwartetes ist passiert. Entschuldige!";
}
}