Exemple #1
0
        //向服务器 POST 弹幕
        public async void AddDanmakuAsync(Danmaku d)
        {
            string     url        = uri + "/upload_danmaku";
            HttpClient httpClient = new HttpClient();

            var content = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("channel_id", d.Channel_id.ToString()),
                new KeyValuePair <string, string>("type", d.Mode.ToString()),
                new KeyValuePair <string, string>("date", d.Date.ToString("yyyy-MM-dd HH:mm:ss")),
                new KeyValuePair <string, string>("danmaku", d.Text.ToString()),
            });

            try
            {
                var res = await httpClient.PostAsync(url, content);
            }catch (Exception e)
            {
            }
        }
Exemple #2
0
        public List <Danmaku> GetInitDanmaku()
        {
            List <Danmaku> ret = new List <Danmaku>();
            Danmaku        d1  = new Danmaku
            {
                Channel_id = "test",
                Mode       = "scroll",
                Date       = new DateTime(2018, 05, 05),
                Text       = "test1",
                Offset     = TimeSpan.FromSeconds(3)
            };
            Danmaku d2 = new Danmaku
            {
                Channel_id = "test",
                Mode       = "scroll",
                Date       = new DateTime(2018, 05, 05),
                Text       = "test222",
                Offset     = TimeSpan.FromSeconds(10)
            };

            ret.Add(d1); ret.Add(d2);
            return(ret);
        }
Exemple #3
0
        public static List <Danmaku> Xml2DanmakuList(string xmlSourceStr)
        {
            List <Danmaku> tmpList = new List <Danmaku>();
            XmlDocument    xmlDoc  = new XmlDocument();

            xmlDoc.LoadXml(xmlSourceStr);
            XmlNodeList nodelist = xmlDoc.SelectNodes("DanmakuList/Danmaku");

            foreach (XmlNode node in nodelist)
            {
                Danmaku entity = new Danmaku();
                entity.Mode       = HttpUtility.HtmlEncode(node["type"].InnerText);
                entity.Channel_id = HttpUtility.HtmlEncode(node["channel_id"].InnerText);

                DateTimeFormatInfo dtFormat = new DateTimeFormatInfo();
                dtFormat.ShortDatePattern = "yyyy-MM-dd hh:mm:ss";

                entity.Date = Convert.ToDateTime(node["date"].InnerText, dtFormat);
                entity.Text = node["content"].InnerText;
                tmpList.Add(entity);
            }
            return(tmpList);
        }
Exemple #4
0
        public int GetY(Danmaku d, string mode)
        {
            int ret = 0;

            if (mode == "scroll")
            {
                ret = 0;
                if (scrY != null)
                {
                    for (int i = scrY.Count - 1; i >= 0; i--)
                    {
                        if (d.Date >= scrY[i].Date)
                        {
                            int r = (scrY[i].row + 1) % scrollLineLimit;
                            scrY.Add(new DanmakuPosition(r, d.Date));
                            scrY = scrY.OrderBy(s => s.Date).ToList();
                            ret  = r * lineHeight; break;
                        }
                    }
                }
                else
                {
                    scrY.Add(new DanmakuPosition(0, d.Date));
                }
            }
            else if (mode == "top")
            {
                ret = 0;
                if (topY != null)
                {
                    for (int i = topY.Count - 1; i >= 0; i--)
                    {
                        if (d.Date >= topY[i].Date)
                        {
                            int r = (topY[i].row + 1) % topLineLimit;
                            topY.Add(new DanmakuPosition(r, d.Date));
                            topY = topY.OrderBy(s => s.Date).ToList();
                            ret  = r * lineHeight; break;
                        }
                    }
                }
                else
                {
                    topY.Add(new DanmakuPosition(0, d.Date));
                }
            }
            else
            {
                ret = ViewHeight - lineHeight;
                if (botY != null)
                {
                    for (int i = botY.Count - 1; i >= 0; i--)
                    {
                        if (d.Date >= botY[i].Date)
                        {
                            int r = (botY[i].row + 1) % bottomLineLimit;
                            botY.Add(new DanmakuPosition(r, d.Date));
                            botY = botY.OrderBy(s => s.Date).ToList();
                            ret  = ViewHeight - r * lineHeight - lineHeight; break;
                        }
                    }
                }
                else
                {
                    botY.Add(new DanmakuPosition(0, d.Date));
                }
            }
            Debug.WriteLine("getY===" + ret + "view Height = " + ViewHeight);
            return(ret);
        }
Exemple #5
0
        public void AddScrollDanmaku(Danmaku danmaku, bool isNewDanmaku)
        {
            double xx, yy;

            xx = 400; yy = GetY(danmaku, danmaku.Mode);
            Grid danmakuGrid = new Grid
            {
                Margin = new Thickness(0, yy, 0, 0)
            };
            TextBlock tb = new TextBlock
            {
                Text       = danmaku.Text,
                FontSize   = 24,
                Foreground = new SolidColorBrush(Colors.White),
            };

            danmakuGrid.Children.Add(tb);
            TranslateTransform c = new TranslateTransform();

            danmakuGrid.RenderTransform = c;

            Storyboard      sb        = new Storyboard();
            DoubleAnimation animation = new DoubleAnimation
            {
                From     = 4 * xx,
                To       = -xx,
                Duration = new Duration(TimeSpan.FromSeconds(5))
            };

            animation.Completed += ((sender, e) => {
                if (container.Children.Contains(danmakuGrid))
                {
                    container.Children.Remove(danmakuGrid);
                }
            });

            Storyboard.SetTarget(animation, danmakuGrid);

            Storyboard.SetTargetName(animation, "danmakuGrid");
            Storyboard.SetTargetProperty(animation, "(danmakuGrid.RenderTransform).(TranslateTransform.X)");
            sb.Children.Add(animation);
            container.Children.Add(danmakuGrid);
            if (isNewDanmaku)
            {
                sb.BeginTime = TimeSpan.FromSeconds(0);
            }
            else
            {
                //sb.BeginTime = TimeSpan.FromSeconds(danmaku.offset);
                sb.BeginTime = TimeSpan.FromSeconds(danmaku.Offset.TotalSeconds);
            }
            storyBoards.Add(sb);

            if (danmakus != null && !danmakus.Contains(danmaku))
            {
                danmakus.Add(danmaku);
            }

            sb.Begin();
            Debug.WriteLine(danmaku.Text);
        }