Пример #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;
            }
        }
Пример #2
0
        public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
        {
            if (_notificationManager == null)
            {
                _notificationManager = new RadioStationNotificationManager(this);
            }

            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                if (_startId == 0)
                {
                    StartForeground(NotificationId, _notificationManager.CreateNotificationBuilder().Build());
                }
            }

            if (_startId == 0)
            {
                _startId = startId;
            }

            switch (intent?.Action)
            {
            case ActionPlay:
            case ActionToggle when !IsPlaying:
                Play();
                break;

            case ActionStop:
            case ActionToggle when IsPlaying:
                Stop(intent.HasExtra(ExtraKeyForce));
                break;
            }

            return(StartCommandResult.Sticky);
        }
Пример #3
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);
 }
Пример #4
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();
        }