Exemplo n.º 1
0
        public void PrepareRecording()
        {
            try
            {
                if (File.Exists(m_oSaveRawPath))
                {
                    File.Delete(m_oSaveRawPath);
                }


                if (m_oRecorder == null)
                {
                    m_oRecorder = new MediaRecorder();
                }
                else
                {
                    m_oRecorder.Reset();
                }
                m_oRecorder.SetAudioSource(AudioSource.Mic);
                m_oRecorder.SetOutputFormat(OutputFormat.RawAmr);
                m_oRecorder.SetAudioEncoder(AudioEncoder.Default);
                m_oRecorder.SetMaxDuration(10000); // 10sec
                //m_oRecorder.SetAudioSamplingRate(44100);
                m_oRecorder.SetAudioEncodingBitRate(16);
                m_oRecorder.SetOutputFile(m_oSaveRawPath);
                m_oRecorder.Prepare();
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine("Error: " + ex.Message);
            }
        }
Exemplo n.º 2
0
        public void Record(string pathToAudioFile)
        {
            try
            {
                if (File.Exists(pathToAudioFile))
                {
                    File.Delete(pathToAudioFile);
                }
                if (recorder == null)
                {
                    recorder = new MediaRecorder(); // Initial state.
                }

                recorder.Reset();
                recorder.SetAudioSource(AudioSource.Mic);
                recorder.SetOutputFormat(OutputFormat.ThreeGpp);
                recorder.SetAudioEncoder(AudioEncoder.AmrNb);

                // Initialized state.
                recorder.SetOutputFile(pathToAudioFile);

                // DataSourceConfigured state.
                recorder.Prepare(); // Prepared state
                recorder.Start();   // Recording state.
            }
            catch (Exception ex)
            {
                Debug.Write(ex);
            }
        }
