Ejemplo n.º 1
0
        private void OnReceiveMediaStatus(MessageMediaStatus mediaStatusMessage)
        {
            chromeCastMediaSessionId = mediaStatusMessage.status.Any() ? mediaStatusMessage.status.First().mediaSessionId : 1;

            if (isConnected() && mediaStatusMessage.status.Any())
            {
                switch (mediaStatusMessage.status.First().playerState)
                {
                case "IDLE":
                    setDeviceState(DeviceState.Idle, null);
                    break;

                case "BUFFERING":
                    setDeviceState(DeviceState.Buffering, GetPlayingTime(mediaStatusMessage));
                    break;

                case "PAUSED":
                    setDeviceState(DeviceState.Paused, null);
                    break;

                case "PLAYING":
                    setDeviceState(DeviceState.Playing, GetPlayingTime(mediaStatusMessage));
                    break;

                default:
                    break;
                }
            }
        }
        private void OnReceiveMediaStatus(MessageMediaStatus mediaStatusMessage)
        {
            chromeCastMediaSessionId = mediaStatusMessage.status.Any() ? mediaStatusMessage.status.First().mediaSessionId : 1;

            if (connection.ConnectionState == DeviceConnectionState.Connected && mediaStatusMessage.status.Any())
            {
                switch (mediaStatusMessage.status.First().playerState)
                {
                case "IDLE":
                    DeviceState = DeviceState.Idle;
                    break;

                case "BUFFERING":
                    DeviceState = DeviceState.Buffering;
                    SetPlayingTime(mediaStatusMessage);
                    break;

                case "PAUSED":
                    DeviceState = DeviceState.Paused;
                    break;

                case "PLAYING":
                    DeviceState = DeviceState.Playing;
                    SetPlayingTime(mediaStatusMessage);
                    break;

                default:
                    break;
                }
            }
        }
 private void SetPlayingTime(MessageMediaStatus mediaStatusMessage)
 {
     if (mediaStatusMessage.status != null && mediaStatusMessage.status.First() != null)
     {
         var seconds = (int)(mediaStatusMessage.status.First().currentTime % 60);
         var minutes = ((int)(mediaStatusMessage.status.First().currentTime) % 3600) / 60;
         var hours   = ((int)mediaStatusMessage.status.First().currentTime) / 3600;
         PlayingTime = new TimeSpan(hours, minutes, seconds);
     }
 }
Ejemplo n.º 4
0
        private string GetPlayingTime(MessageMediaStatus mediaStatusMessage)
        {
            if (mediaStatusMessage.status != null && mediaStatusMessage.status.First() != null)
            {
                var seconds = (int)(mediaStatusMessage.status.First().currentTime % 60);
                var minutes = ((int)(mediaStatusMessage.status.First().currentTime) % 3600) / 60;
                var hours   = ((int)mediaStatusMessage.status.First().currentTime) / 3600;
                return(string.Format("{0}:{1}:{2}", hours, minutes.ToString("D2"), seconds.ToString("D2")));
            }

            return(null);
        }
        private string GetPlayingTime(MessageMediaStatus mediaStatusMessage)
        {
            if (mediaStatusMessage.status != null && mediaStatusMessage.status.First() != null)
            {
                var seconds = (int)(mediaStatusMessage.status.First().currentTime % 60);
                var minutes = ((int)(mediaStatusMessage.status.First().currentTime) % 3600) / 60;
                var hours   = ((int)mediaStatusMessage.status.First().currentTime) / 3600;
                return($"{hours}:{minutes.ToString("D2")}");
            }

            return(null);
        }
        /// <summary>
        /// Extract the playing time from a media status message.
        /// </summary>
        /// <param name="mediaStatusMessage">a media status message</param>
        /// <returns>the playing time, format hh:mm</returns>
        private string GetPlayingTime(MessageMediaStatus mediaStatusMessage)
        {
            if (mediaStatusMessage == null || IsDisposed)
            {
                return(string.Empty);
            }

            if (mediaStatusMessage.status != null && mediaStatusMessage.status.First() != null)
            {
                var minutes = ((int)(mediaStatusMessage.status.First().currentTime) % 3600) / 60;
                var hours   = ((int)mediaStatusMessage.status.First().currentTime) / 3600;
                return($"{hours}:{minutes:D2}");
            }

            return(null);
        }
        /// <summary>
        /// Handle a media status message from the device.
        /// </summary>
        /// <param name="mediaStatusMessage">the media status message</param>
        private void OnReceiveMediaStatus(MessageMediaStatus mediaStatusMessage)
        {
            if (mediaStatusMessage == null || device == null || IsDisposed)
            {
                return;
            }

            Connected = true;

            if (mediaStatusMessage?.status?.First()?.volume?.controlType != null &&
                mediaStatusMessage?.status?.First()?.volume?.stepInterval > 0)
            {
                device.OnVolumeUpdate(mediaStatusMessage.status.First().volume);
            }

            chromeCastMediaSessionId = mediaStatusMessage.status.Any() ? mediaStatusMessage.status.First().mediaSessionId : 1;

            if (device.IsConnected() && mediaStatusMessage.status.Any())
            {
                switch (mediaStatusMessage.status.First().playerState)
                {
                case "IDLE":
                    device.SetDeviceState(DeviceState.Idle, null);
                    break;

                case "BUFFERING":
                    device.SetDeviceState(DeviceState.Buffering, GetPlayingTime(mediaStatusMessage));
                    break;

                case "PAUSED":
                    device.SetDeviceState(DeviceState.Paused, null);
                    break;

                case "PLAYING":
                    device.SetDeviceState(DeviceState.Playing, GetPlayingTime(mediaStatusMessage));
                    break;

                default:
                    break;
                }
            }
        }