master.flame.danmaku.danmaku.model.IDisplayer Java Examples

The following examples show how to use master.flame.danmaku.danmaku.model.IDisplayer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VideoPlayActivity.java    From BlueBoard with Apache License 2.0 6 votes vote down vote up
private void initDanmaku() {
        // 设置最大显示行数
        HashMap<Integer, Integer> maxLinesPair = new HashMap<Integer, Integer>();
        // 滚动弹幕最大显示3行
        maxLinesPair.put(BaseDanmaku.TYPE_SCROLL_RL, 5);
        // 设置是否禁止重叠
        HashMap<Integer, Boolean> overlappingEnablePair = new HashMap<Integer, Boolean>();
        overlappingEnablePair.put(BaseDanmaku.TYPE_SCROLL_RL, true);
        overlappingEnablePair.put(BaseDanmaku.TYPE_FIX_TOP, true);

        mDanmakuContext = DanmakuContext.create();
        mDanmakuContext.setDanmakuStyle(IDisplayer.DANMAKU_STYLE_STROKEN, 3)
                .setDuplicateMergingEnabled(false)
                .setScrollSpeedFactor(1.2f)
                .setScaleTextSize(1.2f)
                .setCacheStuffer(new SpannedCacheStuffer(), null) // 图文混排使用SpannedCacheStuffer
//        .setCacheStuffer(new BackgroundCacheStuffer())  // 绘制背景使用BackgroundCacheStuffer
                .setMaximumLines(maxLinesPair)
                .preventOverlapping(overlappingEnablePair);
    }
 
Example #2
Source File: DanmakuConfig.java    From QSVideoPlayer with Apache License 2.0 6 votes vote down vote up
public static DanmakuContext getDefaultContext() {
        if (danmakuContext != null)
            return danmakuContext;

        // 设置最大显示行数
        HashMap<Integer, Integer> maxLinesPair = new HashMap<>();
        maxLinesPair.put(BaseDanmaku.TYPE_SCROLL_RL, 5); // 滚动弹幕最大显示5行
        // 设置是否禁止重叠
        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 BackgroundCacheStuffer())  // 绘制背景使用BackgroundCacheStuffer
                .setMaximumLines(maxLinesPair)
                .preventOverlapping(overlappingEnablePair)
                .setDanmakuMargin(40);
        return danmakuContext;
    }
 
Example #3
Source File: DanmakuUtils.java    From letv with Apache License 2.0 6 votes vote down vote up
public static boolean willHitInDuration(IDisplayer disp, BaseDanmaku d1, BaseDanmaku d2, long duration, long currTime) {
    int type1 = d1.getType();
    if (type1 != d2.getType()) {
        return false;
    }
    if (d1.isOutside()) {
        return false;
    }
    long dTime = d2.time - d1.time;
    if (dTime < 0) {
        return true;
    }
    if (Math.abs(dTime) >= duration || d1.isTimeOut() || d2.isTimeOut()) {
        return false;
    }
    if (type1 == 5 || type1 == 4) {
        return true;
    }
    return checkHitAtTime(disp, d1, d2, currTime) || checkHitAtTime(disp, d1, d2, d1.time + d1.getDuration());
}
 
Example #4
Source File: BiliDanmukuParser.java    From HeroVideo-master with Apache License 2.0 5 votes vote down vote up
@Override
public BaseDanmakuParser setDisplayer(IDisplayer disp) {
    super.setDisplayer(disp);
    mDispScaleX = mDispWidth / DanmakuFactory.BILI_PLAYER_WIDTH;
    mDispScaleY = mDispHeight / DanmakuFactory.BILI_PLAYER_HEIGHT;
    return this;
}
 
Example #5
Source File: BiliDanmukuParser.java    From GSYVideoPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public BaseDanmakuParser setDisplayer(IDisplayer disp) {
    super.setDisplayer(disp);
    mDispScaleX = mDispWidth / DanmakuFactory.BILI_PLAYER_WIDTH;
    mDispScaleY = mDispHeight / DanmakuFactory.BILI_PLAYER_HEIGHT;
    return this;
}
 
Example #6
Source File: BiliDanmukuParser.java    From HeroVideo-master with Apache License 2.0 5 votes vote down vote up
@Override
public BaseDanmakuParser setDisplayer(IDisplayer disp) {
    super.setDisplayer(disp);
    mDispScaleX = mDispWidth / DanmakuFactory.BILI_PLAYER_WIDTH;
    mDispScaleY = mDispHeight / DanmakuFactory.BILI_PLAYER_HEIGHT;
    return this;
}
 
