Beispiel #1
0
        //void logo_PointerExited(object sender, PointerRoutedEventArgs e)
        //{
        //    logo.PointerExit();
        //}

        //void logo_PointerEntered(object sender, PointerRoutedEventArgs e)
        //{
        //    logo.PointerEnter();
        //}

        async void logo_Tapped(object sender, TappedRoutedEventArgs e)
        {
            if (!b)
            {
                //StartRecord();
                file = await folder.CreateFileAsync(DateTime.Now.ToString("yyyy-MM-dd hh-mm-ss") + ".mp3", CreationCollisionOption.GenerateUniqueName);

                await micphone.StartRecordToStorageFileAsync(MediaEncodingProfile.CreateMp3(AudioEncodingQuality.Auto), file);

                b = true;
                logo.StartFlash();
            }
            else
            {
                //StopRecord();
                await micphone.StopRecordAsync();

                var stream = await file.OpenAsync(FileAccessMode.Read);

                mediaElement.SetSource(stream, file.FileType);
                mediaElement.AutoPlay = false;
                b = false;
                logo.StopFlash();

                obs.Add(file.Name);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 'Start Video Record' button click action function
        /// Button name is changed to 'Stop Video Record' once recording is started
        /// Records video to a file in the default account videos folder
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void recordVideo_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                takePhoto.IsEnabled    = false;
                recordVideo.IsEnabled  = false;
                playbackElement.Source = null;

                if (recordVideo.Content.ToString() == "Start Video Record")
                {
                    status.Text = "Initialize video recording";
                    String fileName;
                    fileName = VIDEO_FILE_NAME;

                    recordStorageFile = await Windows.Storage.KnownFolders.VideosLibrary.CreateFileAsync(fileName, Windows.Storage.CreationCollisionOption.GenerateUniqueName);

                    status.Text = "Video storage file preparation successful";

                    MediaEncodingProfile recordProfile = null;
                    recordProfile = MediaEncodingProfile.CreateMp4(Windows.Media.MediaProperties.VideoEncodingQuality.Auto);

                    await mediaCapture.StartRecordToStorageFileAsync(recordProfile, recordStorageFile);

                    recordVideo.IsEnabled = true;
                    recordVideo.Content   = "Stop Video Record";
                    isRecording           = true;
                    status.Text           = "Video recording in progress... press \'Stop Video Record\' to stop";
                }
                else
                {
                    status.Text = "Stopping video recording...";
                    await mediaCapture.StopRecordAsync();

                    isRecording = false;

                    status.Text = "Playing recorded video" + recordStorageFile.Path;
                    var stream = await recordStorageFile.OpenReadAsync();

                    playbackElement.AutoPlay = true;
                    playbackElement.SetSource(stream, recordStorageFile.FileType);
                    playbackElement.Play();
                    recordVideo.Content = "Start Video Record";
                }
            }
            catch (Exception ex)
            {
                status.Text = ex.Message;
            }
            finally
            {
                takePhoto.IsEnabled   = true;
                recordVideo.IsEnabled = true;
            }
        }
Beispiel #3
0
        private async Task <MediaCapture> StartRecording(string fileName)
        {
            var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Devices.Enumeration.DeviceClass.VideoCapture);

            var camerDeviceId = devices.FirstOrDefault()?.Id;

            var captureSettings = new MediaCaptureInitializationSettings
            {
                VideoDeviceId        = camerDeviceId,
                AudioDeviceId        = string.Empty,
                PhotoCaptureSource   = PhotoCaptureSource.VideoPreview,
                StreamingCaptureMode = StreamingCaptureMode.Video
            };

            var mediaCapture = new MediaCapture();
            await mediaCapture.InitializeAsync(captureSettings);

            var def = new Windows.Media.Effects.VideoEffectDefinition(Windows.Media.VideoEffects.VideoStabilization);
            await mediaCapture.AddVideoEffectAsync(def, MediaStreamType.VideoRecord);

            var profile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Qvga);

            var storageFolder = await KnownFolders.RemovableDevices
                                .GetFolderAsync("E:\\");

            var storageFile = await storageFolder.CreateFileAsync(fileName, CreationCollisionOption.GenerateUniqueName);

            await mediaCapture.StartRecordToStorageFileAsync(profile, storageFile);

            return(mediaCapture);
        }
