Example #1
0
 private void SilentlyStopLiveStream(LiveStream liveStream)
 {
     Log.Debug("ChannelNavigator: SilentlyStopLiveStream()");
     g_Player.Stop();
     _liveStream = liveStream;
     StopLiveStream();
 }
Example #2
0
        private void AsyncStopLiveStreamThreadMain()
        {
            if (_streamToStopAsync != null)
            {
                for (int i = 0; i < 50; i++)
                {
                    if (!GUIGraphicsContext.IsPlaying)
                    {
                        break;
                    }

                    Thread.Sleep(100);
                    Log.Debug("ChannelNavigator: AsyncStopLiveStream wait 100ms {0}", _lastChannelChangeFailed);
                }
                Thread.Sleep(200);

                for (int i = 0; i < 10; i++)
                {
                    try
                    {
                        this.ControlAgent.StopLiveStream(_streamToStopAsync);
                    }
                    catch
                    {
                        Thread.Sleep(25);
                    }
                }
                _streamToStopAsync = null;
            }
        }
Example #3
0
        /// <summary>
        /// Ask the recorder whether it is grabbing teletext for the given live stream.
        /// </summary>
        /// <param name="liveStream">The live stream.</param>
        /// <returns>True if the recorder is grabbing teletext.</returns>
        public async Task <bool> IsGrabbingTeletext(LiveStream liveStream)
        {
            var request = NewRequest(HttpMethod.Put, "Live/Teletext/IsGrabbing");

            request.AddBody(liveStream);
            return(await ExecuteResult <bool>(request).ConfigureAwait(false));
        }
Example #4
0
        public static LiveStream CreateLiveStream(string title, string description, string resolution = "1080p", int frameRate = 30)
        {
            var livestream = new LiveStream
            {
                Snippet = new LiveStreamSnippet
                {
                    Title       = title,
                    Description = description
                },
                Cdn = new CdnSettings
                {
                    IngestionType = "rtmp",
                    Resolution    = resolution,
                    FrameRate     = $"{frameRate}fps"
                },
                ContentDetails = new LiveStreamContentDetails
                {
                    IsReusable = true
                }
            };
            var request  = youtubeService.LiveStreams.Insert(livestream, "snippet,cdn,contentDetails,status");
            var response = request.Execute();

            return(response);
        }
        /// <summary>
        /// Tell the recorder to stop grabbing teletext for the given live stream.
        /// </summary>
        /// <param name="liveStream">The live stream.</param>
        public async Task StopGrabbingTeletext(LiveStream liveStream)
        {
            var request = NewRequest(HttpMethod.Post, "StopGrabbingTeletext");

            request.AddBody(liveStream);
            await ExecuteAsync(request).ConfigureAwait(false);
        }
Example #6
0
        /// <summary>
        /// Stop the live stream (if it is found and belongs to the recorder).
        /// </summary>
        /// <param name="liveStream">The live stream to stop.</param>
        public async Task StopLiveStream(LiveStream liveStream)
        {
            var request = NewRequest(HttpMethod.Put, "Live/Stop");

            request.AddBody(liveStream);
            await ExecuteAsync(request).ConfigureAwait(false);
        }