Exemplo n.º 3
0
        public bool PrepareRecord()
        {
            try
            {
                string fileName = $"Myfile{DateTime.Now.ToString("yyyyMMddHHmmss")}.wav";
                audioFilePath = Path.Combine(Path.GetTempPath(), fileName);
                if (recorder == null)
                {
                    recorder = new MediaRecorder();
                }
                else
                {
                    recorder.Reset();
                }

                Console.WriteLine("daeseong1");

                recorder.SetAudioSource(AudioSource.Mic);
                recorder.SetOutputFormat(OutputFormat.ThreeGpp);
                recorder.SetAudioEncoder(AudioEncoder.Aac);
                recorder.SetOutputFile(audioFilePath);
                recorder.Prepare();

                Console.WriteLine("daeseong2");

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 4
0
        public void StartRecording()
        {
            string fileName = $"Myfile{DateTime.Now.ToString("yyyyMMddHHmmss")}.mp4";

            audioFilePath = Path.Combine(Path.GetTempPath(), fileName);

            try
            {
                if (File.Exists(audioFilePath))
                {
                    File.Delete(audioFilePath);
                }

                if (recorder == null)
                {
                    recorder = new MediaRecorder();
                }

                recorder.Reset();
                recorder.SetAudioSource(AudioSource.Mic);
                recorder.SetOutputFormat(OutputFormat.Mpeg4);
                recorder.SetAudioEncoder(AudioEncoder.AmrNb);
                // Initialized state.
                recorder.SetOutputFile(audioFilePath);
                // DataSourceConfigured state.
                recorder.Prepare(); // Prepared state
                recorder.Start();   // Recording state.
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine(ex.StackTrace);
            }
        }
        public void StartRecord(string filename)
        {
            if (recorder != null)
            {
                recorder.Reset();
            }
            else
            {
                recorder = new MediaRecorder();
            }
            mCamera.Lock();
            mCamera.Unlock();

            recorder.SetCamera(mCamera);
            recorder.SetVideoSource(VideoSource.Camera);
            recorder.SetAudioSource(AudioSource.Camcorder);

            try
            {
                //try for full hd
                recorder.SetProfile(CamcorderProfile.Get(CURRENTCAMERA, CamcorderQuality.Q1080p));
            }
            catch
            {
                try
                {
                    recorder.SetProfile(CamcorderProfile.Get(CURRENTCAMERA, CamcorderQuality.Q720p));
                }
                catch
                {
                    try
                    {
                        //if not hd, try for highest phone can give
                        recorder.SetProfile(CamcorderProfile.Get(CURRENTCAMERA, CamcorderQuality.High));
                    }
                    catch
                    {
                        //if not, then set to low
                        recorder.SetProfile(CamcorderProfile.Get(CURRENTCAMERA, CamcorderQuality.Q480p));
                    }
                }
            }

            //recorder.SetAudioEncoder(AudioEncoder.Aac);
            //recorder.SetVideoEncoder(VideoEncoder.H264);
            recorder.SetPreviewDisplay(mPreview.Holder.Surface);
            recorder.SetOutputFile(filename);
            recorder.SetMaxDuration(1000 * 60 * 5);

            try
            {
                recorder.Prepare();
                recorder.Start();
            }
            catch (Exception e)
            {
                OnError?.Invoke(e.ToString());
            }
        }
Exemplo n.º 6
0
 public void stoprecorder()
 {
     // _stop.Enabled = !_stop.Enabled;
     _recorder.Stop();
     _recorder.Reset();
     _player.SetDataSource(filePath);
     _player.Prepare();
     _player.Start();
     //mikestop.Visibility = ViewStates.Invisible;
 }
        public void StartRecording()
        {
            try
            {
                if (System.IO.File.Exists(filePath))
                {
                    System.IO.File.Delete(filePath);
                }


                if (recorder == null)
                {
                    recorder = new MediaRecorder(); // Initial state.
                }
                else
                {
                    recorder.Reset();
                }

                recorder.SetAudioSource(AudioSource.Mic);
                recorder.SetOutputFormat(OutputFormat.Mpeg4);
                recorder.SetAudioEncoder(AudioEncoder.AmrNb); // Initialized state.
                recorder.SetOutputFile(filePath);             // DataSourceConfigured state.
                recorder.Prepare();                           // Prepared state
                recorder.Start();                             // Recording state.
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine(ex.StackTrace);
            }
        }
Exemplo n.º 8
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Main);

            _start = FindViewById <Button> (Resource.Id.start);
            _stop  = FindViewById <Button> (Resource.Id.stop);

            string path = "/sdcard/test.3gpp";

            _start.Click += delegate {
                _stop.Enabled  = !_stop.Enabled;
                _start.Enabled = !_start.Enabled;

                _recorder.SetAudioSource(AudioSource.Mic);
                _recorder.SetOutputFormat(OutputFormat.ThreeGpp);
                _recorder.SetAudioEncoder(AudioEncoder.AmrNb);
                _recorder.SetOutputFile(path);
                _recorder.Prepare();
                _recorder.Start();
            };

            _stop.Click += delegate {
                _stop.Enabled = !_stop.Enabled;

                _recorder.Stop();
                _recorder.Reset();

                _player.SetDataSource(path);
                _player.Prepare();
                _player.Start();
            };
        }
Exemplo n.º 9
0
        public void StopRecord()
        {
            if (_isRecording)
            {
                if (_textureView != null)
                {
                    _textureView.Visibility = ViewStates.Invisible;
                }
                // 録画終了
                _recorder.Stop();
                _recorder.Reset();
                _recorder.Release();
                _recorder = null;

                if (_linearLayout != null)
                {
                    ((ViewGroup)_linearLayout.Parent).RemoveView(_linearLayout);
                    _linearLayout.Dispose();
                    _linearLayout = null;
                }

                if (_listener != null)
                {
                    _listener.StopCamera2();
                    _listener.Dispose();
                    _listener = null;
                }

                _isRecording = false;
            }
        }
