コード例 #1
0
        /// <summary>
        /// コメント更新一覧を取得する
        /// </summary>
        /// <returns></returns>
        private IList <CommentStruct> GetBcCmntListUpdate()
        {
            bool isFirst = IsFirst;

            IsFirst = false;
            IList <CommentStruct> workCommentList = new List <CommentStruct>();

            if (!IsBcMovieValid())
            {
                return(workCommentList);
            }

            string url = "https://www.googleapis.com/youtube/v3/liveChat/messages?" +
                         "key=" + APIKey +
                         "&liveChatId=" + ChatId +
                         "&part=" + "id,snippet,authorDetails";

            if (!isFirst)
            {
                url += "&pageToken=" + NextPageToken;
            }
            string recvStr = DoHttpRequest(url);

            if (recvStr == null)
            {
                // 接続エラー
                return(workCommentList);
            }
            try
            {
                // JSON形式からコメント応答オブジェクトに変換
                Root bcCmntResponse = JsonConvert.DeserializeObject <Root>(recvStr);
                NextPageToken = bcCmntResponse.nextPageToken;
                var items = bcCmntResponse.items;

                // コメント応答リストからコメントを取り出す
                workCommentList = new List <CommentStruct>();

                bool isBouyomiOn = !isFirst;
                foreach (var item in items)
                {
                    string channelId = item.snippet.authorChannelId;
                    string msg       = item.snippet.displayMessage;
                    string usr       = item.authorDetails.displayName;

                    var cmnt = new CommentStruct();
                    cmnt.UserName    = usr;
                    cmnt.Text        = msg;
                    cmnt.IsBouyomiOn = isBouyomiOn;
                    workCommentList.Add(cmnt);
                }
            }
            catch (Exception exception)
            {
                System.Diagnostics.Debug.WriteLine(exception.Message + " " + exception.StackTrace);
                System.Diagnostics.Debug.WriteLine("[Error]getBcCmntListUpdate: recvStr: " + recvStr);
                return(workCommentList);
            }
            return(workCommentList);
        }
コード例 #2
0
        /// <summary>
        /// コメントをGUIに登録する
        /// </summary>
        /// <param name="workCommentList"></param>
        private void SetCmntToGui(IList <CommentStruct> workCommentList)
        {
            // 登録済みの最新コメントを取得
            for (int iComment = 0; iComment < workCommentList.Count; iComment++)
            {
                CommentStruct tagtComment = workCommentList[iComment];

                // 新規のコメントの場合、リストに追加する
                CommentList.Add(tagtComment);
                System.Diagnostics.Debug.WriteLine("■{0} {1}", tagtComment.UserName, tagtComment.Text);

                // 最大コメント数チェック
                if (CommentList.Count > MaxStoredCommentCnt)
                {
                    CommentList.RemoveAt(0);
                    System.Diagnostics.Debug.Assert(CommentList.Count == MaxStoredCommentCnt);
                }

                if (OnCommentReceiveEach != null)
                {
                    OnCommentReceiveEach(this, tagtComment);
                }
            }

            if (OnCommentReceiveDone != null)
            {
                OnCommentReceiveDone(this);
            }
        }
コード例 #3
0
        /// <summary>
        /// コメント受信イベントハンドラ
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="comment"></param>
        private void YoutubeChatClient_OnCommentReceiveEach(YoutubeChatClient sender, CommentStruct comment)
        {
            // コメントの追加
            UiCommentData uiCommentData = new UiCommentData();

            uiCommentData.UserThumbUrl = "";
            uiCommentData.UserName     = comment.UserName;
            uiCommentData.CommentStr   = comment.Text;

            System.Diagnostics.Debug.WriteLine("UserThumbUrl " + uiCommentData.UserThumbUrl);
            System.Diagnostics.Debug.WriteLine("UserName " + uiCommentData.UserName);
            System.Diagnostics.Debug.WriteLine("CommentStr " + uiCommentData.CommentStr);

            ViewModel viewModel = this.DataContext as ViewModel;
            ObservableCollection <UiCommentData> uiCommentDataList = viewModel.UiCommentDataCollection;

            uiCommentDataList.Add(uiCommentData);

            // コメントログを記録
            WriteLog(uiCommentData.UserName, uiCommentData.CommentStr);

            // 棒読みちゃんへ送信
            if (comment.IsBouyomiOn)
            {
                string sendText = comment.Text;
                string bcTitle  = YoutubeChatClient.BcTitle;
                if (bcTitle != "")
                {
                    StringBuilder sendTextSb = new StringBuilder(sendText);
                    sendTextSb.Replace("(" + bcTitle + ")", "");
                    sendText = sendTextSb.ToString();
                }
                bouyomiChan.Talk(sendText);
            }
        }