예제 #1
0
        public void RecordStart(string fileName)
        {
            var filePath = _Storage.GetPath(fileName);

            System.Diagnostics.Debug.WriteLine(string.Format("*** AudioService.RecordStart - Preparing to record to: {0}.", filePath));

            _OutputUrl = NSUrl.FromFilename(filePath);

            //  apply recorder settings
            _Recorder = AVAudioRecorder.Create(_OutputUrl, new AudioSettings(_Settings), out _Error);

            //  record
            if (!_Recorder.PrepareToRecord())
            {
                _Recorder.Dispose();
                _Recorder = null;
                throw new Exception("Could not prepare recording");
            }

            _Recorder.FinishedRecording += delegate(object sender, AVStatusEventArgs e)
            {
                _Recorder.Dispose();
                _Recorder = null;
                Console.WriteLine("Done Recording (status: {0})", e.Status);
            };

            _Recorder.Record();

            System.Diagnostics.Debug.WriteLine("*** AudioService.RecordStart - Recording started");
        }
예제 #2
0
        public void RecordStart(string fileName)
        {
            _FileName = fileName;
            var filePath = _Storage.GetPath(fileName);

            Task.Run(async() => await RecordStartAsync(filePath, _Format));
        }
예제 #3
0
        public void PlayPrepare(string fileName)
        {
            try
            {
                var filePath = _Storage.GetPath(fileName);
                var url      = NSUrl.FromFilename(filePath);

                if (_Player == null)
                {
                    _Player = new AVPlayer();
                }

                if (_PlayerItem != null)
                {
                    _Player.RemoveTimeObserver(_TimeChanged); // for skipping 1-2 extra triggering for new item creation code below
                    CleanPlayerItem();
                }

                PlayerReady = false;
                _Asset      = AVAsset.FromUrl(url);
                _PlayerItem = new AVPlayerItem(_Asset);
                _PlayerItem.AddObserver(this, _status, NSKeyValueObservingOptions.Initial | NSKeyValueObservingOptions.New, _Player.Handle);
                _PlayerItem.AddObserver(this, _error, NSKeyValueObservingOptions.Initial | NSKeyValueObservingOptions.New, _Player.Handle);
                _Player.ReplaceCurrentItemWithPlayerItem(_PlayerItem);
                _Player.Rate = 1;
                _Player.Pause(); // HACK: stop autoplaying after recording

                _TimeChanged = _Player.AddPeriodicTimeObserver(new CMTime(1, 1), DispatchQueue.MainQueue, time => {
                    // skip restart event
                    if (_isRestart)
                    {
                        _isRestart = false;

                        return;
                    }

                    if (_PlayerItem != null && _PlayerItem.Duration != CMTime.Indefinite)
                    {
                        var stopped = time == _PlayerItem.Duration;
                        PlaybackStatus?.Invoke(this, new PlaybackEventArgs {
                            CurrentTime = time.Seconds,
                            Duration    = _PlayerItem.Duration.Seconds,
                            Stopped     = stopped
                        });

                        if (stopped)
                        {
                            _isRestart = true;
                            _Player.Seek(CMTime.Zero);
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(string.Format("*** AudioService.PlayPrepare - Exception: {0}", ex));
            }
        }
예제 #4
0
        public async Task InitializeAsync(string userId)
        {
            System.Diagnostics.Debug.WriteLine($"*** {GetType().Name}.{nameof(InitializeAsync)} - Initializing data service - {userId}.");
            try
            {
                //  create the local store
                var path = _StorageService.GetPath($"{userId}.db3");

                await _UserRepository.Initialize(path).ConfigureAwait(false);

                Intialized = true;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"*** {nameof(InitializeAsync)} - Exception: {ex}");
            }
        }