Example #7
Source File: DanmakuUtils.java    From letv with Apache License 2.0 5 votes vote down vote up
public static DrawingCache buildDanmakuDrawingCache(BaseDanmaku danmaku, IDisplayer disp, DrawingCache cache) {
    if (cache == null) {
        cache = new DrawingCache();
    }
    cache.build((int) Math.ceil((double) danmaku.paintWidth), (int) Math.ceil((double) danmaku.paintHeight), disp.getDensityDpi(), false);
    DrawingCacheHolder holder = cache.get();
    if (holder != null) {
        ((AbsDisplayer) disp).drawDanmaku(danmaku, holder.canvas, 0.0f, 0.0f, true);
        if (disp.isHardwareAccelerated()) {
            holder.splitWith(disp.getWidth(), disp.getHeight(), disp.getMaximumCacheWidth(), disp.getMaximumCacheHeight());
        }
    }
    return cache;
}
 
Example #8
Source File: DanmakuUtils.java    From letv with Apache License 2.0 5 votes vote down vote up
private static boolean checkHitAtTime(IDisplayer disp, BaseDanmaku d1, BaseDanmaku d2, long time) {
    float[] rectArr1 = d1.getRectAtTime(disp, time);
    float[] rectArr2 = d2.getRectAtTime(disp, time);
    if (rectArr1 == null || rectArr2 == null) {
        return false;
    }
    return checkHit(d1.getType(), d2.getType(), rectArr1, rectArr2);
}
 
Example #9
Source File: DanmakusRetainer.java    From letv with Apache License 2.0 5 votes vote down vote up
public void fix(BaseDanmaku danmaku, IDisplayer disp, Verifier verifier) {
    switch (danmaku.getType()) {
        case 1:
            if (this.rldrInstance == null) {
                this.rldrInstance = new RLDanmakusRetainer();
            }
            this.rldrInstance.fix(danmaku, disp, verifier);
            return;
        case 4:
            if (this.fbdrInstance == null) {
                this.fbdrInstance = new FBDanmakusRetainer();
            }
            this.fbdrInstance.fix(danmaku, disp, verifier);
            return;
        case 5:
            if (this.ftdrInstance == null) {
                this.ftdrInstance = new FTDanmakusRetainer();
            }
            this.ftdrInstance.fix(danmaku, disp, verifier);
            return;
        case 6:
            if (this.lrdrInstance == null) {
                this.lrdrInstance = new RLDanmakusRetainer();
            }
            this.lrdrInstance.fix(danmaku, disp, verifier);
            return;
        case 7:
            danmaku.layout(disp, 0.0f, 0.0f);
            return;
        default:
            return;
    }
}
 
Example #10
Source File: DanmakuFactory.java    From letv with Apache License 2.0 5 votes vote down vote up
public BaseDanmaku createDanmaku(int type, IDisplayer disp, float viewportScale, float scrollSpeedFactor) {
    if (disp == null) {
        return null;
    }
    this.sLastDisp = disp;
    return createDanmaku(type, disp.getWidth(), disp.getHeight(), viewportScale, scrollSpeedFactor);
}
 
Example #11
Source File: BaseDanmakuParser.java    From letv with Apache License 2.0 5 votes vote down vote up
public BaseDanmakuParser setDisplayer(IDisplayer disp) {
    this.mDisp = disp;
    this.mDispWidth = disp.getWidth();
    this.mDispHeight = disp.getHeight();
    this.mDispDensity = disp.getDensity();
    this.mScaledDensity = disp.getScaledDensity();
    this.mContext.mDanmakuFactory.updateViewportState((float) this.mDispWidth, (float) this.mDispHeight, getViewportSizeFactor());
    this.mContext.mDanmakuFactory.updateMaxDanmakuDuration();
    return this;
}
 
