Search in sources :

Example 6 with BaseDanmaku

use of master.flame.danmaku.danmaku.model.BaseDanmaku in project DanmakuFlameMaster by Bilibili.

the class MainActivity method addDanmaku.

private void addDanmaku(boolean islive) {
    BaseDanmaku danmaku = mContext.mDanmakuFactory.createDanmaku(BaseDanmaku.TYPE_SCROLL_RL);
    if (danmaku == null || mDanmakuView == null) {
        return;
    }
    // for(int i=0;i<100;i++){
    // }
    danmaku.text = "这是一条弹幕" + System.nanoTime();
    danmaku.padding = 5;
    // 可能会被各种过滤器过滤并隐藏显示
    danmaku.priority = 0;
    danmaku.isLive = islive;
    danmaku.setTime(mDanmakuView.getCurrentTime() + 1200);
    danmaku.textSize = 25f * (mParser.getDisplayer().getDensity() - 0.6f);
    danmaku.textColor = Color.RED;
    danmaku.textShadowColor = Color.WHITE;
    // danmaku.underlineColor = Color.GREEN;
    danmaku.borderColor = Color.GREEN;
    mDanmakuView.addDanmaku(danmaku);
}
Also used : BaseDanmaku(master.flame.danmaku.danmaku.model.BaseDanmaku)

Example 7 with BaseDanmaku

use of master.flame.danmaku.danmaku.model.BaseDanmaku in project DanmakuFlameMaster by Bilibili.

the class UglyViewCacheStufferSampleActivity method addDanmaKuShowTextAndImage.

private void addDanmaKuShowTextAndImage(boolean islive) {
    BaseDanmaku danmaku = mContext.mDanmakuFactory.createDanmaku(BaseDanmaku.TYPE_SCROLL_RL);
    Drawable drawable = getResources().getDrawable(R.drawable.ic_launcher);
    drawable.setBounds(0, 0, 100, 100);
    //SpannableStringBuilder spannable = createSpannable(drawable);
    danmaku.text = "这是文本,图片在textview左侧";
    danmaku.setTag(new MyImageWare("http://i0.hdslb.com/bfs/face/084bd13eb5dc51a64674085bb28e958ecd5addd0.jpg@180w_180h.webp", danmaku, mIconWidth, mIconWidth, mDanmakuView));
    danmaku.padding = 5;
    // 一定会显示, 一般用于本机发送的弹幕
    danmaku.priority = 1;
    danmaku.isLive = islive;
    danmaku.setTime(mDanmakuView.getCurrentTime() + 1200);
    danmaku.textSize = 25f * (mParser.getDisplayer().getDensity() - 0.6f);
    danmaku.textColor = Color.RED;
    // 重要:如果有图文混排,最好不要设置描边(设textShadowColor=0),否则会进行两次复杂的绘制导致运行效率降低
    danmaku.textShadowColor = 0;
    danmaku.underlineColor = Color.GREEN;
    mDanmakuView.addDanmaku(danmaku);
}
Also used : BaseDanmaku(master.flame.danmaku.danmaku.model.BaseDanmaku) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 8 with BaseDanmaku

use of master.flame.danmaku.danmaku.model.BaseDanmaku in project ABPlayer by winkstu.

the class Danmakus method sub.

@Override
public IDanmakus sub(long startTime, long endTime) {
    if (mSortType == ST_BY_LIST || items == null || items.size() == 0) {
        return null;
    }
    if (subItems == null) {
        subItems = new Danmakus(mDuplicateMergingEnabled);
    }
    if (startItem == null) {
        startItem = createItem("start");
    }
    if (endItem == null) {
        endItem = createItem("end");
    }
    if (subItems != null) {
        long dtime = startTime - startItem.time;
        if (dtime >= 0 && endTime <= endItem.time) {
            return subItems;
        }
    }
    startItem.time = startTime;
    endItem.time = endTime;
    subItems.setItems(((SortedSet<BaseDanmaku>) items).subSet(startItem, endItem));
    return subItems;
}
Also used : BaseDanmaku(master.flame.danmaku.danmaku.model.BaseDanmaku) IDanmakus(master.flame.danmaku.danmaku.model.IDanmakus)