Example #7
0
        /// <summary>
        /// Tell the recorder to stop grabbing teletext for the given live stream.
        /// </summary>
        /// <param name="liveStream">The live stream.</param>
        public void StopGrabbingTeletext(LiveStream liveStream)
        {
            var request = NewRequest("/Live/Teletext/StopGrabbing", Method.PUT);

            request.AddBody(liveStream);
            Execute(request);
        }
        /// <summary>
        /// Request a teletext page/subpage from the recorder for the given live stream, as an image. Note that the page
        /// may contain transparent parts even if 'useTransparentBackground' is set to false (e.g. subtitle or newsflash page).
        /// </summary>
        /// <param name="liveStream">The live stream.</param>
        /// <param name="pageNumber">The teletext page number</param>
        /// <param name="subPageNumber">The teletext subpage number</param>
        /// <param name="imageWidth">The width of the teletext image</param>
        /// <param name="imageHeight">The height of the teletext image</param>
        /// <param name="useTransparentBackground">Use a transparent background instead of black.</param>
        /// <param name="showHidden">Show the hidden teletext information.</param>
        /// <returns>The requested teletext page in form of an image, or null if the page was not ready yet.</returns>
        public async Task <byte[]> GetTeletextPageImage(LiveStream liveStream, int pageNumber, int subPageNumber, int imageWidth, int imageHeight, bool useTransparentBackground = false, bool showHidden = false)
        {
            var request = NewRequest(HttpMethod.Post, "TeletextPageImage/{0}/{1}", imageWidth, imageHeight);

            if (useTransparentBackground)
            {
                request.AddParameter("useTransparentBackground", true);
            }
            if (showHidden)
            {
                request.AddParameter("showHidden", true);
            }
            request.AddBody(new
            {
                LiveStream    = liveStream,
                PageNumber    = pageNumber,
                SubPageNumber = subPageNumber
            });
            using (var response = await ExecuteRequestAsync(request).ConfigureAwait(false))
            {
                switch (response.StatusCode)
                {
                case HttpStatusCode.NoContent:
                    return(null);

                case HttpStatusCode.NotModified:
                    return(new byte[0]);

                case HttpStatusCode.OK:
                    return(response.Content.ReadAsByteArrayAsync().Result);
                }
                throw new ArgusTVException(response.ReasonPhrase);
            }
        }
Example #9
0
        /// <summary>
        /// Ask the recorder for the give live stream's tuning details (if possible).
        /// </summary>
        /// <param name="liveStream">The active live stream.</param>
        /// <returns>The service tuning details, or null if none are available.</returns>
        public ServiceTuning GetLiveStreamTuningDetails(LiveStream liveStream)
        {
            var request = NewRequest("/Live/TuningDetails", Method.PUT);

            request.AddBody(liveStream);
            return(ExecuteResult <ServiceTuning>(request));
        }
Example #10
0
        /// <summary>
        /// Ask the recorder whether the given liveStream has teletext.
        /// </summary>
        /// <param name="liveStream">The live stream.</param>
        /// <returns>True if teletext is present.</returns>
        public bool HasTeletext(LiveStream liveStream)
        {
            var request = NewRequest("/Live/HasTeletext", Method.PUT);

            request.AddBody(liveStream);
            return(ExecuteResult <bool>(request));
        }
Example #11
0
        /// <summary>
        /// Stop the live stream (if it is found and belongs to the recorder).
        /// </summary>
        /// <param name="liveStream">The live stream to stop.</param>
        public void StopLiveStream(LiveStream liveStream)
        {
            var request = NewRequest("/Live/Stop", Method.PUT);

            request.AddBody(liveStream);
            Execute(request);
        }
