コード例 #1
0
 private void EnsureControlServiceIsAlive()
 {
     try
     {
         if (_controlService.State == CommunicationState.Closed || _controlService.State == CommunicationState.Faulted)
         {
             _controlService.Abort();
             _controlService = new PlayerControlServiceClient(new InstanceContext(this));
             _controlService.Subscribe();
         }
     }
     catch (Exception)
     {
     }
 }
コード例 #2
0
        private void SubscribeToControlEvents()
        {
            try
            {
                _controlService = new PlayerControlServiceClient(new InstanceContext(this));
                _controlService.Subscribe();
            }
            catch (Exception)
            {
                _controlService.Abort();

                Thread thread = new Thread(() =>
                {
                    Thread.Sleep(5000);
                    Initialize();
                });
                thread.IsBackground = true;
                thread.Start();
            }
        }
コード例 #3
0
        public void Pause()
        {
            if (IsPlaying)
            {
                EnsureControlServiceIsAlive();

                PlayerControlServiceClient controlService = new PlayerControlServiceClient(new InstanceContext(this));
                try
                {
                    controlService.TogglePause();
                    controlService.Close();
                }
                catch (Exception)
                {
                    controlService.Abort();
                }

                _isPaused = true;
            }
        }
コード例 #4
0
        public void Play()
        {
            if (_currentTrack == null)
            {
                return;
            }

            if (_isPaused)
            {
                EnsureControlServiceIsAlive();

                PlayerControlServiceClient controlService = new PlayerControlServiceClient(new InstanceContext(this));
                try
                {
                    controlService.TogglePause();
                    controlService.Close();
                }
                catch (Exception)
                {
                    controlService.Abort();
                }
            }
            else
            {
                TrackPlayerServiceClient trackPlayer = new TrackPlayerServiceClient();

                try
                {
                    trackPlayer.Play(_currentTrack.TrackId);
                    trackPlayer.Close();
                }
                catch (Exception)
                {
                    trackPlayer.Abort();
                    throw;
                }
            }

            _isPaused = false;
        }