本文整理汇总了C#中Windows.Media.Capture.MediaCapture.StartRecordToStreamAsync方法的典型用法代码示例。如果您正苦于以下问题:C# MediaCapture.StartRecordToStreamAsync方法的具体用法?C# MediaCapture.StartRecordToStreamAsync怎么用?C# MediaCapture.StartRecordToStreamAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Media.Capture.MediaCapture
的用法示例。
在下文中一共展示了MediaCapture.StartRecordToStreamAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Grid_Loaded
private async void Grid_Loaded(object sender, RoutedEventArgs e)
{
var camera = (await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture)).FirstOrDefault();
if (camera != null)
{
mediaCapture = new MediaCapture();
var settings = new MediaCaptureInitializationSettings() { VideoDeviceId = camera.Id };
await mediaCapture.InitializeAsync(settings);
displayRequest.RequestActive();
VideoPreview.Source = mediaCapture;
await mediaCapture.StartPreviewAsync();
memStream = new InMemoryRandomAccessStream();
MediaEncodingProfile mediaEncodingProfile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto);
await mediaCapture.StartRecordToStreamAsync(mediaEncodingProfile, memStream);
}
//video = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Video);
//if (video!=null)
//{
// MediaClip mediaClip = await MediaClip.CreateFromFileAsync(video);
// mediaComposition.Clips.Add(mediaClip);
// mediaStreamSource = mediaComposition.GeneratePreviewMediaStreamSource(600, 600);
// VideoPreview.SetMediaStreamSource(mediaStreamSource);
//}
//FFMPEGHelper.RTMPEncoder encoder = new FFMPEGHelper.RTMPEncoder();
//encoder.Initialize("rtmp://youtube.co");
}
示例2: OnNavigatedTo
protected override async void OnNavigatedTo(Windows.UI.Xaml.Navigation.NavigationEventArgs e)
{
media = new MediaCapture();
var captureInitSettings = new MediaCaptureInitializationSettings();
captureInitSettings.StreamingCaptureMode = StreamingCaptureMode.Audio;
await media.InitializeAsync(captureInitSettings);
media.Failed += (_, ex) => new MessageDialog(ex.Message).ShowAsync();
media.RecordLimitationExceeded += (_) => new MessageDialog("record limit exceeded").ShowAsync();
var stream = new AudioAmplitudeStream();
media.StartRecordToStreamAsync(MediaEncodingProfile.CreateWav(AudioEncodingQuality.Low), stream);
stream.AmplitudeReading += stream_AmplitudeReading;
base.OnNavigatedTo(e);
}
示例3: PrintMicrophoneSample
public void PrintMicrophoneSample()
{
MediaCapture capture;
IRandomAccessStream stream;
const int BufferSize = 64000;
bool recording;
float volume = 100;
capture = new MediaCapture();
stream = new InMemoryRandomAccessStream();
var captureInitSettings2 = new MediaCaptureInitializationSettings();
captureInitSettings2.StreamingCaptureMode = StreamingCaptureMode.Audio;
capture.InitializeAsync(captureInitSettings2).AsTask().Wait();
capture.AudioDeviceController.VolumePercent = volume;
MediaEncodingProfile profile = new MediaEncodingProfile();
AudioEncodingProperties audioProperties = AudioEncodingProperties.CreatePcm(16000, 1, 16);
profile.Audio = audioProperties;
profile.Video = null;
profile.Container = new ContainerEncodingProperties() { Subtype = MediaEncodingSubtypes.Wave };
capture.StartRecordToStreamAsync(profile, stream).GetResults();
recording = true;
// waste time
for (int i = 0; i < 5; i++)
{
i = i * 232323 + 89;// WriteLine(i);
}
capture.StopRecordAsync().GetResults();
byte[] wav = new byte[stream.Size];
stream.Seek(0);
stream.ReadAsync(wav.AsBuffer(), (uint)stream.Size, InputStreamOptions.None).GetResults();
int sum = 0;
for(int i = 0; i < wav.Count(); i++)
{
sum += (int) wav[i];
}
WriteLine((double) wav.Count() / sum);
}