Beispiel #4
0
        private async void CaptureAudio()
        {
            try
            {
                String fileName = "AUDIO_FILE_NAME";

                _recordStorageFile = await KnownFolders.VideosLibrary.CreateFileAsync(fileName, CreationCollisionOption.GenerateUniqueName);

                MediaEncodingProfile recordProfile = MediaEncodingProfile.CreateM4a(AudioEncodingQuality.Medium);

                await _mediaCaptureManager.StartRecordToStorageFileAsync(recordProfile, this._recordStorageFile);

                DispatcherTimer dt = new DispatcherTimer();
                dt.Interval = new TimeSpan(0, 0, 3);
                dt.Tick    += delegate
                {
                    StopCapture();
                    dt.Stop();
                };
                dt.Start();
            }
            catch (Exception e)
            {
            }
        }
Beispiel #5
0
        private async void UpdateTorchStatus(bool isOn)
        {
            try
            {
                await InitTorchControl();
            }
            catch (Exception exception)
            {
                System.Diagnostics.Debug.WriteLine($"{nameof(UpdateTorchStatus)}: {exception.Message}");
            }

            if (!isOn && _torchControl.Enabled)
            {
                _torchControl.Enabled = false;
                _mediaCapture.Dispose();

                return;
            }

            if (isOn && !_torchControl.Enabled)
            {
                var videoEncodingProperties = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Vga);
                var videoStorageFile        = await ApplicationData.Current.TemporaryFolder.CreateFileAsync("temp.mp4", CreationCollisionOption.ReplaceExisting);

                await _mediaCapture.StartRecordToStorageFileAsync(videoEncodingProperties, videoStorageFile);

                _torchControl.Enabled = true;
            }
        }
Beispiel #6
0
        private async System.Threading.Tasks.Task StartRecordAsync()
        {
            try
            {
                IsRecording = true;
                //if camera does not support lowlag record and lowlag photo at the same time enable TakePhoto button after recording
                IsCaptureEnabled = m_mediaCapture.MediaCaptureSettings.ConcurrentRecordAndPhotoSupported;

                string fileName = "LumiaImagingVideo.mp4";

                var recordStorageFile = await KnownFolders.PicturesLibrary.CreateFileAsync(fileName, Windows.Storage.CreationCollisionOption.GenerateUniqueName);

                MediaEncodingProfile recordProfile = MediaEncodingProfile.CreateMp4(Windows.Media.MediaProperties.VideoEncodingQuality.Auto);

                // Calculate rotation angle, taking mirroring into account if necessary
                var rotationAngle = 360 - ConvertDeviceOrientationToDegrees(GetCameraOrientation());
                recordProfile.Video.Properties.Add(RotationKey, PropertyValue.CreateInt32(rotationAngle));

                Debug.WriteLine("Starting recording...");

                await m_mediaCapture.StartRecordToStorageFileAsync(recordProfile, recordStorageFile);
            }
            catch (Exception exception)
            {
                Debug.Assert(true, string.Format("Failed to start record video. {0}", exception.Message));
                IsRecording = false;
            }
        }
Beispiel #7
0
        private async void StartRecord()
        {
            if (BtnColVis)
            {
                LogoBack.Visibility             = Visibility.Visible;
                LogoBack.Opacity                = 1;
                LogoBackOpacitySmall.Visibility = Visibility.Visible;
                LogoBackOpacityBig.Visibility   = Visibility.Visible;
                Logo.Visibility     = Visibility.Collapsed;
                StopLogo.Visibility = Visibility.Visible;
                BtnColVis           = false;
                sb1.Begin();



                //开始录音
                //micphoneStorageFile = await KnownFolders.MusicLibrary.CreateFileAsync(DateTime.Now.ToString("yyyy-MM-dd hh-mm-ss") + ".mp3", CreationCollisionOption.GenerateUniqueName);
                //micphoneStorageFile = await KnownFolders.RemovableDevices.CreateFileAsync(DateTime.Now.ToString("yyyy-MM-dd hh-mm-ss") + ".mp3", CreationCollisionOption.GenerateUniqueName);
                StorageFolder folder2 = await KnownFolders.MusicLibrary.CreateFolderAsync(DateTime.Now.ToString("yyyy-MM-dd"), CreationCollisionOption.OpenIfExists);

                micphoneStorageFile = await folder2.CreateFileAsync(DateTime.Now.ToString("yyyy=MM=dd hh=mm=ss") + ".mp3", CreationCollisionOption.GenerateUniqueName);

                await micphone.StartRecordToStorageFileAsync(MediaEncodingProfile.CreateMp3(AudioEncodingQuality.Auto), this.micphoneStorageFile);
            }
        }
        /// <summary>
        /// Records an MP4 video to a StorageFile and adds rotation metadata to it
        /// </summary>
        /// <returns></returns>
        private async Task StartRecordingAsync()
        {
            try
            {
                // Create storage file in Pictures Library
                var videoFile = await _captureFolder.CreateFileAsync("SimpleVideo.mp4", CreationCollisionOption.GenerateUniqueName);

                var encodingProfile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto);

                // Calculate rotation angle, taking mirroring into account if necessary
                var rotationAngle = 360 - ConvertDeviceOrientationToDegrees(GetCameraOrientation());
                encodingProfile.Video.Properties.Add(RotationKey, PropertyValue.CreateInt32(rotationAngle));

                Debug.WriteLine("Starting recording to " + videoFile.Path);

                await _mediaCapture.StartRecordToStorageFileAsync(encodingProfile, videoFile);

                _isRecording = true;

                Debug.WriteLine("Started recording!");
            }
            catch (Exception ex)
            {
                // File I/O errors are reported as exceptions
                Debug.WriteLine("Exception when starting video recording: " + ex.ToString());
            }
        }