Exemplo n.º 10
0
 private void RecordButton_Tapped(object sender, EventArgs e)
 {
     if (!recordClicked)
     {
         if (recorder == null)
         {
             recorder = new MediaRecorder();
         }
         else
         {
             recorder.Reset();
         }
         recorder.SetAudioSource(AudioSource.Mic);
         recorder.SetOutputFormat(OutputFormat.Mpeg4);
         recorder.SetAudioEncoder(AudioEncoder.AmrNb);
         audioFilePath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + $"/{DateTime.Now.ToString("MM-dd-yyyy-HH;mm;ss")}.mp3";
         recorder.SetOutputFile(audioFilePath);
         recorder.Prepare();
         recorder.Start();
         RecordButton.Source = "stopbuttonimage.png";
         recordClicked       = true;
         Device.StartTimer(new TimeSpan(0, 0, 1), () => { time.Seconds++; timeLabel.Text = time.ToString(); return(recordClicked); });
     }
     else
     {
         StopRecording();
     }
 }
        public void StopRecording()
        {
            if (recorder == null)
            {
                return;
            }
            try
            {
                recorder.Stop();
                recorder.Reset();
                recorder.Release();

                if (timer != null && timer.Enabled)
                {
                    timer.Stop();
                }

                if (File.Exists(filePath))
                {
                    byte[] note = File.ReadAllBytes(filePath);
                    OnRecordingCompleted?.Invoke(note, null);
                }
            }
            catch (Exception ex)
            {
                EbLog.Error(ex.Message);
            }
        }
Exemplo n.º 12
0
        private void EnsureInitiazed()
        {
            if (Initialized)
            {
                return;
            }

            const string rec = Android.Content.PM.PackageManager.FeatureMicrophone;

            if (rec != "android.hardware.microphone")
            {
                throw new InvalidOperationException("You don't seem to have a microphone to record with");
            }
            try
            {
                recorder = new MediaRecorder();
                recorder.Reset();
                recorder.SetAudioSource(AudioSource.Mic);
                recorder.SetOutputFormat(OutputFormat.ThreeGpp);
                recorder.SetAudioEncoder(AudioEncoder.AmrNb);
                recorder.SetOutputFile(filePath);
                recorder.Prepare();

                // player = new MediaPlayer();
                Initialized = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Exemplo n.º 13
0
        public void StartRecorder()
        {
            try
            {
                //Java.IO.File sdDir = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryMusic);
                //filePath = sdDir + "/" + "testAudio.mp3";
                if (File.Exists(filename))
                {
                    File.Delete(filename);
                }

                //Java.IO.File myFile = new Java.IO.File(filePath);
                //myFile.CreateNewFile();

                if (recorder == null)
                {
                    recorder = new MediaRecorder(); // Initial state.
                }
                else
                {
                    recorder.Reset();
                }

                recorder.SetAudioSource(AudioSource.Mic);
                recorder.SetOutputFormat(OutputFormat.ThreeGpp);
                recorder.SetOutputFile(filename);             // DataSourceConfigured state.
                recorder.SetAudioEncoder(AudioEncoder.AmrNb); // Initialized state.
                recorder.Prepare();                           // Prepared state
                recorder.Start();                             // Recording state.
            }
            catch (Exception ex)
            {
                Console.Out.WriteLine(ex.StackTrace);
            }
        }
Exemplo n.º 14
0
 public void Start(string filePath)
 {
     try
     {
         if (File.Exists(filePath))
         {
             File.Delete(filePath);
         }
         if (recorder == null)
         {
             recorder = new MediaRecorder(); // Initial state.
         }
         recorder.Reset();
         recorder.SetAudioSource(AudioSource.Mic);
         recorder.SetOutputFormat(OutputFormat.Default);
         recorder.SetAudioEncoder(AudioEncoder.AmrNb);
         recorder.SetAudioChannels(1);
         recorder.SetAudioEncodingBitRate(96000);
         //recorder.SetAudioSamplingRate(44100);
         //recorder.SetAudioEncodingBitRate(48000);
         //recorder.SetAudioSamplingRate(22050);
         recorder.SetOutputFile(filePath);
         recorder.Prepare(); // Prepared state
         //recorder.SetMaxDuration(30000);
         recorder.Start();   // Recording state.
     }
     catch (Exception e)
     {
         HandleError.Process("RecordAudioService", "Start", e, false);
     }
 }
Exemplo n.º 15
0
        public void RecordingFunction(string Action, string Userid)
        {
            if (Action == "Start")
            {
                try
                {
                    var dir = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDcim);
                    SoundFile = GetTimestamp(DateTime.Now) + ".mp3";
                    var DirectoryPath =
                        new Java.IO.File(dir + "/" + WowonderPhone.Settings.ApplicationName + "/" + SoundFile);
                    if (!Directory.Exists(dir + "/" + WowonderPhone.Settings.ApplicationName))
                    {
                        Directory.CreateDirectory(dir + "/" + WowonderPhone.Settings.ApplicationName);
                    }

                    recorder = new MediaRecorder();
                    recorder.Reset();
                    recorder.SetAudioSource(AudioSource.Mic);
                    recorder.SetOutputFormat(OutputFormat.Default);
                    recorder.SetAudioEncoder(AudioEncoder.AmrNb);
                    recorder.SetOutputFile(DirectoryPath.AbsolutePath);
                    recorder.Prepare();
                    recorder.Start();
                }
                catch (Exception)
                {
                }
            }
            else
            {
                recorder.Stop();
                recorder.Release();
            }
        }
Exemplo n.º 16
0
        private void RecordBtn_Click(object sender, EventArgs e)
        {
            recording = !recording;

            if (recording)
            {
                // Start recording
                recorder.SetAudioSource(AudioSource.Mic);
                recorder.SetOutputFormat(OutputFormat.Mpeg4);
                recorder.SetAudioEncoder(AudioEncoder.Aac);
                recorder.SetAudioSamplingRate(44100);
                recorder.SetAudioEncodingBitRate(96000);
                recorder.SetOutputFile(filePath);
                recorder.Prepare();
                recorder.Start();

                recordBtn.Text = Resources.GetString(Resource.String.StopBtn);
                image.Alpha    = 1f;
                clockThread    = new Thread(UpdateClock);
                clockThread.Start();
            }
            else
            {
                // Stop recording
                recorder.Stop();
                recorder.Reset();

                recordBtn.Text = Resources.GetString(Resource.String.StartBtn);
                image.Alpha    = LowAlpha;
                clockThread.Join();

                PlaybackAcceptPopup();
            }
        }
Exemplo n.º 17
0
 public string StopRecord()
 {
     _recorder.Stop();
     _recorder.Reset();
     _recorder.Release();
     return(sFileName);
 }
Exemplo n.º 18
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Main);

            _start = FindViewById <Button> (Resource.Id.start);
            _stop  = FindViewById <Button> (Resource.Id.stop);

            string path = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/test.mp4";


            _start.Click += delegate {
                _stop.Enabled  = !_stop.Enabled;
                _start.Enabled = !_start.Enabled;

                _recorder.SetAudioSource(AudioSource.Mic);
                _recorder.SetOutputFormat(OutputFormat.ThreeGpp);
                _recorder.SetAudioEncoder(AudioEncoder.AmrNb);
                _recorder.SetOutputFile(path);
                _recorder.Prepare();
                _recorder.Start();
            };

            _stop.Click += delegate {
                _stop.Enabled = !_stop.Enabled;

                _recorder.Stop();
                _recorder.Reset();

                _player.SetDataSource(path);
                _player.Prepare();
                _player.Start();
            };
        }
