Search in sources :

Example 11 with BaseDanmaku

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

the class MainActivity method addDanmaku.

private void addDanmaku(boolean islive) {
    BaseDanmaku danmaku = DanmakuFactory.createDanmaku(BaseDanmaku.TYPE_SCROLL_RL);
    //for(int i=0;i<100;i++){
    //}
    danmaku.text = "杩欐槸涓�鏉″脊骞�" + System.nanoTime();
    danmaku.padding = 5;
    danmaku.priority = 1;
    danmaku.isLive = islive;
    danmaku.time = 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 12 with BaseDanmaku

use of master.flame.danmaku.danmaku.model.BaseDanmaku in project GSYVideoPlayer by CarGuo.

the class DanmakuVideoPlayer method addDanmaku.

/**
     * 模拟添加弹幕数据
     */
private void addDanmaku(boolean islive) {
    BaseDanmaku danmaku = mDanmakuContext.mDanmakuFactory.createDanmaku(BaseDanmaku.TYPE_SCROLL_RL);
    if (danmaku == null || mDanmakuView == null) {
        return;
    }
    danmaku.text = "这是一条弹幕 " + getCurrentPositionWhenPlaying();
    danmaku.padding = 5;
    // 可能会被各种过滤器过滤并隐藏显示,所以提高等级
    danmaku.priority = 8;
    danmaku.isLive = islive;
    danmaku.setTime(mDanmakuView.getCurrentTime() + 500);
    danmaku.textSize = 25f * (mParser.getDisplayer().getDensity() - 0.6f);
    danmaku.textColor = Color.RED;
    danmaku.textShadowColor = Color.WHITE;
    danmaku.borderColor = Color.GREEN;
    mDanmakuView.addDanmaku(danmaku);
}
Also used : BaseDanmaku(master.flame.danmaku.danmaku.model.BaseDanmaku)

Example 13 with BaseDanmaku

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

the class DanmakuFactory method createDanmaku.

/**
     * 创建弹幕数据请尽量使用此方法,参考BiliDanmakuParser或AcfunDanmakuParser
     * @param type 弹幕类型
     * @param viewportWidth danmakuview宽度,会影响滚动弹幕的存活时间(duration)
     * @param viewportHeight danmakuview高度
     * @param viewportSizeFactor 会影响滚动弹幕的速度/存活时间(duration)
     * @return
     */
public static BaseDanmaku createDanmaku(int type, float viewportWidth, float viewportHeight, float viewportSizeFactor) {
    boolean sizeChanged = updateViewportState(viewportWidth, viewportHeight, viewportSizeFactor);
    if (MAX_Duration_Scroll_Danmaku == null) {
        MAX_Duration_Scroll_Danmaku = new Duration(REAL_DANMAKU_DURATION);
        MAX_Duration_Scroll_Danmaku.setFactor(DanmakuGlobalConfig.DEFAULT.scrollSpeedFactor);
    } else if (sizeChanged) {
        MAX_Duration_Scroll_Danmaku.setValue(REAL_DANMAKU_DURATION);
    }
    if (MAX_Duration_Fix_Danmaku == null) {
        MAX_Duration_Fix_Danmaku = new Duration(COMMON_DANMAKU_DURATION);
    }
    if (sizeChanged && viewportWidth > 0) {
        updateMaxDanmakuDuration();
        float scaleX = 1f;
        float scaleY = 1f;
        if (CURRENT_DISP_WIDTH > 0 && CURRENT_DISP_HEIGHT > 0) {
            scaleX = viewportWidth / (float) CURRENT_DISP_WIDTH;
            scaleY = viewportHeight / (float) CURRENT_DISP_HEIGHT;
        }
        if (viewportHeight > 0) {
            updateSpecialDanmakusDate(scaleX, scaleY);
        }
    }
    BaseDanmaku instance = null;
    switch(type) {
        case // 从右往左滚动
        1:
            instance = new R2LDanmaku(MAX_Duration_Scroll_Danmaku);
            break;
        case // 底端固定
        4:
            instance = new FBDanmaku(MAX_Duration_Fix_Danmaku);
            break;
        case // 顶端固定
        5:
            instance = new FTDanmaku(MAX_Duration_Fix_Danmaku);
            break;
        case // 从左往右滚动
        6:
            instance = new L2RDanmaku(MAX_Duration_Scroll_Danmaku);
            break;
        case // 特殊弹幕
        7:
            instance = new SpecialDanmaku();
            sSpecialDanmakus.addItem(instance);
            break;
    }
    return instance;
}
Also used : FBDanmaku(master.flame.danmaku.danmaku.model.FBDanmaku) BaseDanmaku(master.flame.danmaku.danmaku.model.BaseDanmaku) FTDanmaku(master.flame.danmaku.danmaku.model.FTDanmaku) L2RDanmaku(master.flame.danmaku.danmaku.model.L2RDanmaku) Duration(master.flame.danmaku.danmaku.model.Duration) SpecialDanmaku(master.flame.danmaku.danmaku.model.SpecialDanmaku) R2LDanmaku(master.flame.danmaku.danmaku.model.R2LDanmaku)

Example 14 with BaseDanmaku

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

the class DanmakuRenderer method draw.

@Override
public RenderingState draw(IDisplayer disp, IDanmakus danmakus, long startRenderTime) {
    int lastTotalDanmakuCount = mRenderingState.totalDanmakuCount;
    mRenderingState.reset();
    IDanmakuIterator itr = danmakus.iterator();
    int orderInScreen = 0;
    mStartTimer.update(System.currentTimeMillis());
    int sizeInScreen = danmakus.size();
    BaseDanmaku drawItem = null;
    while (itr.hasNext()) {
        drawItem = itr.next();
        if (drawItem.isLate()) {
            break;
        }
        if (drawItem.time < startRenderTime || (drawItem.priority == 0 && DanmakuFilters.getDefault().filter(drawItem, orderInScreen, sizeInScreen, mStartTimer, false))) {
            continue;
        }
        if (drawItem.getType() == BaseDanmaku.TYPE_SCROLL_RL) {
            // 同屏弹幕密度只对滚动弹幕有效
            orderInScreen++;
        }
        // measure
        if (!drawItem.isMeasured()) {
            drawItem.measure(disp);
        }
        // layout
        DanmakusRetainer.fix(drawItem, disp);
        // draw
        if (!drawItem.isOutside() && drawItem.isShown()) {
            if (drawItem.lines == null && drawItem.getBottom() > disp.getHeight()) {
                // skip bottom outside danmaku
                continue;
            }
            int renderingType = drawItem.draw(disp);
            if (renderingType == IRenderer.CACHE_RENDERING) {
                mRenderingState.cacheHitCount++;
            } else if (renderingType == IRenderer.TEXT_RENDERING) {
                mRenderingState.cacheMissCount++;
            }
            mRenderingState.addCount(drawItem.getType(), 1);
            mRenderingState.addTotalCount(1);
        }
    }
    mRenderingState.nothingRendered = (mRenderingState.totalDanmakuCount == 0);
    mRenderingState.endTime = drawItem != null ? drawItem.time : RenderingState.UNKNOWN_TIME;
    if (mRenderingState.nothingRendered) {
        mRenderingState.beginTime = RenderingState.UNKNOWN_TIME;
    }
    mRenderingState.incrementCount = mRenderingState.totalDanmakuCount - lastTotalDanmakuCount;
    mRenderingState.consumingTime = mStartTimer.update(System.currentTimeMillis());
    return mRenderingState;
}
Also used : BaseDanmaku(master.flame.danmaku.danmaku.model.BaseDanmaku) IDanmakuIterator(master.flame.danmaku.danmaku.model.IDanmakuIterator)

Example 15 with BaseDanmaku

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

the class MainActivity 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 = spannable;
    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) SpannableStringBuilder(android.text.SpannableStringBuilder)

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