Skip to content

Commit

Permalink
Sample: add example for sending danmaku
Browse files Browse the repository at this point in the history
  • Loading branch information
ctiao committed Apr 14, 2014
1 parent f70b5b3 commit 27a8bfa
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Sample/src/main/java/com/sample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import java.io.InputStream;
import android.app.Activity;
import android.graphics.Color;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Environment;
Expand All @@ -16,9 +17,11 @@
import master.flame.danmaku.danmaku.loader.ILoader;
import master.flame.danmaku.danmaku.loader.IllegalDataException;
import master.flame.danmaku.danmaku.loader.android.DanmakuLoaderFactory;
import master.flame.danmaku.danmaku.model.BaseDanmaku;
import master.flame.danmaku.danmaku.model.DanmakuTimer;
import master.flame.danmaku.danmaku.model.android.DanmakuGlobalConfig;
import master.flame.danmaku.danmaku.parser.BaseDanmakuParser;
import master.flame.danmaku.danmaku.parser.DanmakuFactory;
import master.flame.danmaku.danmaku.parser.IDataSource;
import master.flame.danmaku.danmaku.parser.android.BiliDanmukuParser;
import master.flame.danmaku.ui.widget.DanmakuSurfaceView;
Expand All @@ -45,6 +48,8 @@ public class MainActivity extends Activity implements View.OnClickListener {

private Button mBtnResumeDanmaku;

private Button mBtnSendDanmaku;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -74,11 +79,13 @@ private void findViews() {
mBtnShowDanmaku = (Button) findViewById(R.id.btn_show);
mBtnPauseDanmaku = (Button) findViewById(R.id.btn_pause);
mBtnResumeDanmaku = (Button) findViewById(R.id.btn_resume);
mBtnSendDanmaku = (Button) findViewById(R.id.btn_send);
mBtnHideDanmaku.setOnClickListener(this);
mMediaController.setOnClickListener(this);
mBtnShowDanmaku.setOnClickListener(this);
mBtnPauseDanmaku.setOnClickListener(this);
mBtnResumeDanmaku.setOnClickListener(this);
mBtnSendDanmaku.setOnClickListener(this);

// VideoView
mVideoView = (VideoView) findViewById(R.id.videoview);
Expand Down Expand Up @@ -154,6 +161,14 @@ public void onClick(View v) {
mDanmakuView.pause();
} else if (v == mBtnResumeDanmaku) {
mDanmakuView.resume();
} else if (v == mBtnSendDanmaku) {
BaseDanmaku danmaku = DanmakuFactory.createDanmaku(BaseDanmaku.TYPE_SCROLL_RL, mDanmakuView.getWidth());
danmaku.text = "这是一条弹幕";
danmaku.time = mParser.getTimer().currMillisecond + 100;
danmaku.textColor = Color.RED;
danmaku.textShadowColor = Color.WHITE;
danmaku.underlineColor = Color.GREEN;
mDanmakuView.addDanmaku(danmaku);
}
}

Expand Down
6 changes: 6 additions & 0 deletions Sample/src/main/res/layout/media_controller.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
android:layout_height="wrap_content"
android:text="@string/resume_danmaku" />

<Button
android:id="@+id/btn_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/send_danmaku" />

</LinearLayout>

</FrameLayout>
1 change: 1 addition & 0 deletions Sample/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<string name="show_danmaku">show</string>
<string name="pause_danmaku">pause</string>
<string name="resume_danmaku">resume</string>
<string name="send_danmaku">发送一条弹幕</string>

<string name="release">release</string>
</resources>

0 comments on commit 27a8bfa

Please sign in to comment.