bilibili / DanmakuFlameMaster

Android开源弹幕引擎·烈焰弹幕使 ~
http://app.bilibili.com/
Apache License 2.0
9.54k stars 2.11k forks source link

一条弹幕显示了两次 #175

Closed LuoboDcom closed 8 years ago

LuoboDcom commented 8 years ago

Acfun 格式设置弹幕,会出现一条弹幕显示两次的情况。比如一共就3条弹幕数据,但是显示了6条弹幕出来。每条显示了两遍。 弹幕数据: jsonArray ="[{'c':'0,16777215,1,25,196050,1364468342','m':'2333333333333'},"+" {'c':'3.619,16777215,1,25,196050,1364468347','m':'哎呦喂。。。。。\uD83D\ue415。\ue056。。\ue405'},"+ "{'c':'7.539,16777215,1,25,196050,1364468351','m':'好长的。。。。。。\uD83D\uDC1F。。。。。。 \uD83D\uDE0A。。。。。。。。。。。。。。'}]";

弹幕配置 public void initDanmaku(){ //设置最大显示行数 HashMap<Integer, Integer> maxLinesPair = new HashMap<>(); maxLinesPair.put(BaseDanmaku.TYPE_SCROLL_RL, 5);//滚动弹幕最大显示3行 //设置是否禁止重叠 HashMap<Integer, Boolean> overlappingEnablePair = new HashMap<>(); overlappingEnablePair.put(BaseDanmaku.TYPE_SCROLL_RL, true); overlappingEnablePair.put(BaseDanmaku.TYPE_FIX_TOP, true);

    danmakuContext = DanmakuContext.create();
    danmakuContext.setDanmakuStyle(IDisplayer.DANMAKU_STYLE_STROKEN, 3)
            .setDuplicateMergingEnabled(false)
            .setScrollSpeedFactor(1.2f)
            .setScaleTextSize(1.2f)
            .setCacheStuffer(new SpannedCacheStuffer(), mCacheStufferAdapter) //图文混拍使用SpannedCacheStuffer

// .setCacheStuffer(new BackgrounndCacheStuffer(),mCacheStufferAdapter) //绘制背景使用BackgroundCacheStuffer .setMaximumLines(maxLinesPair) // 设置最大行数 .preventOverlapping(overlappingEnablePair);//设置是否重叠 }

LuoboDcom commented 8 years ago

是 AcFunDanmakuParser中的这段代码有问题,for中 jsonObject本身就有 c 和 m两个对象,所以它遍历了两次,其实应该不用for遍历 private Danmakus _parse(JSONObject jsonObject, Danmakus danmakus) { if (danmakus == null) { danmakus = new Danmakus(); } if (jsonObject == null || jsonObject.length() == 0) { return danmakus; } for (int i = 0; i < jsonObject.length(); i++) { try { JSONObject obj = jsonObject; String c = obj.getString("c"); String[] values = c.split(","); if (values.length > 0) { int type = Integer.parseInt(values[2]); // 弹幕类型 if (type == 7) // FIXME : hard code // TODO : parse advance danmaku json continue; long time = (long) (Float.parseFloat(values[0]) * 1000); // 出现时间 int color = Integer.parseInt(values[1]) | 0xFF000000; // 颜色 float textSize = Float.parseFloat(values[3]); // 字体大小 BaseDanmaku item = mContext.mDanmakuFactory.createDanmaku(type, mContext); if (item != null) { item.time = time; item.textSize = textSize * (mDispDensity - 0.6f); item.textColor = color; item.textShadowColor = color <= Color.BLACK ? Color.WHITE : Color.BLACK; DanmakuUtils.fillText(item, obj.optString("m", "....")); item.index = i; item.setTimer(mTimer); danmakus.addItem(item); } } } catch (JSONException e) { } catch (NumberFormatException e) { } } return danmakus; }

LuoboDcom commented 8 years ago

我对弹幕实现逻辑也不是很清楚,不知道可不可以直接去掉for,希望作者回答下,谢谢

ctiao commented 8 years ago

可以去掉,这个parser没有经过测试,不保证可用。 建议你自己定义弹幕文件格式和parser

LuoboDcom commented 8 years ago

好的,谢谢!