private void AddLivestreamBroadcastDialog_FormClosed(object sender, FormClosedEventArgs e) { if (!string.IsNullOrWhiteSpace(addLivestreamBroadcastDialog.Title) && !string.IsNullOrWhiteSpace(addLivestreamBroadcastDialog.Description)) { var broadcast = YoutubeApiHelper.CreateLiveBroadcast(addLivestreamBroadcastDialog.Title, addLivestreamBroadcastDialog.Description, addLivestreamBroadcastDialog.MadeForKids); var livestream = YoutubeApiHelper.CreateLiveStream(addLivestreamBroadcastDialog.Title, addLivestreamBroadcastDialog.Description, addLivestreamBroadcastDialog.Format, addLivestreamBroadcastDialog.Fps); YoutubeApiHelper.ConnectStreamToBroadcast(livestream.Id, broadcast.Id); var newLivebroadcast = new LivestreamBroadcast() { LiveBroadcastDescription = addLivestreamBroadcastDialog.Description, LiveBroadcastTitle = addLivestreamBroadcastDialog.Title, LiveStreamBroadcastId = broadcast.Id, Playlist = addLivestreamBroadcastDialog.Playlist, PlaylistName = addLivestreamBroadcastDialog.Playlist.PlaylistName, LiveStreamId = livestream.Id, LivestreamName = livestream.Cdn.IngestionInfo.StreamName, LivestreamStatus = broadcast.Status.LifeCycleStatus, MadeForKids = (bool)broadcast.Status.MadeForKids, Format = addLivestreamBroadcastDialog.Format, Fps = addLivestreamBroadcastDialog.Fps }; livestreamBroadcasts.Add(newLivebroadcast); updateLivesBroadcastSource(); } }
private async Task PublishLive() { if (dgvLivebroadcast.SelectedRows == null) { NotificationHelper.Notice("Chưa chọn livestream để publish"); } else { var currentSelectedLive = dgvLivebroadcast.SelectedRows[0].DataBoundItem as LivestreamBroadcast; if (currentSelectedLive != null) { if (NotificationHelper.Confirm("Bạn có muốn publish livestream này?") == DialogResult.Yes) { foreach (var media in DataHelper.GetMedias(currentSelectedLive.Playlist.PlaylistId)) { switch (media.MediaTypeId) { case 1: LiveFromMediaSource(media.MediaLink, currentSelectedLive.Format, currentSelectedLive.Fps, currentSelectedLive.LivestreamName); break; case 2: await LiveFromMediaLink(media.MediaLink, currentSelectedLive.Format, currentSelectedLive.Fps, currentSelectedLive.LivestreamName); break; case 3: LiveFromLiveStream(media.MediaLink, currentSelectedLive.Format, currentSelectedLive.Fps, currentSelectedLive.LivestreamName); break; default: LogHelper.AddLog("Media in playlist can't map type"); break; } var result = await YoutubeApiHelper.GoLiveBroadcast(currentSelectedLive.LiveStreamBroadcastId, currentSelectedLive.LiveStreamId); if (!result) { NotificationHelper.Notice("Không thể publish livestream"); FfmpegHelper.StopFFmpegProcess(currentSelectedLive.LivestreamName); LogHelper.AddLog("Stop ffmpeg process"); } } } } } }
private async void LoadData() { playlists = DataHelper.LoadPlayList(); lbxPlaylist.DataSource = playlists; lbxPlaylist.DisplayMember = "PlaylistName"; dgvMediaLink.DefaultCellStyle.WrapMode = DataGridViewTriState.True; dgvMediaLink.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders; var isConnected = await YoutubeApiHelper.ConnectYoutube(); if (isConnected) { LogHelper.AddLog($"Connected to your youtube channel"); grbLivestream.Text = "Connected"; grbLivestream.Enabled = true; } else { LogHelper.AddLog("Authenticate failed"); grbLivestream.Text = "No connect"; grbLivestream.Enabled = false; } }