標籤:
彈幕現在很流行,特別是在視頻播放時,安卓上沒有簡單好用的彈幕控制項,於是自己寫了一個.
項目地址:https://github.com/linsea/OpenDanmaku
或者國內開源中國上的鏡像:http://git.oschina.net/dictfb/OpenDanmaku
使用方法
完整的使用方法請查看項目的Demo.
1. 在build.gradle檔案中加入依賴.
dependencies { compile ‘com.linsea:opendanmaku:[email protected]‘ }
2. 在布局檔案中加入自訂的彈幕View.
<com.opendanmaku.DanmakuView android:id="@+id/danmakuView" android:layout_width="fill_parent" android:layout_height="fill_parent" app:start_Y_offset="0.2" app:end_Y_offset="0.8" app:max_row="4" app:max_running_per_row="2" app:pick_interval="1000" app:show_debug="false" />
3. 在Activity中產生彈幕對象,並加入到播放清單中.
mDanmakuView = (DanmakuView) findViewById(R.id.danmakuView);// add danmaku items:mDanmakuView.addItem(list, true);mDanmakuView.addItem(new DanmakuItem(this, "Hello World", mDanmakuView.getWidth());//show danmaku and play animation:mDanmakuView.show();//hide and pause playing:mDanmakuView.hide();//release all playing and waiting items:mDanmakuView.clear();
DanmakuView的自訂屬性
* start_Y_offset
第一條播放航道距離彈幕View上邊緣的位移量,注意值是百分比量,以彈幕View的高度為基準,簡而言之就是彈幕View的上邊緣空出多少百分比.
* end_Y_offset
與上一個屬性類似,最後一條播放航道距離彈幕View上邊緣的位移量,注意值是百分比量,以彈幕View的高度為基準,主要作用是便於在彈幕View的底部留出一定的空白.
* max_row
設定最多多少條播放航道.
* max_running_per_row
每條航道上最多同時有多少條彈幕運行.
* pick_interval
每隔多少毫秒取出一條彈幕來播放.
* show_debug
是否顯示航道線及播放幀率,調試時很有用,主要用於調試.
一個Android上的彈幕控制項Open Danmaku