// needs to be tested
        public async Task <LiveBroadcast> updateBroadcast(String broadcastId, String snippetTitle, DateTime startTime, DateTime endTime, String privacyStatus)
        {
            youtube = new YouTubeService(await youtubeAuthen.GetInitializer());

            IList <LiveBroadcast> broadcasts = await listBroadcast();

            for (int i = 0; i < broadcasts.Count; i++)
            {
                if (broadcasts[i].Id == broadcastId)
                {
                    LiveBroadcast updateBroadcast = new LiveBroadcast();

                    // Set broadcast snippet
                    updateBroadcast.Snippet       = new LiveBroadcastSnippet();
                    updateBroadcast.Snippet.Title = snippetTitle;
                    updateBroadcast.Snippet.ScheduledStartTime = startTime;
                    updateBroadcast.Snippet.ScheduledEndTime   = endTime;

                    //Set broadcast status
                    updateBroadcast.Status = new LiveBroadcastStatus();
                    updateBroadcast.Status.PrivacyStatus = privacyStatus;

                    LiveBroadcastsResource.UpdateRequest liveBroadcastUpdate = youtube.LiveBroadcasts.Update(updateBroadcast, "id, snippet,contentDetails,status");

                    LiveBroadcast broadcastResponse = liveBroadcastUpdate.Execute();

                    return(broadcastResponse);
                }
            }
            throw new System.ArgumentException("Parameter must belong to user and not be null", "Invalid");
        }
        public async Task <ActionResult> Create([Bind(Include = "Id,CourseId,BroadcastId,BroadcastKind,BroadcastTitle,BroadcastDescription,BroadcastScheduledStartTime,BroadcastScheduledEndTime,BroadcastStatus,BroadcastchannelId,BroadcastlifeCycleStatus,BroadcastEmbededhtml,StreamId,StreamKind,StreamName,StreamStatus,StreamSnippetTitle,StreamCDNFormat,StreamCDNIngestionType,StreamCDNIngestionUrl,StreamcontentclosedCaptionsIngestionUrl")] YoutubeLiveDetail youtubelivedetail)
        {
            BroadcastController liveController = new BroadcastController();

            youtubelivedetail.StreamCDNIngestionType = "rtmp";
            youtubelivedetail.BroadcastKind          = "youtube#liveBroadcast";
            youtubelivedetail.StreamKind             = "youtube#liveStream";
            // Create broadcast and stream for YoutubeLive
            LiveBroadcast broadcast = await liveController.createBroadcast(youtubelivedetail.BroadcastKind, youtubelivedetail.BroadcastTitle, youtubelivedetail.BroadcastScheduledStartTime, youtubelivedetail.BroadcastScheduledEndTime, youtubelivedetail.BroadcastStatus);

            LiveStream stream = await liveController.createStream(youtubelivedetail.StreamKind, youtubelivedetail.StreamSnippetTitle, youtubelivedetail.StreamCDNFormat, youtubelivedetail.StreamCDNIngestionType);

            // Bind them together
            LiveBroadcast bindedBroadcast = await liveController.bindBroadcast(broadcast, stream);

            // Values to-be inserted updated
            youtubelivedetail.BroadcastId           = bindedBroadcast.Id;
            youtubelivedetail.BroadcastchannelId    = bindedBroadcast.ContentDetails.BoundStreamId;
            youtubelivedetail.StreamName            = stream.Cdn.IngestionInfo.StreamName;
            youtubelivedetail.StreamStatus          = stream.Status.StreamStatus;
            youtubelivedetail.StreamId              = stream.Id;
            youtubelivedetail.StreamCDNIngestionUrl = stream.Cdn.IngestionInfo.IngestionAddress;

            String         id      = (bindedBroadcast.ContentDetails.MonitorStream.EmbedHtml).ToString();
            YouTubeService youtube = new YouTubeService(await(new GoogleAuthentication()).GetInitializer());

            bindedBroadcast.ContentDetails.MonitorStream.EnableMonitorStream = false;
            LiveBroadcastsResource.UpdateRequest disablePreview = youtube.LiveBroadcasts.Update(bindedBroadcast, "contentDetails");
            LiveBroadcast returnBroadcast = disablePreview.Execute();

            //substring for browser
            if (id.Contains("embed/"))
            {
                int startIndex = id.IndexOf("embed/");
                int endIndex   = id.IndexOf("?");
                id = id.Substring(startIndex + 6, (endIndex - (startIndex + 6)));
            }

            youtubelivedetail.BroadcastEmbededhtml = id;

            //BroadCastID for Player

            if (ModelState.IsValid)
            {
                db.YoutubeLiveDetails.Add(youtubelivedetail);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CourseId = new SelectList(db.Courses, "Id", "Title", youtubelivedetail.CourseId);
            return(View(youtubelivedetail));
        }