Beispiel #9
0
        public async Task StartMediaCaptureProcess()
        {
            //message += $"{Environment.NewLine}start process:";
            //txtBlock.Text = message;
            var sw = new Stopwatch();

            isRecording = true;
            while (isRecording)
            {
                sw.Start();
                fileName = GenerateFileName("mp4");
                var storageFile = await Windows.Storage.KnownFolders.VideosLibrary.CreateFileAsync(fileName, Windows.Storage.CreationCollisionOption.GenerateUniqueName);

                //message += $"{Environment.NewLine}start: {fileName}, ";
                //txtBlock.Text = message;
                await mediaCapture.StartRecordToStorageFileAsync(profile, storageFile);

                while (sw.Elapsed.TotalMilliseconds <= 60000)
                {
                    //delay between start recording and stop recording
                }
                //message += $"{Environment.NewLine}stop: {fileName}, ";
                //txtBlock.Text = message;
                IsPhoneDetected("");

                await mediaCapture.StopRecordAsync();

                sw.Reset();
            }
        }
Beispiel #10
0
        /// <summary>
        /// Start video recording
        /// </summary>
        /// <returns></returns>
        private async Task StartVideoRecordingAsync()
        {
            try
            {
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => PhotoButton.IsEnabled = false);

                if (_mediaCapture.MediaCaptureSettings.ConcurrentRecordAndPhotoSupported)
                {
                    ImageEncodingProperties imageEncodingProperties = ImageEncodingProperties.CreateJpeg();
                    _lowLagPhotoCapture = await _mediaCapture.PrepareLowLagPhotoCaptureAsync(imageEncodingProperties);

                    await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => PhotoButton.IsEnabled = true);
                }

                var mediaEncodingProfile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto);
                var folder = await KnownFolders.PicturesLibrary.CreateFolderAsync("Cam360", CreationCollisionOption.OpenIfExists);

                var file = await folder.CreateFileAsync("test.mp4", CreationCollisionOption.GenerateUniqueName);

                await _mediaCapture.StartRecordToStorageFileAsync(mediaEncodingProfile, file);
            }
            catch (Exception ex)
            {
                string errorMessage = string.Format("StartVideoRecording did not complete: {0}", ex.Message);
                Debug.Write(errorMessage);
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                {
                    await new MessageDialog(errorMessage).ShowAsync();
                });
            }
        }
        /// <summary>
        /// Records an MP4 video to a StorageFile and adds rotation metadata to it
        /// </summary>
        /// <returns></returns>
        private async Task StartRecordingAsync()
        {
            try
            {
                // Create storage file in Pictures Library
                var videoFile = await KnownFolders.PicturesLibrary.CreateFileAsync("SimpleVideo.mp4", CreationCollisionOption.GenerateUniqueName);

                // Calculate rotation angle, taking mirroring into account if necessary
                var rotationAngle = 360 - ConvertDeviceOrientationToDegrees(GetCameraOrientation());

                // Add it to the encoding profile, or edit the value if the GUID was already a part of the properties
                _encodingProfile.Video.Properties[RotationKey] = PropertyValue.CreateInt32(rotationAngle);

                Debug.WriteLine("Starting recording...");

                await _mediaCapture.StartRecordToStorageFileAsync(_encodingProfile, videoFile);

                _isRecording = true;

                Debug.WriteLine("Started recording to: " + videoFile.Path);
            }
            catch (Exception ex)
            {
                // File I/O errors are reported as exceptions
                Debug.WriteLine("Exception when starting video recording: {0}", ex.ToString());
            }
        }
