Example #1
0
        void Play()
        {
            if (!IsPlaying)
            {
                try
                {
                    _lock = new RadioStationServiceLock(this);
                    _player.Start();
                    // _schedule.Refresh(force: true);
                }
                catch (Exception ex)
                {
                    //Log.Error(TAG, $"Failed to play: {ex.Message}");
                    //Log.Debug(TAG, ex.ToString());

                    if (_lock != null)
                    {
                        _lock.Release();
                        _lock = null;
                    }

                    Error?.Invoke(this, new RadioStationErrorEventArgs(ex));
                }
            }
        }
Example #2
0
        public void Stop(bool force = false)
        {
            try
            {
                if (IsPlaying)
                {
                    _player.Stop();
                }
            }
            catch (Exception ex)
            {
                //Log.Error(TAG, $"Error during stop: {ex.Message}");
                //Log.Debug(TAG, ex.ToString());
            }
            finally
            {
                if (_lock != null)
                {
                    _lock.Release();
                    _lock = null;
                }

                StopForeground(force);
                StopSelf(_startId);

                _startId = 0;
            }
        }
        private void Play()
        {
            if (!IsPlaying)
            {
                try
                {
                    if (_mediaSession == null)
                    {
                        _mediaSession = new RadioStationMediaSession(this);
                    }

                    if (_player == null)
                    {
                        _player = new RadioStationPlayer(this, this);
                        _player.StateChanged += OnPlayerStateChanged;
                        _player.Error        += OnPlayerError;
                    }

                    _lock = new RadioStationServiceLock(this);
                    _player.Start();
                }
                catch (Exception ex)
                {
                    Log.Error(TAG, $"Failed to play: {ex.Message}");
                    Log.Debug(TAG, ex.ToString());

                    if (_lock != null)
                    {
                        _lock.Release();
                        _lock = null;
                    }

                    Error?.Invoke(this, new RadioStationErrorEventArgs(ex));
                }
            }
        }