Exemplo n.º 19
0
        public void StartRecorder()
        {
            try
            {
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                }

                if (recoder == null)
                {
                    recoder = new MediaRecorder();
                }
                else
                {
                    recoder.Reset();
                }

                recoder.SetAudioSource(AudioSource.Mic);
                recoder.SetOutputFormat(OutputFormat.Mpeg4);
                recoder.SetAudioEncoder(AudioEncoder.AmrNb);
                recoder.SetOutputFile(filePath);
                recoder.Prepare();
                recoder.Start();
            }catch (Exception ex)
            {
                Console.Out.WriteLine(ex.StackTrace);
            }
        }
Exemplo n.º 20
0
        public void StartRecorder()
        {
            try
            {
                var file = new Java.IO.File(filePath);
                file.CreateNewFile();

                if (recorder == null)
                {
                    recorder = new MediaRecorder();  // Initial state.
                }
                else
                {
                    recorder.Reset();
                }

                recorder.SetAudioSource(AudioSource.Mic);
                recorder.SetOutputFormat(OutputFormat.Default);
                recorder.SetAudioEncoder(AudioEncoder.Default); // Initialized state.
                recorder.SetOutputFile(filePath);               // DataSourceConfigured state.
                recorder.Prepare();                             // Prepared state
                recorder.Start();                               // Recording state.
            } catch (Exception ex) {
                Console.Out.WriteLine(ex.StackTrace);
            }
        }
 public void Stop()
 {
     if (_recorder != null && _isRecording)
     {
         _recorder.Stop();
         _recorder.Reset();
         _isRecording = false;
     }
 }