Example #12
Source File: DanmakuRenderer.java    From letv with Apache License 2.0 4 votes vote down vote up
public RenderingState draw(IDisplayer disp, IDanmakus danmakus, long startRenderTime) {
    int lastTotalDanmakuCount = this.mRenderingState.totalDanmakuCount;
    this.mRenderingState.reset();
    IDanmakuIterator itr = danmakus.iterator();
    int orderInScreen = 0;
    this.mStartTimer.update(SystemClock.uptimeMillis());
    int sizeInScreen = danmakus.size();
    BaseDanmaku drawItem = null;
    while (itr.hasNext()) {
        drawItem = itr.next();
        if (!drawItem.hasPassedFilter()) {
            this.mContext.mDanmakuFilters.filter(drawItem, orderInScreen, sizeInScreen, this.mStartTimer, false, this.mContext);
        }
        if (drawItem.time >= startRenderTime && (!(drawItem.priority == (byte) 0 && drawItem.isFiltered()) && drawItem.time >= startRenderTime)) {
            if (!drawItem.isDanmakuTypeFiltered || !drawItem.isFiltered()) {
                if (drawItem.isLate()) {
                    if (this.mCacheManager == null || drawItem.hasDrawingCache()) {
                        break;
                    }
                    this.mCacheManager.addDanmaku(drawItem);
                } else {
                    orderInScreen++;
                    if (!drawItem.isMeasured()) {
                        drawItem.measure(disp, false);
                    }
                    this.mDanmakusRetainer.fix(drawItem, disp, this.mVerifier);
                    if (!drawItem.isOutside() && drawItem.isShown()) {
                        if (drawItem.lines != null || drawItem.getBottom() <= ((float) disp.getHeight())) {
                            int renderingType = drawItem.draw(disp);
                            RenderingState renderingState;
                            if (renderingType == 1) {
                                renderingState = this.mRenderingState;
                                renderingState.cacheHitCount++;
                            } else if (renderingType == 2) {
                                renderingState = this.mRenderingState;
                                renderingState.cacheMissCount++;
                                if (this.mCacheManager != null) {
                                    this.mCacheManager.addDanmaku(drawItem);
                                }
                            }
                            this.mRenderingState.addCount(drawItem.getType(), 1);
                            this.mRenderingState.addTotalCount(1);
                            if (!(this.mOnDanmakuShownListener == null || drawItem.firstShownFlag == this.mContext.mGlobalFlagValues.FIRST_SHOWN_RESET_FLAG)) {
                                drawItem.firstShownFlag = this.mContext.mGlobalFlagValues.FIRST_SHOWN_RESET_FLAG;
                                this.mOnDanmakuShownListener.onDanmakuShown(drawItem);
                            }
                        }
                    }
                }
            }
        }
    }
    this.mRenderingState.nothingRendered = this.mRenderingState.totalDanmakuCount == 0;
    this.mRenderingState.endTime = drawItem != null ? drawItem.time : -1;
    if (this.mRenderingState.nothingRendered) {
        this.mRenderingState.beginTime = -1;
    }
    this.mRenderingState.incrementCount = this.mRenderingState.totalDanmakuCount - lastTotalDanmakuCount;
    this.mRenderingState.consumingTime = this.mStartTimer.update(SystemClock.uptimeMillis());
    return this.mRenderingState;
}
 
Example #13
Source File: DanmakusRetainer.java    From letv with Apache License 2.0 4 votes vote down vote up
public void fix(BaseDanmaku drawItem, IDisplayer disp, Verifier verifier) {
    if (!drawItem.isOutside()) {
        float topPos = 0.0f;
        int lines = 0;
        boolean willHit = (drawItem.isShown() || this.mVisibleDanmakus.isEmpty()) ? false : true;
        boolean isOutOfVertialEdge = false;
        boolean shown = drawItem.isShown();
        if (!shown) {
            boolean overwriteInsert;
            this.mCancelFixingFlag = false;
            IDanmakuIterator it = this.mVisibleDanmakus.iterator();
            BaseDanmaku insertItem = null;
            BaseDanmaku firstItem = null;
            BaseDanmaku lastItem = null;
            BaseDanmaku minRightRow = null;
            while (!this.mCancelFixingFlag && it.hasNext()) {
                lines++;
                BaseDanmaku item = it.next();
                if (item == drawItem) {
                    insertItem = item;
                    lastItem = null;
                    shown = true;
                    willHit = false;
                    overwriteInsert = false;
                    break;
                }
                if (firstItem == null) {
                    firstItem = item;
                }
                if (drawItem.paintHeight + item.getTop() > ((float) disp.getHeight())) {
                    overwriteInsert = true;
                    break;
                }
                if (minRightRow == null) {
                    minRightRow = item;
                } else if (minRightRow.getRight() >= item.getRight()) {
                    minRightRow = item;
                }
                willHit = DanmakuUtils.willHitInDuration(disp, item, drawItem, drawItem.getDuration(), drawItem.getTimer().currMillisecond);
                if (!willHit) {
                    insertItem = item;
                    overwriteInsert = false;
                    break;
                }
                lastItem = item;
            }
            overwriteInsert = false;
            boolean checkEdge = true;
            if (insertItem != null) {
                if (lastItem != null) {
                    topPos = lastItem.getBottom();
                } else {
                    topPos = insertItem.getTop();
                }
                if (insertItem != drawItem) {
                    this.mVisibleDanmakus.removeItem(insertItem);
                    shown = false;
                }
            } else if (overwriteInsert && minRightRow != null) {
                topPos = minRightRow.getTop();
                checkEdge = false;
                shown = false;
            } else if (lastItem != null) {
                topPos = lastItem.getBottom();
                willHit = false;
            } else if (firstItem != null) {
                topPos = firstItem.getTop();
                this.mVisibleDanmakus.removeItem(firstItem);
                shown = false;
            } else {
                topPos = 0.0f;
            }
            if (checkEdge) {
                isOutOfVertialEdge = isOutVerticalEdge(overwriteInsert, drawItem, disp, topPos, firstItem, lastItem);
            }
            if (isOutOfVertialEdge) {
                topPos = 0.0f;
                willHit = true;
            }
            if (topPos == 0.0f) {
                shown = false;
            }
        }
        if (verifier == null || !verifier.skipLayout(drawItem, topPos, lines, willHit)) {
            if (isOutOfVertialEdge) {
                clear();
            }
            drawItem.layout(disp, drawItem.getLeft(), topPos);
            if (!shown) {
                this.mVisibleDanmakus.addItem(drawItem);
            }
        }
    }
}
 
