Exemplo n.º 1
0
        public void StartRecording(RecordType type)
        {
            _type = type;

            if (_type == RecordType.None)
            {
                return;
            }

            try
            {
                _recorder        = new MediaRecorder();
                _recorder.Error += (o, e) =>
                {
                    _isRecording = false;
                    OnServiceChanged.Invoke(this, EventArgs.Empty);
                };

                _recorder.Reset();


                if (_type == RecordType.Video)
                {
                    _recorder.SetAudioSource(AudioSource.Camcorder);
                    _recorder.SetVideoSource(VideoSource.Camera);
                    _recorder.SetOutputFormat(OutputFormat.Mpeg4);
                    _recorder.SetVideoSize(640, 480);
                    _recorder.SetCaptureRate(30);
                    _recorder.SetVideoEncoder(VideoEncoder.Mpeg4Sp);
                    _recorder.SetAudioEncoder(AudioEncoder.Aac);
                }
                else if (_type == RecordType.Audio)
                {
                    _recorder.SetAudioSource(AudioSource.Mic);
                    _recorder.SetOutputFormat(OutputFormat.Default);
                    _recorder.SetAudioEncoder(AudioEncoder.Default);
                }

                _recorder.SetOutputFile(GetFilePath());
                _recorder.Prepare();
                _recorder.Start();
                _isRecording = true;
                OnServiceChanged.Invoke(this, EventArgs.Empty);
            }
            catch (Exception ex)
            {
                _isRecording = false;
                OnServiceChanged.Invoke(this, new UnhandledExceptionEventArgs(ex, false));
            }
        }
Exemplo n.º 2
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();
     }
 }
Exemplo n.º 3
0
        public VoiceCallRecorder()
        {
            //https://developer.android.com/reference/android/media/MediaRecorder.html
            _Recorder = new MediaRecorder();

            _Recorder.SetAudioSource(AudioSource.VoiceCall);
            //API requirements
            //Container : WAV
            //Encoding : PCM
            //Rate : 16K
            //Sample Format : 16bit
            //Channels : Mono

            //AndroidはWAV対応してないようなので自前で組み込む必要があるとのこと
            //http://stackoverflow.com/questions/4871149/how-to-record-voice-in-wav-format-in-android

            _Recorder.SetOutputFormat(OutputFormat.Mpeg4);
            _Recorder.SetAudioEncoder(AudioEncoder.Aac);

            var storage = File.CreateTempFile("hoge_", ".mp4", Android.OS.Environment.ExternalStorageDirectory);

            _OutputPath = storage.AbsolutePath;

            _Recorder.SetOutputFile(_OutputPath);
            _Recorder.Prepare();
        }
Exemplo n.º 4
0
        public Recorder()
        {
            try
            {
                recorder = new MediaRecorder();
                recorder.SetAudioSource(AudioSource.Mic);
                recorder.SetOutputFormat(OutputFormat.Mpeg4);
                recorder.SetAudioEncoder(AudioEncoder.AmrNb);
                //      ActivityCompat.RequestPermissions()

                /*
                 * recorder.SetOutputFormat(OutputFormat.AacAdts);
                 * recorder.SetAudioEncoder(AudioEncoder.Aac);
                 * recorder.SetAudioSource(AudioSource.Mic);
                 */
                recorder.Info  += Recorder_Info;
                recorder.Error += Recorder_Error;
                isRecording     = false;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Exemplo n.º 5
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.º 6
0
        public void StartRecord(string sFileName)
        {
            this.sFileName = sFileName;

            var path = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), sFileName);

            path = Android.App.Application.Context.GetExternalFilesDir(null).AbsolutePath + "/" + sFileName;

            _recorder.SetAudioSource(AudioSource.Mic);
            _recorder.SetOutputFormat(OutputFormat.Mpeg4);
            _recorder.SetAudioEncoder(AudioEncoder.Aac);
            _recorder.SetOutputFile(path);

            if (Int32.Parse(Android.OS.Build.VERSION.Sdk) >= 10)
            {
                _recorder.SetAudioSamplingRate(44100);
                _recorder.SetAudioEncodingBitRate(96000);
            }
            else
            {
                _recorder.SetAudioSamplingRate(8000);
                _recorder.SetAudioEncodingBitRate(12200);
            }

            _recorder.Prepare();
            _recorder.Start();
        }
Exemplo n.º 7
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.º 8
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.º 9
0
        protected void StartRecord()
        {
            string fileName = DateTime.Now.ToString("MM-dd-yyyy-HHmmss");

            recordFile = fileName + ".mp3";

            stop.Enabled  = !stop.Enabled;
            start.Enabled = !start.Enabled;

            aTimer          = new Timer();
            aTimer.Interval = 1000;
            aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
            aTimer.Enabled  = true;
            aTimer.Start();

            recorder = new MediaRecorder();
            recorder.SetAudioSource(AudioSource.Mic);
            recorder.SetOutputFormat(OutputFormat.Mpeg4);
            recorder.SetAudioEncoder(AudioEncoder.Aac);
            recorder.SetOutputFile(recordFolder + "/" + recordFile);

            recorder.SetMaxFileSize(0);
            recorder.SetMaxDuration(0);

            recorder.Prepare();
            recorder.Start();
        }