Beispiel #12
0
        /// <summary>
        /// Records an MP4 video to a StorageFile and adds rotation metadata to it
        /// </summary>
        /// <returns></returns>
        private async Task StartRecordingAsync()
        {
            try
            {
                // Create storage file for the capture
                var videoFile = await localFolder.CreateFileAsync($"Video {DateTime.Now:D}.mp4", CreationCollisionOption.GenerateUniqueName);

                var encodingProfile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto);

                // Calculate rotation angle, taking mirroring into account if necessary
                var rotationAngle = CameraRotationHelper.ConvertSimpleOrientationToClockwiseDegrees(rotationHelper.GetCameraCaptureOrientation());
                encodingProfile?.Video?.Properties.Add(RotationKey, PropertyValue.CreateInt32(rotationAngle));

                Debug.WriteLine("Starting recording to " + videoFile.Path);

                await mediaCapture.StartRecordToStorageFileAsync(encodingProfile, videoFile);

                isRecording = true;

                Debug.WriteLine("Started recording!");
            }
            catch (Exception ex)
            {
                // File I/O errors are reported as exceptions
                Debug.WriteLine("Exception when starting video recording: " + ex.ToString());
            }
        }
        async private void ToggleRecordVideo(object sender, RoutedEventArgs e)
        {
            //initialize capture
            MediaCaptureInitializationSettings settings = new MediaCaptureInitializationSettings();

            settings.StreamingCaptureMode = StreamingCaptureMode.AudioAndVideo;
            _capture = new MediaCapture();
            await _capture.InitializeAsync(settings);

            //start preview
            capture_element.Source = _capture;
            await _capture.StartPreviewAsync();

            //start capturing media
            var profile         = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Vga);
            var feedback_folder = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFolderAsync("VideoFeedback", CreationCollisionOption.OpenIfExists);

            _target_file = await feedback_folder.CreateFileAsync("video message.mp4", CreationCollisionOption.GenerateUniqueName);

            await _capture.StartRecordToStorageFileAsync(profile, _target_file);

            //show the flyout menu
            media_message.Visibility = Visibility.Collapsed;
            media.Stop();  //stop playback since we are recording
            FlyoutBase.ShowAttachedFlyout(sender as FrameworkElement);
        }
Beispiel #14
0
        public async Task PlatformRecordAsync()
        {
            try
            {
                _mediaCapture = new MediaCapture();
                await _mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings { StreamingCaptureMode = StreamingCaptureMode.Audio });

                _mediaCapture.RecordLimitationExceeded += sender =>
                {
                    DeleteMediaCapture();
                    throw new Exception("Record Limitation Exceeded");
                };

                _mediaCapture.Failed += (sender, errorEventArgs) =>
                {
                    DeleteMediaCapture();
                    throw new Exception($"Audio recording failed: {errorEventArgs.Code}. {errorEventArgs.Message}");
                };

                _audioFilePath = Path.Combine(Kit.CachePath, Kit.NewGuid + ".m4a");
                var file = await StorageFile.GetFileFromPathAsync(_audioFilePath);

                await _mediaCapture.StartRecordToStorageFileAsync(MediaEncodingProfile.CreateM4a(AudioEncodingQuality.Auto), file);
            }
            catch
            {
                DeleteMediaCapture();
                throw;
            }
        }
        private async void ToggleRecording(object sender, RoutedEventArgs e)
        {
            if (VideoButton.IsChecked.Value)
            {
                CameraLabel.Text             = "wait for it...";
                Back.IsEnabled               = false;
                SwitchCameraButton.IsEnabled = false;
                CameraButton.IsEnabled       = false;
                VideoButton.IsEnabled        = false;
                var folder = await KnownFolders.VideosLibrary.CreateFolderAsync("NYLT Form Capture", CreationCollisionOption.OpenIfExists);

                var file = await folder.CreateFileAsync(applicant.FileName + ".mp4", CreationCollisionOption.ReplaceExisting);

                await mediaCapture.StartRecordToStorageFileAsync(MediaEncodingProfile.CreateMp4(VideoEncodingQuality.HD720p), file);

                CameraLabel.Foreground = new Windows.UI.Xaml.Media.SolidColorBrush(Colors.Red);
                CameraLabel.Text       = "recording";
                isRecording            = true;
                VideoButton.IsEnabled  = true;
            }
            else
            {
                CameraLabel.Foreground = new Windows.UI.Xaml.Media.SolidColorBrush(Colors.Black);
                CameraLabel.Text       = "saving";
                await mediaCapture.StopRecordAsync();

                isRecording                  = false;
                CameraLabel.Text             = "";
                SwitchCameraButton.IsEnabled = true;
                CameraButton.IsEnabled       = true;
                Back.IsEnabled               = true;
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private async Task startRecoding()
        {
            if (isPreview)
            {
                timer.Cancel();
                timer     = null;
                isPreview = false;
                await capture.StopPreviewAsync();

                //録画開始
                isRecording = true;

                videoFile = await KnownFolders.VideosLibrary.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);

                MediaEncodingProfile profile = null;
                profile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Qvga);

                await capture.StartRecordToStorageFileAsync(profile, videoFile);

                isRecording = true;

                Debug.WriteLine("Start Recording");

                //15秒後に録画停止
                recordingTimer = new Timer(stopRecording, null, 15000, 15000);
            }
        }