Example #14
Source File: DanmakusRetainer.java    From letv with Apache License 2.0 4 votes vote down vote up
protected boolean isOutVerticalEdge(boolean overwriteInsert, BaseDanmaku drawItem, IDisplayer disp, float topPos, BaseDanmaku firstItem, BaseDanmaku lastItem) {
    if (topPos < 0.0f || ((firstItem != null && firstItem.getTop() > 0.0f) || drawItem.paintHeight + topPos > ((float) disp.getHeight()))) {
        return true;
    }
    return false;
}
 
Example #15
Source File: DanmakusRetainer.java    From letv with Apache License 2.0 4 votes vote down vote up
protected boolean isOutVerticalEdge(boolean overwriteInsert, BaseDanmaku drawItem, IDisplayer disp, float topPos, BaseDanmaku firstItem, BaseDanmaku lastItem) {
    if (drawItem.paintHeight + topPos > ((float) disp.getHeight())) {
        return true;
    }
    return false;
}
 
Example #16
Source File: DanmakusRetainer.java    From letv with Apache License 2.0 4 votes vote down vote up
public void fix(BaseDanmaku drawItem, IDisplayer disp, Verifier verifier) {
    if (!drawItem.isOutside()) {
        boolean shown = drawItem.isShown();
        float topPos = drawItem.getTop();
        int lines = 0;
        boolean willHit = (drawItem.isShown() || this.mVisibleDanmakus.isEmpty()) ? false : true;
        boolean isOutOfVerticalEdge = false;
        if (topPos < 0.0f) {
            topPos = ((float) disp.getHeight()) - drawItem.paintHeight;
        }
        BaseDanmaku removeItem = null;
        BaseDanmaku firstItem = null;
        if (!shown) {
            this.mCancelFixingFlag = false;
            IDanmakuIterator it = this.mVisibleDanmakus.iterator();
            while (!this.mCancelFixingFlag && it.hasNext()) {
                lines++;
                BaseDanmaku item = it.next();
                if (item == drawItem) {
                    removeItem = null;
                    willHit = false;
                    break;
                }
                if (firstItem == null) {
                    firstItem = item;
                    if (firstItem.getBottom() != ((float) disp.getHeight())) {
                        break;
                    }
                }
                if (topPos < 0.0f) {
                    removeItem = null;
                    break;
                }
                willHit = DanmakuUtils.willHitInDuration(disp, item, drawItem, drawItem.getDuration(), drawItem.getTimer().currMillisecond);
                if (!willHit) {
                    removeItem = item;
                    break;
                }
                topPos = item.getTop() - drawItem.paintHeight;
            }
            isOutOfVerticalEdge = isOutVerticalEdge(false, drawItem, disp, topPos, firstItem, null);
            if (isOutOfVerticalEdge) {
                topPos = ((float) disp.getHeight()) - drawItem.paintHeight;
                willHit = true;
            } else if (topPos >= 0.0f) {
                willHit = false;
            }
        }
        if (verifier == null || !verifier.skipLayout(drawItem, topPos, lines, willHit)) {
            if (isOutOfVerticalEdge) {
                clear();
            }
            drawItem.layout(disp, drawItem.getLeft(), topPos);
            if (!shown) {
                this.mVisibleDanmakus.removeItem(removeItem);
                this.mVisibleDanmakus.addItem(drawItem);
            }
        }
    }
}
 
