コード例 #1
0
        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");
                            }
                        }
                    }
                }
            }
        }