private void RecordButton_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (!IsHitTestVisible)
            {
                return;
            }
            if (Component == null)
            {
                return;
            }
            if (_microphone == null)
            {
                return;
            }

            _fileId          = TLLong.Random();
            _fileName        = _fileId.Value + ".mp3";
            _isPartReady     = true;
            _uploadingLength = 0;
            _uploadableParts.Clear();

            _isSliding       = true;
            _stopRequested   = false;
            _cancelRequested = false;

            RaiseRecordStarted();

            Duration.Text         = "00:00";
            SliderTransform.X     = 0.0;
            Slider.Visibility     = Visibility.Visible;
            TimerPanel.Visibility = Visibility.Visible;
            Component.StartRecord(ApplicationData.Current.LocalFolder.Path + "\\" + _fileName);

            _stream    = new MemoryStream();
            _startTime = DateTime.Now;
            VibrateController.Default.Start(TimeSpan.FromMilliseconds(25));
            _asyncDispatcher.StartService(null);
            _microphone.Start();

            StartRecordingStoryboard.Begin();
        }
Exemplo n.º 2
0
        private void RecordButton_OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (!IsHitTestVisible)
            {
                return;
            }
            var microphoneState = _microphone != null ? _microphone.State : (MicrophoneState?)null;

            if (microphoneState == MicrophoneState.Started)
            {
                return;
            }
            if (_isHintStoryboardPlaying)
            {
                return;
            }

            Log(string.Format("microphone_state={0} storyboard_state={1}", microphoneState, _isHintStoryboardPlaying));

            if (Component == null)
            {
                return;
            }
            if (_asyncDispatcher == null)
            {
                _asyncDispatcher = new XnaAsyncDispatcher(TimeSpan.FromMilliseconds(33), OnTimerTick);
            }

            if (SliderPanel == null)
            {
                SliderPanel = CreateSliderPanel();
                LayoutRoot.Children.Add(SliderPanel);
            }
            if (TimerPanel == null)
            {
                TimerPanel = CreateTimerPanel();
                LayoutRoot.Children.Add(TimerPanel);
            }

            if (_microphone == null)
            {
                _microphone = Microphone.Default;

                ShellViewModel.WriteTimer("AudioRecorderControl ctor microphone");

                if (_microphone == null)
                {
                    RecordButton.Visibility = Visibility.Collapsed;
                    Visibility       = Visibility.Collapsed;
                    IsHitTestVisible = false;

                    return;
                }

                try
                {
                    _microphone.BufferDuration = TimeSpan.FromMilliseconds(240);
                    _duration = _microphone.BufferDuration;
                    _buffer   = new byte[_microphone.GetSampleSizeInBytes(_microphone.BufferDuration)];
                }
                catch (Exception ex)
                {
                    TLUtils.WriteException(ex);

                    RecordButton.Visibility = Visibility.Collapsed;
                    Visibility       = Visibility.Collapsed;
                    IsHitTestVisible = false;

                    return;
                }

                _microphone.BufferReady += Microphone_OnBufferReady;
            }

            _skipBuffersCount = 0;
            _fileId           = TLLong.Random();
            _fileName         = _fileId.Value + ".mp3";
            _isPartReady      = true;
            _uploadingLength  = 0;
            _uploadableParts.Clear();

            _isSliding       = true;
            _stopRequested   = false;
            _cancelRequested = false;

            RaiseRecordStarted();

            if (Duration != null)
            {
                Duration.Text = "00:00.00";
            }
            if (Slider != null)
            {
                ((TranslateTransform)Slider.RenderTransform).X = 0.0;
            }
            Component.StartRecord(ApplicationData.Current.LocalFolder.Path + "\\" + _fileName);

            _stream    = new MemoryStream();
            _startTime = DateTime.Now;
            VibrateController.Default.Start(TimeSpan.FromMilliseconds(25));

            Execute.BeginOnUIThread(TimeSpan.FromMilliseconds(25.0), () =>
            {
                if (!_isSliding)
                {
                    if (_stopRequested)
                    {
                        _stopRequested   = false;
                        _cancelRequested = false;

                        _isHintStoryboardPlaying = true;
                        HintStoryboard.Begin();
                        return;
                    }
                    Log("_isSliding=false return");
                    return;
                }

                if (Slider != null)
                {
                    Slider.Visibility = Visibility.Visible;
                }
                if (TimerPanel != null)
                {
                    TimerPanel.Visibility = Visibility.Visible;
                }

                _asyncDispatcher.StartService(null);
                _microphone.Start();

                StartRecordingStoryboard();
            });
        }