Beispiel #17
0
        private async void record_Click_1(object sender, RoutedEventArgs e)
        {
            try
            {
                _mediaCaptureManager = new MediaCapture();
                var settings = new MediaCaptureInitializationSettings();
                settings.StreamingCaptureMode = StreamingCaptureMode.Audio;//设置为音频
                await _mediaCaptureManager.InitializeAsync(settings);


                gridRecord.Visibility = Visibility.Visible;



                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());
            }
        }
        async Task <MethodResponse> startRecordingAsync(MethodRequest methodRequest, object userContext)
        {
            if (isRecording)
            {
                return(await Task.FromResult(new MethodResponse(Encoding.UTF8.GetBytes("Already Recording"), (int)HttpStatusCode.Conflict)));
            }
            if (!isInitialized)
            {
                await initializeCameraAsync();
            }

            isRecording = true;

            //If we want to have the mobile application set a title, we need to ge that here
            //var jsonData = methodRequest.DataAsJson;

            var storageFile = await Windows.Storage.KnownFolders.VideosLibrary.CreateFileAsync($"{DeviceInfo.Instance.Id}-{DateTime.UtcNow.Ticks}.wmv", Windows.Storage.CreationCollisionOption.GenerateUniqueName);

            recordedFileName = storageFile.Name;

            await mediaCapture.StartRecordToStorageFileAsync(profile, storageFile);

            await reportUpdatesAsync();

            return(await Task.FromResult(new MethodResponse(Encoding.UTF8.GetBytes("'Success'"), 200)));
        }
Beispiel #19
0
        private async void CaptureButton_Click(object sender, RoutedEventArgs e)
        {
            if (tbxCourseID.Text.Trim() == "" || tbxWeek.Text.Trim() == "")
            {
                await new MessageDialog("Please enter in a valid course ID and week number").ShowAsync();
            }
            else
            {
                try
                {
                    Random r = new Random();
                    CaptureButton.IsEnabled     = false;
                    CaptureButton.Content       = "Recording......";
                    StopCaptureButton.IsEnabled = true;
                    btnSave.IsEnabled           = false;
                    PlayRecordButton.IsEnabled  = false;
                    fileName = tbxCourseID.Text.Trim() + "Week" +
                               tbxWeek.Text.Trim() + "No" +
                               r.Next(1000, 9999).ToString() + ".m4a";
                    // Record audio
                    // Source: http://stackoverflow.com/questions/23048661/capture-and-playback-of-audio-wp8-1-xaml
                    _recordStorageFile = await KnownFolders.VideosLibrary.CreateFileAsync(fileName, CreationCollisionOption.GenerateUniqueName);

                    recordProfile = MediaEncodingProfile.CreateM4a(AudioEncodingQuality.Auto);
                    await _mediaCaptureManager.StartRecordToStorageFileAsync(recordProfile, this._recordStorageFile);

                    _recording = true;
                }
                catch (Exception ex)
                {
                    await new MessageDialog(ex.Message, "Error").ShowAsync();
                }
            }
        }
