StartRecordToStreamAsync() public méthode

public StartRecordToStreamAsync ( [ encodingProfile, [ stream ) : IAsyncAction
encodingProfile [
stream [
Résultat IAsyncAction
        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");
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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);
        }