Exemplo n.º 10
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.º 11
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.º 12
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.º 13
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.º 14
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);
            }
        }
Exemplo n.º 15
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.º 16
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);
            }
        }
Exemplo n.º 17
0
        protected override IEnumerable <Datum> Poll(CancellationToken cancellationToken)
        {
            MediaRecorder recorder = null;

            try
            {
                recorder = new MediaRecorder();
                recorder.SetAudioSource(AudioSource.Mic);
                recorder.SetOutputFormat(OutputFormat.ThreeGpp);
                recorder.SetAudioEncoder(AudioEncoder.AmrNb);
                recorder.SetOutputFile("/dev/null");
                recorder.Prepare();
                recorder.Start();

                // mark start time of amplitude measurement -- MaxAmplitude is always computed from previous call to MaxAmplitude
                int dummy = recorder.MaxAmplitude;

                Thread.Sleep(SampleLengthMS);

                return(new Datum[] { new SoundDatum(DateTimeOffset.UtcNow, 20 * Math.Log10(recorder.MaxAmplitude)) });  // http://www.mathworks.com/help/signal/ref/mag2db.html
            }
            finally
            {
                if (recorder != null)
                {
                    try { recorder.Stop(); }
                    catch (Exception) { }

                    try { recorder.Release(); }
                    catch (Exception) { }
                }
            }
        }
        public OperationResult Initialize(string audioFilePath, float sampleRate = 44100, int channels = 2, int bitDepth = 16)
        {
            if (string.IsNullOrEmpty(audioFilePath))
            {
                return(OperationResult <double> .AsFailure("Invalid audio file path specified"));
            }

            _audioFilePath = audioFilePath;

            if (_recorder == null)
            {
                _recorder = new MediaRecorder();
                _recorder.SetAudioSource(AudioSource.Mic);
                _recorder.SetOutputFormat(OutputFormat.ThreeGpp);
                _recorder.SetAudioEncoder(AudioEncoder.AmrNb);
            }
            else
            {
                if (File.Exists(_audioFilePath))
                {
                    File.Delete(_audioFilePath);
                }
            }

            File.Create(audioFilePath);
            _recorder.SetOutputFile(audioFilePath);
            _recorder.Prepare();

            return(OperationResult.AsSuccess());
        }
 private async Task RecordVideo()
 {
     if (!(Element as VideoCameraPage).IsRecording)
     {
         string filepath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
         string filename = System.IO.Path.Combine(filepath, "video.mp4");
         if (File.Exists(filename))
         {
             File.Delete(filename);
         }
         recorder = new MediaRecorder();
         camera.Unlock();
         recorder.SetCamera(camera);
         recorder.SetVideoSource(VideoSource.Camera);
         recorder.SetAudioSource(AudioSource.Mic);
         recorder.SetProfile(CamcorderProfile.Get(0, CamcorderQuality.High));
         //recorder.SetVideoEncoder(VideoEncoder.Default);
         //recorder.SetAudioEncoder(AudioEncoder.Default);
         //recorder.SetOutputFormat(OutputFormat.Mpeg4);
         recorder.SetOutputFile(filename);
         recorder.Prepare();
         recorder.Start();
         (Element as VideoCameraPage).IsRecording = true;
     }
 }
Exemplo n.º 20
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);
            }
        }
        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.º 22
0
 //protected override void OnPause()
 //{
 //    base.OnPause();
 //   // _player.Release();
 //    mediaRecorder.Release();
 //   // _player.Dispose();
 //    mediaRecorder.Dispose();
 //    //_player = null;
 //    mediaRecorder = null;
 //    //_player.Release();
 //    //_recorder.Release();
 //    //_player.Dispose();
 //    //_recorder.Dispose();
 //    //_player = null;
 //    //_recorder = null;
 //}
 public void StartRecorder()
 {
     try
     {
         if (File.Exists(filePath))
         {
             File.Delete(filePath);
         }
         if (_recorder == null)
         {
             _recorder = new MediaRecorder();
         }
         else
         {
             _recorder.Reset();
             _recorder.SetAudioSource(AudioSource.Mic);
             _recorder.SetOutputFormat(OutputFormat.ThreeGpp);
             _recorder.SetAudioEncoder(AudioEncoder.AmrNb);
             _recorder.SetOutputFile(filePath);
             _recorder.Prepare();
             _recorder.Start();
         }
     }
     catch (Exception ex)
     {
         Console.Out.WriteLine(ex.StackTrace);
     }
 }