Beispiel #20
0
        // </SnippetInitMediaCapture>

        // <SnippetStartRecording>
        private async void StartRecording()
        {
            if (_mediaCapture == null)
            {
                return;
            }

            try
            {
                // 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
                await _mediaCapture.StartRecordToStorageFileAsync(profile, videoFile);

                _isRecording = true;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("StartRecording Exception: " + ex.Message);
            }
        }
Beispiel #21
0
        private async void recording()
        {
            try
            {
                ShowStatusMessage("Starting Record");
                String fileName;
                fileName = VIDEO_FILE_NAME;

                recordStorageFile = await KnownFolders.VideosLibrary.CreateFileAsync(fileName, CreationCollisionOption.GenerateUniqueName);

                ShowStatusMessage("Create record file successful");

                MediaEncodingProfile recordProfile = null;
                recordProfile = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto);

                await mediaCaptureMgr.StartRecordToStorageFileAsync(recordProfile, recordStorageFile);

                isRecording         = true;
                recordBtn.IsEnabled = true;
                recordBtn.Content   = "Stop Record";

                ShowStatusMessage("Start Record successful");
            }
            catch
            {
            }
        }
        private async void CaptureAudio()
        {
            try
            {
                Debug.WriteLine("Starting record");
                String fileName = "record.m4a";

                _recordStorageFile = await KnownFolders.VideosLibrary.CreateFileAsync(fileName, CreationCollisionOption.GenerateUniqueName);

                Debug.WriteLine("Create record file successfully");

                MediaEncodingProfile recordProfile = MediaEncodingProfile.CreateM4a(AudioEncodingQuality.Auto);


                await _mediaCaptureManager.StartRecordToStorageFileAsync(recordProfile, this._recordStorageFile);

                Debug.WriteLine("Start Record successful");

                _recording = true;
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
        }
Beispiel #23
0
 public async Task StartAsync()
 {
     {
         var mp3Profile = MediaEncodingProfile.CreateM4a(AudioEncodingQuality.Medium);
         await m_mediaCapture.StartRecordToStorageFileAsync(mp3Profile, m_file);
     }
 }
        async Task <MethodResponse> StartRecordingAsync(MethodRequest methodRequest, object userContext)
        {
            if (isRecording)
            {
                return(await Task.FromResult(new MethodResponse(Encoding.UTF8.GetBytes("Already Recording"), (int)HttpStatusCode.Conflict)).ConfigureAwait(false));
            }

            if (!isInitialized)
            {
                await InitializeCameraAsync().ConfigureAwait(false);
            }

            var filename = methodRequest?.DataAsJson;

            if (string.IsNullOrWhiteSpace(filename))
            {
                recordedFileName = "No name provided";
            }
            else
            {
                recordedFileName = filename;
            }

            isRecording = true;

            var storageFile = await KnownFolders.VideosLibrary.CreateFileAsync($"{DeviceInfo.Instance.Id}-{DateTime.UtcNow.Ticks}.mp4", CreationCollisionOption.GenerateUniqueName);

            recordedFileStorageName = storageFile.Name;

            await mediaCapture.StartRecordToStorageFileAsync(profile, storageFile);

            await ReportUpdatesAsync().ConfigureAwait(false);

            return(await Task.FromResult(new MethodResponse(Encoding.UTF8.GetBytes("'Success'"), 200)).ConfigureAwait(false));
        }
Beispiel #25
0
        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;
        }
Beispiel #26
0
        //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);
            }
        }