Exemplo n.º 22
0
 void StopRecording()
 {
     if (_isrecording)
     {
         _isrecording = false;
         _recorder.Stop();
         _recorder.Reset();
         LOG_EVENT("STOP_RECORDING");
     }
 }
Exemplo n.º 23
0
        public Task <AudioRecording> StopAsync()
        {
            if (isRecording)
            {
                mediaRecorder.Stop();
                mediaRecorder.Reset();
            }

            return(Task.FromResult(GetRecording()));
        }
Exemplo n.º 24
0
 private void releaseMediaRecorder()
 {
     if (mediaRecorder != null)
     {
         mediaRecorder.Reset();
         mediaRecorder.Release();
         mediaRecorder = null;
         camera.Lock();
     }
 }
Exemplo n.º 25
0
 //LIBERAMOS LOS RECURSOS DE NUESTRO MEDIARECORDER
 private void LiberarMediaRecorder()
 {
     if (_mediaRecorder == null)
     {
         return;
     }
     _mediaRecorder.Reset();
     _mediaRecorder.Release();
     _mediaRecorder.Dispose();
     _mediaRecorder = null;
     _camera.Lock();
 }
Exemplo n.º 26
0
        private void ReleaseMediaRecorder()
        {
            if (mediaRecorder == null)
            {
                return;
            }

            mediaRecorder.Reset();
            mediaRecorder.Release();
            mediaRecorder = null;
            camera.Lock();
        }
Exemplo n.º 27
0
        public async Task <bool> StartRecording()
        {
            recorder.Reset();
            recorder.SetAudioSource(AudioSource.VoiceCall);
            recorder.SetOutputFormat(OutputFormat.ThreeGpp);
            recorder.SetAudioEncoder(AudioEncoder.Aac);
            recorder.SetOutputFile("/sdcard/Download/123.3gpp");
            recorder.Prepare();
            recorder.Start();

            return(true);
        }
Exemplo n.º 28
0
 public void Record()
 {
     CheckForPermissions();
     _mediaRecorder = new MediaRecorder();
     _mediaRecorder.Reset();
     _mediaRecorder.SetAudioSource(AudioSource.Mic);
     _mediaRecorder.SetOutputFormat(OutputFormat.Mpeg2Ts);
     _mediaRecorder.SetOutputFile(GetFileName());
     _mediaRecorder.SetAudioEncoder(AudioEncoder.Aac);
     _mediaRecorder.Prepare();
     _mediaRecorder.Start();
 }
Exemplo n.º 29
0
        public void stopRecord()
        {
            if (recorder == null)
            {
                return;
            }

            recorder.Stop();
            recorder.Reset();
            recorder.Release();
            recorder = null;
        }
Exemplo n.º 30
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.criticaGUI);
            TextView nomeRestaurante = FindViewById <TextView>(Resource.Id.textView3);
            string   nome            = Intent.GetStringExtra("restaurante");

            nomeRestaurante.Text = nome;

            // Create intent to Open Image applications like Gallery, Google Photos
            Button imagem = FindViewById <Button>(Resource.Id.button1);

            _start = FindViewById <Button>(Resource.Id.button2);
            _stop  = FindViewById <Button>(Resource.Id.button3);
            string path = "/storage/emulated/0/SaboresPortugal/" + nome + ".3gpp";


            imagem.Click += (sender, e) =>
            {
                // Start the Intent
                var imageIntent = new Intent();
                imageIntent.SetType("image/*");
                imageIntent.SetAction(Intent.ActionGetContent);
                StartActivityForResult(
                    Intent.CreateChooser(imageIntent, "Select photo"), 0);
            };

            _start.Click += (sender, e) =>
            {
                _start.Enabled = !_start.Enabled;

                _recorder.SetAudioSource(AudioSource.Mic);
                _recorder.SetOutputFormat(OutputFormat.ThreeGpp);
                _recorder.SetAudioEncoder(AudioEncoder.AmrNb);
                _recorder.SetOutputFile(path);
                _recorder.Prepare();
                _recorder.Start();
            };

            _stop.Click += (sender, e) =>
            {
                _stop.Enabled = !_stop.Enabled;

                _recorder.Stop();
                _recorder.Reset();

                _player.SetDataSource(path);
                _player.Prepare();
                _player.Start();
            };
        }