Beispiel #1
0
        private void processResponse(string responseBody)
        {
            JObject json = JObject.Parse(responseBody);

            try
            {
                int totalResults = json["pageInfo"]["totalResults"].ToObject <int>();
                if (totalResults == 0)
                {
                    State = StreamState.Unknown;
                    return;
                }

                JToken firstItem            = json["items"][0];
                JToken liveStreamingDetails = firstItem["liveStreamingDetails"];

                string actualEndTime = liveStreamingDetails["actualEndTime"]?.ToString();
                if (!string.IsNullOrEmpty(actualEndTime))
                {
                    State = StreamState.Ended;
                    return;
                }

                string actualStartTime = liveStreamingDetails["actualStartTime"]?.ToString();
                if (!string.IsNullOrEmpty(actualStartTime))
                {
                    State = StreamState.Running;
                    if (int.TryParse(liveStreamingDetails["concurrentViewers"]?.ToString(), out int viewerCount))
                    {
                        ViewerCount = viewerCount;
                    }
                    else
                    {
                        ViewerCount = 0;
                    }
                    return;
                }

                string scheduledStartTime = liveStreamingDetails["scheduledStartTime"]?.ToString();
                if (!string.IsNullOrEmpty(scheduledStartTime))
                {
                    State = StreamState.NotStarted;
                    return;
                }

                State = StreamState.Unknown;
            }
            catch (Exception ex)
            {
                string logMessage = string.Format("Couldn't process response of YouTube API while tried to get state of a stream (ID: {0}). Exception message: [{1}]",
                                                  videoId,
                                                  ex.Message);
                LogDispatcher.E(LOG_TAG, logMessage);
                State = StreamState.Unknown;
            }
        }
Beispiel #2
0
 public void Connect()
 {
     try
     {
         switcher?.Connect();
     }
     catch (CouldNotConnectException ex)
     {
         string errorMessage = string.Format("Couldn't connect to a BlackMagic Design mixer/switcher (ID: {0}) with IP {1}. Exception message: [{2}]",
                                             ID, IpAddress, ex.Message);
         LogDispatcher.E(LOG_TAG, errorMessage);
     }
     catch (AlreadyConnectedException ex)
     {
         string errorMessage = string.Format("Tried to connect to a BlackMagic Design mixer/switcher (ID: {0}) with IP {1}, but was already connected. Exception message: [{2}]",
                                             ID, IpAddress, ex.Message);
         LogDispatcher.W(LOG_TAG, errorMessage);
     }
 }
Beispiel #3
0
 private void doHttpRequest()
 {
     try
     {
         string         url     = string.Format(API_URL, videoId, ApiKeySetting.Value);
         HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
         request.ContentType = "application/json; charset=utf-8";
         HttpWebResponse response = request.GetResponse() as HttpWebResponse;
         using (System.IO.Stream responseStream = response.GetResponseStream())
         {
             StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
             processResponse(reader.ReadToEnd());
         }
     }
     catch (Exception ex)
     {
         State = StreamState.Unknown;
         string logMessage = string.Format("Error occurred while trying to get state of a stream (ID: {0}) using YouTube API. Exception message: [{1}]",
                                           videoId,
                                           ex.Message);
         LogDispatcher.E(LOG_TAG, logMessage);
     }
 }