Beispiel #27
0
        private async void btnVideo_Click(object sender, RoutedEventArgs e)
        {
            MediaEncodingProfile video = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.HD720p);

            StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync("Video.mp4", CreationCollisionOption.ReplaceExisting);

            await takePhotoManager.StartRecordToStorageFileAsync(video, file);
        }
        private async void StartRecord()
        {
            if (BtnColVis)
            {
                LogoBack.Visibility             = Visibility.Visible;
                LogoBack.Opacity                = 1;
                LogoBackOpacitySmall.Visibility = Visibility.Visible;
                LogoBackOpacityBig.Visibility   = Visibility.Visible;
                Logo.Visibility     = Visibility.Collapsed;
                StopLogo.Visibility = Visibility.Visible;
                BtnColVis           = false;
                sb1.Begin();



                //开始录音

                //StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(Package.Current.InstalledLocation.Path + @"\AudioFile");

                //micphoneStorageFile = await folder.CreateFileAsync(DateTime.Now.ToString("yyyy-MM-dd hh-mm-ss") + ".mp3");

                StorageFolder folder2 = await KnownFolders.MusicLibrary.CreateFolderAsync(DateTime.Now.ToString("yyyy-MM-dd"), CreationCollisionOption.OpenIfExists);

                micphoneStorageFile = await folder2.CreateFileAsync(DateTime.Now.ToString("yyyy=MM=dd hh=mm=ss") + ".mp3", CreationCollisionOption.GenerateUniqueName);

                await micphone.StartRecordToStorageFileAsync(MediaEncodingProfile.CreateMp3(AudioEncodingQuality.Auto), this.micphoneStorageFile);
            }
            else
            {
                LogoBack.Visibility             = Visibility.Collapsed;
                LogoBack.Opacity                = 0.4;
                LogoBackOpacitySmall.Visibility = Visibility.Collapsed;
                LogoBackOpacityBig.Visibility   = Visibility.Collapsed;
                Logo.Visibility     = Visibility.Visible;
                StopLogo.Visibility = Visibility.Collapsed;
                BtnColVis           = true;
                sb1.Stop();
                micPlay.Stop();



                //停止录音
                await micphone.StopRecordAsync();

                var stream = await micphoneStorageFile.OpenAsync(FileAccessMode.Read);

                micPlay.SetSource(stream, this.micphoneStorageFile.FileType);



                obs.Add(micphoneStorageFile.Name);
                listView.ItemsSource = obs;
                //    lists.Add(micphoneStorageFile.Name );
                //    allAudio.List = new List<Audio>();
                //    allAudio.List.Add(new Audio() { FileName = micphoneStorageFile.Name });
                //    listView.ItemsSource = allAudio.List;
            }
        }
Beispiel #29
0
        private async void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            args.Cancel            = true;
            ppButton.Tag           = "pl";
            smbl.Symbol            = Symbol.Play;
            ppButton.IsEnabled     = false;
            acceptButton.IsEnabled = false;
            if (PrimaryButtonText.First() == dlgRecord.First())
            {
                display.Text    = 0.ToString();
                slide.IsEnabled = false;
                slide.Maximum   = 600;
                slide.Value     = 0;
                MediaCaptureInitializationSettings settings = new MediaCaptureInitializationSettings
                {
                    StreamingCaptureMode = StreamingCaptureMode.Audio
                };
                _capture = new MediaCapture();
                try
                {
                    await _capture.InitializeAsync(settings);
                }
                catch
                {
                    await(new MessageDialog(dlgFailed)).ShowAsync();
                    return;
                }
                var profile = MediaEncodingProfile.CreateM4a(AudioEncodingQuality.High);
                _track = await ApplicationData.Current.TemporaryFolder.CreateFileAsync(
                    _tempFile, CreationCollisionOption.ReplaceExisting);

                _time_started = DateTime.Now;
                _timer.Start();
                try
                {
                    await _capture.StartRecordToStorageFileAsync(profile, _track);
                }
                catch (Exception ex)
                {
                    await(new MessageDialog(ex.Message)).ShowAsync();
                }
                PrimaryButtonText = dlgStop;
            }
            else
            {
                await _capture.StopRecordAsync();

                _timer.Stop();
                var mediaSource = MediaSource.CreateFromStorageFile(_track);
                mediaSource.OpenOperationCompleted += MediaSource_OpenOperationCompleted;
                (_player.Source as MediaSource)?.Dispose();
                _player.Source         = mediaSource;
                PrimaryButtonText      = dlgRecord;
                ppButton.IsEnabled     = true;
                acceptButton.IsEnabled = true;
            }
        }
Beispiel #30
0
        /// <summary>
        /// Start recording. Set audio file path (soundFilePath) to Windows.Storage.KnownFolders.MusicLibrary
        /// </summary>
        private async void StartCapture()
        {
            recording = true;
            StorageFile storageFile = await Windows.Storage.KnownFolders.MusicLibrary.CreateFileAsync(
                soundFile, Windows.Storage.CreationCollisionOption.GenerateUniqueName);

            soundFilePath = storageFile.Path;
            await mediaCapture.StartRecordToStorageFileAsync(encodingProfile, storageFile);
        }