Ejemplo n.º 1
0
        public override void OnDestroy()
        {
            base.OnDestroy();

            if (_refreshHandler != null)
            {
                _refreshHandler.Dispose();
                _refreshHandler = null;
            }

            if (_player != null)
            {
                _player.Dispose();
                _player = null;
            }

            //if (_schedule != null)
            //{
            //    _schedule.Dispose();
            //    _schedule = null;
            //}

            if (_notificationManager != null)
            {
                _notificationManager.Stop();
                _notificationManager = null;
            }

            if (_mediaSession != null)
            {
                _mediaSession.Dispose();
                _mediaSession = null;
            }
        }
Ejemplo n.º 2
0
 public override void OnCreate()
 {
     base.OnCreate();
     _mediaSession        = new RadioStationMediaSession(this);
     _notificationManager = new RadioStationNotificationManager(this);
     //_schedule = new RadioStationSchedule(OnScheduleChanged);
     _player = new RadioStationPlayer(this);
     _player.StateChanged += OnPlayerStateChanged;
     _player.Error        += OnPlayerError;
     _refreshHandler.Post(OnRefresh);
 }
Ejemplo n.º 3
0
        public override void OnDestroy()
        {
            if (_connections != null)
            {
                foreach (var connection in _connections)
                {
                    UnbindService(connection);
                }

                _connections = null;
            }

            if (_playingHandler != null)
            {
                _playingHandler.Dispose();
                _playingHandler = null;
            }

            if (_player != null)
            {
                _player.Dispose();
                _player = null;
            }

            if (_schedule != null)
            {
                _schedule.Dispose();
                _schedule = null;
            }

            if (_notificationManager != null)
            {
                _notificationManager.Stop();
                _notificationManager = null;
            }

            if (_mediaSession != null)
            {
                _mediaSession.Dispose();
                _mediaSession = null;
            }

            base.OnDestroy();
        }
Ejemplo n.º 4
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));
                }
            }
        }