Search in sources :

Example 1 with Danmakus

use of master.flame.danmaku.danmaku.model.android.Danmakus 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 2 with Danmakus

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

the class BiliVideoViewActivity method createParser.

private BaseDanmakuParser createParser(String uri) {
    InputStream stream = null;
    if (uri == null) {
        return new BaseDanmakuParser() {

            @Override
            protected Danmakus parse() {
                return new Danmakus();
            }
        };
    }
    try {
        Response rsp = (Response) Jsoup.connect(uri).execute();
        stream = new ByteArrayInputStream(CompressionTools.decompressXML(rsp.bodyAsBytes()));
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (DataFormatException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    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;
}
Also used : BaseDanmakuParser(master.flame.danmaku.danmaku.parser.BaseDanmakuParser) Response(org.jsoup.helper.HttpConnection.Response) BiliDanmukuParser(master.flame.danmaku.danmaku.parser.android.BiliDanmukuParser) DataFormatException(java.util.zip.DataFormatException) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Danmakus(master.flame.danmaku.danmaku.model.android.Danmakus) IOException(java.io.IOException) ILoader(master.flame.danmaku.danmaku.loader.ILoader) IllegalDataException(master.flame.danmaku.danmaku.loader.IllegalDataException)

Example 3 with Danmakus

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

the class BiliVideoViewActivity method createParser.

private BaseDanmakuParser createParser(InputStream stream) {
    if (stream == null) {
        return new BaseDanmakuParser() {

            @Override
            protected Danmakus 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;
}
Also used : BaseDanmakuParser(master.flame.danmaku.danmaku.parser.BaseDanmakuParser) BiliDanmukuParser(master.flame.danmaku.danmaku.parser.android.BiliDanmukuParser) Danmakus(master.flame.danmaku.danmaku.model.android.Danmakus) ILoader(master.flame.danmaku.danmaku.loader.ILoader) IllegalDataException(master.flame.danmaku.danmaku.loader.IllegalDataException)

Example 4 with Danmakus

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

the class DanmakuVideoPlayer method createParser.

/**
     * 创建解析器对象,解析输入流
     *
     * @param stream
     * @return
     */
private BaseDanmakuParser createParser(InputStream stream) {
    if (stream == null) {
        return new BaseDanmakuParser() {

            @Override
            protected Danmakus 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;
}
Also used : BaseDanmakuParser(master.flame.danmaku.danmaku.parser.BaseDanmakuParser) BiliDanmukuParser(com.example.gsyvideoplayer.utils.BiliDanmukuParser) IDanmakus(master.flame.danmaku.danmaku.model.IDanmakus) Danmakus(master.flame.danmaku.danmaku.model.android.Danmakus) ILoader(master.flame.danmaku.danmaku.loader.ILoader) IllegalDataException(master.flame.danmaku.danmaku.loader.IllegalDataException)

Example 5 with Danmakus

use of master.flame.danmaku.danmaku.model.android.Danmakus in project bilibili-android-client by HotBitmapGG.

the class BiliDanmukuDownloadUtil method downloadXML.

public static Observable<BaseDanmakuParser> downloadXML(final String uri) {
    return Observable.create(new Observable.OnSubscribe<BaseDanmakuParser>() {

        @Override
        public void call(final Subscriber<? super BaseDanmakuParser> subscriber) {
            if (TextUtils.isEmpty(uri)) {
                subscriber.onNext(new BaseDanmakuParser() {

                    @Override
                    protected IDanmakus parse() {
                        return new Danmakus();
                    }
                });
            }
            ILoader loader = null;
            try {
                HttpConnection.Response rsp = (HttpConnection.Response) Jsoup.connect(uri).timeout(20000).execute();
                InputStream stream = new ByteArrayInputStream(BiliDanmukuCompressionTools.decompressXML(rsp.bodyAsBytes()));
                loader = DanmakuLoaderFactory.create(DanmakuLoaderFactory.TAG_BILI);
                loader.load(stream);
            } catch (IOException | DataFormatException | IllegalDataException e) {
                e.printStackTrace();
            }
            BaseDanmakuParser parser = new BiliDanmukuParser();
            assert loader != null;
            IDataSource<?> dataSource = loader.getDataSource();
            parser.load(dataSource);
            subscriber.onNext(parser);
        }
    }).subscribeOn(Schedulers.io());
}
Also used : BaseDanmakuParser(master.flame.danmaku.danmaku.parser.BaseDanmakuParser) HttpConnection(org.jsoup.helper.HttpConnection) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IDanmakus(master.flame.danmaku.danmaku.model.IDanmakus) Danmakus(master.flame.danmaku.danmaku.model.android.Danmakus) IOException(java.io.IOException) DataFormatException(java.util.zip.DataFormatException) Subscriber(rx.Subscriber) ByteArrayInputStream(java.io.ByteArrayInputStream) ILoader(master.flame.danmaku.danmaku.loader.ILoader) IDanmakus(master.flame.danmaku.danmaku.model.IDanmakus) IllegalDataException(master.flame.danmaku.danmaku.loader.IllegalDataException)

Aggregations

Danmakus (master.flame.danmaku.danmaku.model.android.Danmakus)11 ILoader (master.flame.danmaku.danmaku.loader.ILoader)7 IllegalDataException (master.flame.danmaku.danmaku.loader.IllegalDataException)7 IDanmakus (master.flame.danmaku.danmaku.model.IDanmakus)7 BaseDanmakuParser (master.flame.danmaku.danmaku.parser.BaseDanmakuParser)7 BaseDanmaku (master.flame.danmaku.danmaku.model.BaseDanmaku)4 BiliDanmukuParser (master.flame.danmaku.danmaku.parser.android.BiliDanmukuParser)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 DataFormatException (java.util.zip.DataFormatException)2 BiliDanmukuParser (com.example.gsyvideoplayer.utils.BiliDanmukuParser)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 HttpConnection (org.jsoup.helper.HttpConnection)1 Response (org.jsoup.helper.HttpConnection.Response)1 Subscriber (rx.Subscriber)1