Example #12
0
        /// <summary>
        /// Tell the recorder we are still showing this stream and to keep it alive. Call this every 30 seconds or so.
        /// </summary>
        /// <param name="liveStream">The live stream that is stil in use.</param>
        /// <returns>True if the live stream is still running, false otherwise.</returns>
        public bool KeepLiveStreamAlive(LiveStream liveStream)
        {
            var request = NewRequest("/Live/KeepAlive", Method.PUT);

            request.AddBody(liveStream);
            return(ExecuteResult <bool>(request));
        }
 public override void LiveStreamEnded(LiveStream liveStream)
 {
     if (OnLiveStreamEnded != null)
     {
         OnLiveStreamEnded(liveStream);
     }
 }
        public async Task <IActionResult> UpdateLiveStream(int id, LiveStream liveStream)
        {
            if (id != liveStream.Id)
            {
                return(BadRequest());
            }

            //liveStreamRepository.Entry(liveStream).State = EntityState.Modified;

            try
            {
                await liveStreamRepository.UpdateLiveStream(liveStream);
            }
            catch (DbUpdateConcurrencyException)
            {
                //if (!LiveStreamExists(id))
                //{
                //    return NotFound();
                //}
                //else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #15
0
        /// <summary>
        /// Ask the recorder whether it is grabbing teletext for the given live stream.
        /// </summary>
        /// <param name="liveStream">The live stream.</param>
        /// <returns>True if the recorder is grabbing teletext.</returns>
        public bool IsGrabbingTeletext(LiveStream liveStream)
        {
            var request = NewRequest("/Live/Teletext/IsGrabbing", Method.PUT);

            request.AddBody(liveStream);
            return(ExecuteResult <bool>(request));
        }
    // Start is called before the first frame update
    void Start()
    {
        liveStream = GetComponent <LiveStream>();

        //set the number of finger tip
        nbOfFinger = fingerObj.Length;
    }
Example #17
0
        /// <summary>
        /// Tell the recorder we are still showing this stream and to keep it alive. Call this every 30 seconds or so.
        /// </summary>
        /// <param name="liveStream">The live stream that is stil in use.</param>
        /// <returns>True if the live stream is still running, false otherwise.</returns>
        public async Task <bool> KeepLiveStreamAlive(LiveStream liveStream)
        {
            var request = NewRequest(HttpMethod.Put, "Live/KeepAlive");

            request.AddBody(liveStream);
            return(await ExecuteResult <bool>(request).ConfigureAwait(false));
        }
        /// <summary>
        /// Ask the recorder for the give live stream's tuning details (if possible).
        /// </summary>
        /// <param name="liveStream">The active live stream.</param>
        /// <returns>The service tuning details, or null if none are available.</returns>
        public async Task <ServiceTuning> GetLiveStreamTuningDetails(LiveStream liveStream)
        {
            var request = NewRequest(HttpMethod.Post, "GetLiveStreamTuningDetails");

            request.AddBody(liveStream);
            return(await ExecuteAsync <ServiceTuning>(request).ConfigureAwait(false));
        }
Example #19
0
        protected override async Task<LiveStream> GetChannelStream(TunerHostInfo info, string channelId, string streamId, CancellationToken cancellationToken)
        {
            var sources = await GetChannelStreamMediaSources(info, channelId, cancellationToken).ConfigureAwait(false);

            var liveStream = new LiveStream(sources.First());
            return liveStream;
        }
Example #20
0
        private void StartLiveTv()
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;

                Channel channel = GetSelectedChannel();
                if (channel != null)
                {
                    _channelsGridView.ClearSelection();
                    LiveStream liveStream = null;
                    var        result     = Proxies.ControlService.TuneLiveStream(channel, liveStream).Result;
                    liveStream = result.LiveStream;
                    if (result.LiveStreamResult == LiveStreamResult.Succeeded)
                    {
                        LoadAllActiveStreams();
                        WinFormsUtility.RunStreamPlayer(liveStream.RtspUrl, true);
                    }
                    else
                    {
                        ShowLiveStreamResultMessageBox(result.LiveStreamResult);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, null, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }
        public override void StopLiveStream(LiveStream liveStream)
        {
            lock (_liveStreamsLock)
            {
                try
                {
                    if (_liveStreams.ContainsKey(liveStream.RtspUrl))
                    {
                        IUser tve3User = _liveStreamUsers[liveStream.RtspUrl];

#if USE_ARGUS_RTSP
                        StopRtspStream(liveStream);
#endif

                        if (TvServerPlugin.TvController_IsTimeShifting(ref tve3User))
                        {
                            if (!TvServerPlugin.TvController_StopTimeShifting(ref tve3User))
                            {
                                Log(TraceEventType.Error, "Failed to stop live stream '{0}'", liveStream.RtspUrl);
                            }
                        }
                        _liveStreams.Remove(liveStream.RtspUrl);
                        _liveStreamUsers.Remove(liveStream.RtspUrl);
                    }
                    CleanUpTimeshiftingFiles(liveStream.TimeshiftFile);
                }
                catch (Exception ex)
                {
                    Log(TraceEventType.Error, ex.Message);
                }
            }
        }
        /// <summary>
        /// Updates a video stream. If the properties that you want to change cannot be updated, then you need to create a new stream with the proper settings.
        /// Documentation https://developers.google.com/youtube/v3/reference/liveStreams/update
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated Youtube service.</param>
        /// <param name="part">The part parameter serves two purposes in this operation. It identifies the properties that the write operation will set as well as the properties that the API response will include.The part properties that you can include in the parameter value are id, snippet, cdn, and status.Note that this method will override the existing values for all of the mutable properties that are contained in any parts that the parameter value specifies. If the request body does not specify a value for a mutable property, the existing value for that property will be removed.</param>
        /// <param name="body">A valid Youtube v3 body.</param>
        /// <param name="optional">Optional paramaters.</param>
        /// <returns>LiveStreamResponse</returns>
        public static LiveStream Update(YoutubeService service, string part, LiveStream body, LiveStreamsUpdateOptionalParms optional = null)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (part == null)
                {
                    throw new ArgumentNullException(part);
                }

                // Building the initial request.
                var request = service.LiveStreams.Update(body, part);

                // Applying optional parameters to the request.
                request = (LiveStreamsResource.UpdateRequest)SampleHelpers.ApplyOptionalParms(request, optional);

                // Requesting data.
                return(request.Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request LiveStreams.Update failed.", ex);
            }
        }
 public override byte[] GetTeletextPageBytes(LiveStream liveStream, int pageNumber, int subPageNumber, out int subPageCount)
 {
     subPageCount = 0;
     if (liveStream.Channel.ChannelType == ChannelType.Television)
     {
         try
         {
             if (_liveStreams.ContainsKey(liveStream.RtspUrl))
             {
                 IUser  tve3User = _liveStreamUsers[liveStream.RtspUrl];
                 byte[] result   = TvServerPlugin.TvController_GetTeletextPage(tve3User, pageNumber, subPageNumber);
                 if (result != null)
                 {
                     subPageCount = TvServerPlugin.TvController_SubPageCount(tve3User, pageNumber);
                 }
                 return(result);
             }
         }
         catch (Exception ex)
         {
             Log(TraceEventType.Error, ex.Message);
         }
     }
     return(null);
 }
Example #24
0
 public override void LiveStreamTuned(LiveStream liveStream)
 {
     if (_statusForm != null)
     {
         _statusForm.OnLiveStreamStarted(liveStream);
     }
 }
        // creates a stream verified
        public async Task <LiveStream> createStream(String kind, String snippetTitle, String CDNFormat, String CDNIngestionType)
        {
            LiveStream liveStream = new LiveStream();

            youtube = new YouTubeService(await youtubeAuthen.GetInitializer());

            // Set stream kind
            liveStream.Kind = kind;

            // Set stream's snippet and title.
            liveStream.Snippet       = new LiveStreamSnippet();
            liveStream.Snippet.Title = snippetTitle;

            //Set stream's Cdn
            liveStream.Cdn               = new CdnSettings();
            liveStream.Cdn.Format        = CDNFormat;
            liveStream.Cdn.IngestionType = CDNIngestionType;

            liveStream.Status = new LiveStreamStatus();
            liveStream.Status.StreamStatus = "active";


            LiveStream returnedStream = youtube.LiveStreams.Insert(liveStream, "snippet,cdn,status").Execute();

            return(returnedStream);
        }
 public async Task LiveStreamEndedAsync(LiveStream liveStream)
 {
     if (!started)
     {
         throw new InvalidOperationException($"{TAG} Client not started");
     }
     await hubConnection.SendAsync(LiveStreamClientState.ENDED, liveStream);
 }
        public async Task LiveStreamEnded(LiveStream liveStream)
        {
            var currentId = Context.ConnectionId;

            liveStreamLookup.Remove(currentId);
            Console.WriteLine(TAG + $"{currentId} has ended a livestream");
            await Clients.All.SendAsync(LiveStreamClientState.ENDED, liveStream);
        }
Example #28
0
        public async Task <IActionResult> GetLive()
        {
            await Task.CompletedTask.ConfigureAwait(false);// Task.Delay(1).ConfigureAwait(false);

            var srm = new LiveStream(_json);

            return(File(srm, JSON_CONTENT_TYPE));//, "data.json");
        }
        public async Task <LiveStream> AddLiveStream(LiveStream livestream)
        {
            var result = await apiDbContext.LiveStream.AddAsync(livestream);

            await apiDbContext.SaveChangesAsync();

            return(result.Entity);
        }
        /// <summary>
        /// Ask the recorder whether it is grabbing teletext for the given live stream.
        /// </summary>
        /// <param name="liveStream">The live stream.</param>
        /// <returns>True if the recorder is grabbing teletext.</returns>
        public async Task <bool> IsGrabbingTeletext(LiveStream liveStream)
        {
            var request = NewRequest(HttpMethod.Post, "GrabbingTeletext");

            request.AddBody(liveStream);
            var result = await ExecuteAsync <GrabbingTeletextResult>(request).ConfigureAwait(false);

            return(result.IsGrabbingTeletext);
        }
        /// <summary>
        /// Setup youtube channel. Needs to refine it all.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void LaunchPage_Loaded(object sender, RoutedEventArgs e)
        {
            //Move authorize to a common class
            user = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                new Uri("ms-appx:///client_secret.json"),
                scope,
                "user",
                CancellationToken.None
            );

            youtubeService = new YouTubeService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = user,
                ApplicationName = "WatchMe"
            });

            //Individual youtube section to be moved to helper classes

            SearchResource.ListRequest listRequest = youtubeService.Search.List("snippet");
            listRequest.MaxResults = 10;
            listRequest.Q = "Microsoft";
            SearchListResponse searchResponse = await listRequest.ExecuteAsync();
            //YoutubePlayer.Source = new Uri("https://progressivemlx-a.akamaihd.net:443/asset-5f19445d-1500-80c4-d8fd-f1e5a5ddee3a/16914-237342-od1s011z.knj_H264_3400kbps_AAC_und_ch2_96kbps.mp4");
            //YoutubePlayer.Source = new Uri("https://www.youtube.com/v/V_XUSOLVRzA");
            //YoutubePlayer.Play();

            //Create broadcast snippet
            LiveBroadcastSnippet livebcSnippet = new LiveBroadcastSnippet();
            livebcSnippet.Title = "Hello Public Broadcast";
            livebcSnippet.ScheduledStartTime = DateTime.Now;
            livebcSnippet.ScheduledEndTime = DateTime.Now.AddHours(2);

            //Set broadcast privacy
            LiveBroadcastStatus livebcStatus = new LiveBroadcastStatus();
            livebcStatus.PrivacyStatus = "public";

            //Create Live Broadcast request combining the above parts
            LiveBroadcast liveBCRequest = new LiveBroadcast();
            liveBCRequest.Kind = "youtube#liveBroadcast";
            liveBCRequest.Snippet = livebcSnippet;
            liveBCRequest.Status = livebcStatus;

            //Create the live broadcast in youtube
            LiveBroadcastsResource.InsertRequest liveBCInsertRequest = youtubeService.LiveBroadcasts.Insert(liveBCRequest, "snippet,status");

            //Final Live Broadcast reponse
            LiveBroadcast liveBCResponse = await liveBCInsertRequest.ExecuteAsync();

            //Create liveStream snippet
            LiveStreamSnippet liveStreamSnippet = new LiveStreamSnippet();
            liveStreamSnippet.Title = "Live Video Public";

            // Define the content distribution network settings for the video stream.
            // The settings specify the stream's format and ingestion type.
            CdnSettings cdnSettings = new CdnSettings();
            cdnSettings.Format = "1080p";
            cdnSettings.IngestionType = "rtmp";

            //Create liveStream request
            LiveStream liveStreamRequest = new LiveStream();
            liveStreamRequest.Kind = "youtube#liveStream";
            liveStreamRequest.Snippet = liveStreamSnippet;
            liveStreamRequest.Cdn = cdnSettings;

            //Create the live stream in youtube
            LiveStreamsResource.InsertRequest liveStreamInsertRequest = youtubeService.LiveStreams.Insert(liveStreamRequest, "snippet,cdn");

            //Final Live Stream reponse
            LiveStream liveStreamResponse = await liveStreamInsertRequest.ExecuteAsync();

            // Construct and execute a request to bind the new broadcast and stream.
            LiveBroadcastsResource.BindRequest bindRequest = youtubeService.LiveBroadcasts.Bind(liveBCResponse.Id, "id,contentDetails");
            bindRequest.StreamId = liveStreamResponse.Id;

            // The LiveBroadcast object bound to the LiveStream
            LiveBroadcast boundBroadcast = await bindRequest.ExecuteAsync();

            App.RTMPUrl = liveStreamResponse.Cdn.IngestionInfo.IngestionAddress + "/" + liveStreamResponse.Cdn.IngestionInfo.StreamName;

            encoder = new RTMPEncoder();
            if (encoder.Ffmpeg_init(400, 300, AUDIO_SAMPLE_RATE, App.RTMPUrl))
            {
                Debug.WriteLine("encoder initialization successfull");
            }
            else
            {
                Debug.WriteLine("encoder initialization failed");
            }
            
            ChangeScenarioState(ScenarioState.Ready);
        }
        public async Task<ActionResult> IndexAsync(LiveStreamingModel liveModel, CancellationToken cancellationToken)
        {
            if (ModelState.IsValid)
            {
                HttpCookie newModel = new HttpCookie("liveModel");
                newModel.Value = new JavaScriptSerializer().Serialize(liveModel);
                newModel.Expires = DateTime.Now.AddHours(10);
                Response.Cookies.Add(newModel);
            }
            else 
            {
                if (Request.Cookies["liveModel"] != null)
                {
                    JavaScriptSerializer objJavascript = new JavaScriptSerializer();
                    liveModel = objJavascript.Deserialize<LiveStreamingModel>(Request.Cookies["liveModel"].Value);
                }
                else {
                    TempData["errorTitle"] = "Error";
                    TempData["errorMessage"] = "Something wrong! Please try again later!";
                    return RedirectToAction("Index", "Home", liveModel.eventID);
                }
            }
            
                var result = await new AuthorizationCodeMvcApp(this, new AppFlowMetadata()).
                AuthorizeAsync(cancellationToken);
                
                
                if (result.Credential != null)
                {
                    var youtubeService = new YouTubeService(new BaseClientService.Initializer()
                    {
                        HttpClientInitializer = result.Credential,
                        ApplicationName = Assembly.GetExecutingAssembly().GetName().Name
                    });
                    LiveBroadcastSnippet broadcastSnippet = new LiveBroadcastSnippet();
                    broadcastSnippet.Title = liveModel.Title;
                    broadcastSnippet.ScheduledStartTime = liveModel.StartTimeYoutube.CompareTo(DateTime.Now) < 0 ? (DateTime.Now) : liveModel.StartTimeYoutube;
                    broadcastSnippet.ScheduledEndTime = liveModel.EndTimeYoutube;
                    // Set the broadcast's privacy status to "private". See:
                    // https://developers.google.com/youtube/v3/live/docs/liveBroadcasts#status.privacyStatus
                    LiveBroadcastStatus status = new LiveBroadcastStatus();
                    if (liveModel.PrivacyYoutube == EventZoneConstants.publicEvent)
                    {
                        status.PrivacyStatus = "public";
                    }
                    else if (liveModel.PrivacyYoutube == EventZoneConstants.unlistedEvent)
                    {
                        status.PrivacyStatus = "unlisted";
                    }
                    else { 
                        status.PrivacyStatus= "private";
                    }
                    //Set LiveBroadcast
                    LiveBroadcast broadcast = new LiveBroadcast();
                    LiveBroadcast returnBroadcast = new LiveBroadcast();
                    broadcast.Kind = "youtube#liveBroadcast";
                    broadcast.Snippet = broadcastSnippet;
                    broadcast.Status = status;
                    LiveBroadcastsResource.InsertRequest liveBroadcastInsert = youtubeService.LiveBroadcasts.Insert(broadcast, "snippet,status");
                    try
                    {
                        returnBroadcast = liveBroadcastInsert.Execute();
                    }
                    catch (Exception ex){
                        TempData["ErrorCreateLiveMessage"] = "Your youtube account can not create live streaming";
                        result.Credential.RevokeTokenAsync(CancellationToken.None).Wait();
                        return RedirectToAction("Details", "Event", new { id = liveModel.eventID });
                    }
                    
                    //Set LiveStream Snippet
                    LiveStreamSnippet streamSnippet = new LiveStreamSnippet();
                    streamSnippet.Title = liveModel.Title + "Stream Title";
                    CdnSettings cdnSettings = new CdnSettings();
                    cdnSettings.Format = liveModel.Quality;
                    cdnSettings.IngestionType = "rtmp";

                    //Set LiveStream
                    LiveStream streamLive = new LiveStream();
                    streamLive.Kind = "youtube#liveStream";
                    streamLive.Snippet = streamSnippet;
                    streamLive.Cdn = cdnSettings;
                    LiveStream returnLiveStream = youtubeService.LiveStreams.Insert(streamLive, "snippet,cdn").Execute();
                    LiveBroadcastsResource.BindRequest liveBroadcastBind = youtubeService.LiveBroadcasts.Bind(returnBroadcast.Id, "id,contentDetails");
                    liveBroadcastBind.StreamId = returnLiveStream.Id;
                    try
                    {
                        returnBroadcast = liveBroadcastBind.Execute();
                    }
                    catch (Exception ex)
                    {
                        TempData["ErrorCreateLiveMessage"] = "Your youtube account can not create live streaming";
                        result.Credential.RevokeTokenAsync(CancellationToken.None).Wait();
                        return RedirectToAction("Details", "Event", new { id = liveModel.eventID });
                    }
                    
                    //Return Value
                    String streamName = returnLiveStream.Cdn.IngestionInfo.StreamName;
                    String primaryServerUrl = returnLiveStream.Cdn.IngestionInfo.IngestionAddress;
                    String backupServerUrl = returnLiveStream.Cdn.IngestionInfo.BackupIngestionAddress;
                    String youtubeUrl = "https://www.youtube.com/watch?v=" + returnBroadcast.Id;
                    
                    //youtubeReturnModel model = new youtubeReturnModel { streamName = streamName, primaryServerUrl = primaryServerUrl,backupServerUrl=backupServerUrl,youtubeUrl=youtubeUrl };
                    Video video = new Video {  EventPlaceID = liveModel.EventPlaceID,
                                               VideoLink = youtubeUrl,
                                               PrimaryServer = primaryServerUrl,
                                               StartTime = liveModel.StartTimeYoutube,
                                               Privacy = liveModel.PrivacyYoutube,
                                               EndTime = liveModel.EndTimeYoutube,
                                               BackupServer = backupServerUrl,
                                               StreamName= streamName};
                    EventDatabaseHelper.Instance.AddVideo(video);
                    HttpCookie newModel = new HttpCookie("liveModel");
                    newModel.Value = new JavaScriptSerializer().Serialize(liveModel);
                    newModel.Expires = DateTime.Now.AddHours(-1);
                    Response.Cookies.Add(newModel);
                    result.Credential.RevokeTokenAsync(CancellationToken.None).Wait();
                    TempData["ErrorCreateLiveMessage"] = "Success";
                    return RedirectToAction("Details", "Event", new { id = EventDatabaseHelper.Instance.GetEventPlaceByID(liveModel.EventPlaceID).EventID });
            }
            else
            {
                return new RedirectResult(result.RedirectUri);
            }
        }