Closed TongmingWu closed 8 years ago
你需要提供更多的信息,重点检查下弹幕方面的设置是否正确
以下是我修改GiraffePlayer的代码 重载了play方法 public void play(String url, InputStream stream) { this.url = url; this.stream = stream; if (playerSupport) { $.id(R.id.app_video_loading).visible(); videoView.setVideoPath(url); BaseDanmakuParser parser = createParser(stream); danmaku.prepare(parser, context); videoView.start(); } }
//加载弹幕文件 private BaseDanmakuParser createParser(InputStream stream) { if (stream == null) { return new BaseDanmakuParser() { @Override protected IDanmakus parse() { return new Danmakus(); } }; } ILoader loader = DanmakuLoaderFactory.create(DanmakuLoaderFactory.TAG_BILI); try { loader.load(stream); } catch (IllegalDataException e) { e.printStackTrace(); } BaseDanmakuParser parser = new BiliDanmukuParser(); IDataSource<?> dataSource = loader.getDataSource(); parser.load(dataSource); return parser; }
在GiraffePlayer构造方法中添加 danmaku = (DanmakuView) activity.findViewById(R.id.sv_danmaku); //设置最大显示行数 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); context = new DanmakuContext(); context.setDuplicateMergingEnabled(false) .setScrollSpeedFactor(1.2f) .setScaleTextSize(1.2f) .setMaximumLines(maxLinesPair) .preventOverlapping(overlappingEnablePair);
danmaku.setCallback(new DrawHandler.Callback() {
@Override
public void prepared() {
danmaku.start();
LogUtil.i(TAG,"danmaku执行");
}
@Override
public void updateTimer(DanmakuTimer timer) {
}
@Override
public void danmakuShown(BaseDanmaku danmaku) {
}
@Override
public void drawingFinished() {
}
});
danmaku.enableDanmakuDrawingCache(true);
大体上应该是这样了,如果没设置错误的话,应该是我的stream出现问题了- -
搞定了,原来是获取弹幕时服务器返回的数据是经过Deflate压缩的.. 折腾了这么久:(
我用的是b站官方的DanmakuFlameMaster,然后我把danmakuview添加到giraffe_player布局中,但是在播放的时候显示不了弹幕,请问大概应该如何操作呢? :)