Example #17
Source File: DanmakusRetainer.java    From letv with Apache License 2.0 4 votes vote down vote up
protected boolean isOutVerticalEdge(boolean overwriteInsert, BaseDanmaku drawItem, IDisplayer disp, float topPos, BaseDanmaku firstItem, BaseDanmaku lastItem) {
    if (topPos < 0.0f || (firstItem != null && firstItem.getBottom() != ((float) disp.getHeight()))) {
        return true;
    }
    return false;
}
 
Example #18
Source File: BiliDanmukuParser.java    From letv with Apache License 2.0 4 votes vote down vote up
public BaseDanmakuParser setDisplayer(IDisplayer disp) {
    super.setDisplayer(disp);
    this.mDispScaleX = ((float) this.mDispWidth) / DanmakuFactory.BILI_PLAYER_WIDTH;
    this.mDispScaleY = ((float) this.mDispHeight) / DanmakuFactory.BILI_PLAYER_HEIGHT;
    return this;
}
 
Example #19
Source File: BaseDanmakuParser.java    From letv with Apache License 2.0 4 votes vote down vote up
public IDisplayer getDisplayer() {
    return this.mDisp;
}
 
Example #20
Source File: DanmakuUtils.java    From letv with Apache License 2.0 4 votes vote down vote up
public static final boolean isOverSize(IDisplayer disp, BaseDanmaku item) {
    return disp.isHardwareAccelerated() && (item.paintWidth > ((float) disp.getMaximumCacheWidth()) || item.paintHeight > ((float) disp.getMaximumCacheHeight()));
}
 
Example #21
Source File: DrawHandler.java    From letv with Apache License 2.0 4 votes vote down vote up
public IDisplayer getDisplayer() {
    return this.mDisp;
}
 
Example #22
Source File: GameBaseActivity.java    From kcanotify_h5-master with GNU General Public License v3.0 4 votes vote down vote up
/**
 * danmuku init
 */
public void initDanMuKu(){
    //弹幕
    // 设置最大显示行数
    HashMap<Integer, Integer> maxLinesPair = new HashMap<Integer, Integer>();
    maxLinesPair.put(BaseDanmaku.TYPE_SCROLL_RL, 10); // 滚动弹幕最大显示10行
    // 设置是否禁止重叠
    HashMap<Integer, Boolean> overlappingEnablePair = new HashMap<Integer, Boolean>();
    overlappingEnablePair.put(BaseDanmaku.TYPE_SCROLL_RL, true);
    overlappingEnablePair.put(BaseDanmaku.TYPE_FIX_TOP, true);

    danmakuContext = DanmakuContext.create();
    danmakuContext.setDanmakuStyle(IDisplayer.DANMAKU_STYLE_STROKEN, 5).setDuplicateMergingEnabled(false)
            .setMaximumLines(maxLinesPair)
            .preventOverlapping(overlappingEnablePair).setDanmakuMargin(20);
    danmakuView = findViewById(R.id.danmaku_view);
    danmakuView.enableDanmakuDrawingCache(true);
    danmakuView.setCallback(new DrawHandler.Callback() {
        @Override
        public void prepared() {
            showDanmaku = true;
            danmakuView.start();
        }

        @Override
        public void updateTimer(DanmakuTimer timer) {

        }

        @Override
        public void danmakuShown(BaseDanmaku danmaku) {

        }

        @Override
        public void drawingFinished() {

        }
    });
    danmakuView.prepare(parser, danmakuContext);
}
 
Example #23
Source File: DanmakusRetainer.java    From letv with Apache License 2.0 votes vote down vote up
void fix(BaseDanmaku baseDanmaku, IDisplayer iDisplayer, Verifier verifier); 
Example #24
Source File: IRenderer.java    From letv with Apache License 2.0 votes vote down vote up
RenderingState draw(IDisplayer iDisplayer, IDanmakus iDanmakus, long j);