Example 9 with BaseDanmaku

use of master.flame.danmaku.danmaku.model.BaseDanmaku in project ABPlayer by winkstu.

the class AcFunDanmakuParser method _parse.

private Danmakus _parse(JSONArray jsonArray, Danmakus danmakus) {
    if (danmakus == null) {
        danmakus = new Danmakus();
    }
    if (jsonArray == null || jsonArray.length() == 0) {
        return danmakus;
    }
    for (int i = 0; i < jsonArray.length(); i++) {
        try {
            JSONObject obj = jsonArray.getJSONObject(i);
            String c = obj.getString("c");
            String[] values = c.split(",");
            if (values.length > 0) {
                // 弹幕类型
                int type = Integer.parseInt(values[2]);
                if (type == 7)
                    // 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 = DanmakuFactory.createDanmaku(type, mDisp);
                if (item != null) {
                    item.time = time;
                    item.textSize = textSize * (mDispDensity - 0.6f);
                    item.textColor = color;
                    item.textShadowColor = color <= Color.BLACK ? Color.WHITE : Color.BLACK;
                    DanmakuFactory.fillText(item, obj.optString("m", "...."));
                    item.index = i;
                    item.setTimer(mTimer);
                    danmakus.addItem(item);
                }
            }
        } catch (JSONException e) {
        } catch (NumberFormatException e) {
        }
    }
    return danmakus;
}
Also used : BaseDanmaku(master.flame.danmaku.danmaku.model.BaseDanmaku) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) Danmakus(master.flame.danmaku.danmaku.model.android.Danmakus)

Example 10 with BaseDanmaku

use of master.flame.danmaku.danmaku.model.BaseDanmaku in project ABPlayer by winkstu.

the class DrawTask method removeUnusedLiveDanmakusIn.

protected void removeUnusedLiveDanmakusIn(int msec) {
    if (danmakuList == null || danmakuList.isEmpty())
        return;
    synchronized (danmakuList) {
        long startTime = System.currentTimeMillis();
        IDanmakuIterator it = danmakuList.iterator();
        while (it.hasNext()) {
            BaseDanmaku danmaku = it.next();
            boolean isTimeout = danmaku.isTimeOut();
            if (isTimeout && danmaku.isLive) {
                it.remove();
            }
            if (!isTimeout || System.currentTimeMillis() - startTime > msec) {
                break;
            }
        }
    }
}
Also used : BaseDanmaku(master.flame.danmaku.danmaku.model.BaseDanmaku) IDanmakuIterator(master.flame.danmaku.danmaku.model.IDanmakuIterator)

Aggregations

BaseDanmaku (master.flame.danmaku.danmaku.model.BaseDanmaku)23 IDanmakus (master.flame.danmaku.danmaku.model.IDanmakus)9 Danmakus (master.flame.danmaku.danmaku.model.android.Danmakus)4 HashMap (java.util.HashMap)3 DanmakuTimer (master.flame.danmaku.danmaku.model.DanmakuTimer)3 SpecialDanmaku (master.flame.danmaku.danmaku.model.SpecialDanmaku)3 BitmapDrawable (android.graphics.drawable.BitmapDrawable)2 Drawable (android.graphics.drawable.Drawable)2 MediaPlayer (android.media.MediaPlayer)2 VideoView (android.widget.VideoView)2 IDanmakuView (master.flame.danmaku.controller.IDanmakuView)2 Duration (master.flame.danmaku.danmaku.model.Duration)2 FBDanmaku (master.flame.danmaku.danmaku.model.FBDanmaku)2 FTDanmaku (master.flame.danmaku.danmaku.model.FTDanmaku)2 IDanmakuIterator (master.flame.danmaku.danmaku.model.IDanmakuIterator)2 L2RDanmaku (master.flame.danmaku.danmaku.model.L2RDanmaku)2 R2LDanmaku (master.flame.danmaku.danmaku.model.R2LDanmaku)2 SpannedCacheStuffer (master.flame.danmaku.danmaku.model.android.SpannedCacheStuffer)2 Bitmap (android.graphics.Bitmap)1 Paint (android.graphics.Paint)1