private async void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            if (Send_text_Comment.Text.Length == 0)
            {
                Utils.ShowMessageToast("弹幕内容不能为空!");
                return;
            }
            if (!SettingHelper.Account.Logined)
            {
                Utils.ShowMessageToast("请先登录后再操作");
                return;
            }
            try
            {
                int modeInt = 1;
                if (Send_cb_Mode.SelectedIndex == 2)
                {
                    modeInt = 4;
                }
                if (Send_cb_Mode.SelectedIndex == 1)
                {
                    modeInt = 5;
                }
                var result = await playerAPI.SendDanmu(aid, cid, ((ComboBoxItem)Send_cb_Color.SelectedItem).Tag.ToString(), Send_text_Comment.Text, position).Request();

                if (!result.status)
                {
                    Utils.ShowMessageToast("弹幕发送失败" + result.message);
                    return;
                }
                var obj = result.GetJObject();
                if (obj["code"].ToInt32() == 0)
                {
                    if (DanmakuSended != null)
                    {
                        DanmakuSended(this, new SendDanmakuModel()
                        {
                            location = modeInt,
                            color    = ((ComboBoxItem)Send_cb_Color.SelectedItem).Tag.ToString(),
                            text     = Send_text_Comment.Text
                        });
                    }
                    Utils.ShowMessageToast("弹幕成功发射");

                    Send_text_Comment.Text = string.Empty;
                }
                else
                {
                    Utils.ShowMessageToast("弹幕发送失败" + obj["message"].ToString());
                }
            }
            catch (Exception ex)
            {
                Utils.ShowMessageToast("发送弹幕发生错误!\r\n" + ex.HResult);
            }
        }
Esempio n. 2
0
        public async Task <bool> SendDanmaku(string aid, string cid, string text, int mode, string color)
        {
            try
            {
                if (!SettingHelper.Account.Logined && !await Utils.ShowLoginDialog())
                {
                    Utils.ShowMessageToast("请先登录");
                    return(false);
                }
                if (text == null || text.Trim().Length == 0)
                {
                    Utils.ShowMessageToast("弹幕文本不能为空");
                    return(false);
                }
                var result = await PlayerAPI.SendDanmu(aid, cid, color, text, mode).Request();

                if (result.status)
                {
                    var obj = result.GetJObject();
                    if (obj["code"].ToInt32() == 0)
                    {
                        Utils.ShowMessageToast("弹幕成功发射");
                        return(true);
                    }
                    else
                    {
                        Utils.ShowMessageToast("弹幕发送失败" + obj["message"].ToString());
                        return(false);
                    }
                }
                else
                {
                    Utils.ShowMessageToast("弹幕发送失败" + result.message);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                var result = HandelError <object>(ex);
                Utils.ShowMessageToast(result.message);
                return(false);
            }
        }