Exemplo n.º 23
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.º 24
0
        public void StartRecording()
        {
            var mManager = MainActivity.CurrentActivity.GetSystemService(Context.MediaProjectionService) as MediaProjectionManager;

            mediaProjection = mManager.GetMediaProjection((int)MainActivity.ReturnResultFromPermission, MainActivity.ReturnDataFromPermission);
            DisplayManager dManager       = GetSystemService(Context.DisplayService) as DisplayManager;
            var            displayMetrics = new DisplayMetrics();

            dManager.GetDisplay(0).GetMetrics(displayMetrics);

            mediaRecorder = new MediaRecorder();
            mediaRecorder.SetAudioSource(AudioSource.Mic);
            mediaRecorder.SetVideoSource(VideoSource.Surface);

            var profile = CamcorderProfile.Get(CamcorderQuality.High);

            profile.FileFormat       = OutputFormat.Mpeg4;
            profile.VideoFrameHeight = displayMetrics.HeightPixels;
            profile.VideoFrameWidth  = displayMetrics.WidthPixels;

            mediaRecorder.SetProfile(profile);
            mediaRecorder.SetOutputFile($"{Android.OS.Environment.ExternalStorageDirectory}/demovideo.mp4");
            mediaRecorder.Prepare();

            recordingDisplay = mediaProjection.CreateVirtualDisplay("Rec display", displayMetrics.WidthPixels, displayMetrics.HeightPixels,
                                                                    (int)displayMetrics.Density, Android.Views.DisplayFlags.Round,
                                                                    mediaRecorder.Surface, null, null);

            mediaRecorder.Start();
        }
        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.º 26
0
 public void SetupMediaRecorder()
 {
     recorder = new MediaRecorder();
     recorder.SetAudioSource(AudioSource.Mic);
     recorder.SetOutputFormat(OutputFormat.ThreeGpp);
     recorder.SetAudioEncoder(AudioEncoder.AmrNb);
     recorder.SetOutputFile(filePath);
 }
Exemplo n.º 27
0
 public void MediaRecorderReady()
 {
     mediaRecorder = new MediaRecorder();
     mediaRecorder.SetAudioSource(AudioSource.Mic);
     mediaRecorder.SetOutputFormat(OutputFormat.ThreeGpp);
     mediaRecorder.SetAudioEncoder(AudioEncoder.AmrNb);
     mediaRecorder.SetOutputFile(AudioSavePathInDevice);
 }
Exemplo n.º 28
0
 private void SetUpMediaRecorder()
 {
     mediaRecorder = new MediaRecorder();
     mediaRecorder.SetAudioSource(AudioSource.Mic);
     mediaRecorder.SetOutputFormat(OutputFormat.ThreeGpp);
     mediaRecorder.SetAudioEncoder(AudioEncoder.AmrNb);
     mediaRecorder.SetOutputFile(fileTemp);
 }
Exemplo n.º 29
0
        public void PrepareAudio()
        {
            try
            {
                // 一开始应该是false的
                _isPrepared = false;

                File dir = new File(_mDirString);
                if (!dir.Exists())
                {
                    dir.Mkdirs();
                }
                string fileNameString = GeneralFileName();
                using (var file = new File(dir, fileNameString))
                {
                    _mCurrentFilePathString = file.AbsolutePath;

                    _mRecorder = new MediaRecorder();
                    // 设置输出文件
                    _mRecorder.SetOutputFile(file.AbsolutePath);
                }
                //设置meidaRecorder的音频源是麦克风
                _mRecorder.SetAudioSource(AudioSource.Mic);
                // 设置文件音频的输出格式为amr
                _mRecorder.SetOutputFormat(OutputFormat.RawAmr);
                // 设置音频的编码格式为amr
                _mRecorder.SetAudioEncoder(AudioEncoder.AmrNb);
                //设置录音声道
                _mRecorder.SetAudioChannels(1);
                //设置编码比特率
                _mRecorder.SetAudioEncodingBitRate(1);
                //设置编码采样率
                _mRecorder.SetAudioSamplingRate(8000);
                // 严格遵守google官方api给出的mediaRecorder的状态流程图
                try
                {
                    _mRecorder.Prepare();
                }
                catch (IOException e)
                {
                    Debug.WriteLine("录音未成功,请重试" + e.Message);
                }
                _mRecorder.Start();
                // 准备结束
                _isPrepared = true;

                // 已经准备好了,可以录制了
                Prepared?.Invoke(this, new EventArgs());
            }
            catch (IllegalStateException e)
            {
                e.PrintStackTrace();
            }
            catch (IOException e)
            {
                e.PrintStackTrace();
            }
        }
Exemplo n.º 30
0
 public void StartRecord()
 {
     Recorder.SetAudioSource(AudioSource.Mic);
     Recorder.SetOutputFormat(OutputFormat.ThreeGpp);
     Recorder.SetAudioEncoder(AudioEncoder.AmrNb);
     Recorder.SetOutputFile(AudioFilePath + "/" + AudioFileName + ".wav");
     Recorder.Prepare();
     Recorder.Start();
 }