diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 491f8487..e8fe33cc 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -52,7 +52,7 @@
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="portrait" />
diff --git a/app/src/main/java/com/devlin_n/dcplayer/MainActivity.java b/app/src/main/java/com/devlin_n/dcplayer/MainActivity.java
index 8bbd5338..a467ae9b 100644
--- a/app/src/main/java/com/devlin_n/dcplayer/MainActivity.java
+++ b/app/src/main/java/com/devlin_n/dcplayer/MainActivity.java
@@ -22,7 +22,7 @@
import com.devlin_n.dcplayer.activity.LivePlayerActivity;
import com.devlin_n.dcplayer.activity.PlayerActivity;
import com.devlin_n.dcplayer.activity.RecyclerViewActivity;
-import com.devlin_n.dcplayer.activity.RecyclerViewAutoPlayActivity;
+import com.devlin_n.dcplayer.activity.AutoPlayRecyclerViewActivity;
import com.devlin_n.dcplayer.activity.VodPlayerActivity;
import com.devlin_n.videoplayer.player.BackgroundPlayService;
import com.devlin_n.videoplayer.player.VideoCacheManager;
@@ -122,6 +122,6 @@ public void list(View view) {
}
public void recyclerAutoPlay(View view) {
- startActivity(new Intent(this, RecyclerViewAutoPlayActivity.class));
+ startActivity(new Intent(this, AutoPlayRecyclerViewActivity.class));
}
}
diff --git a/app/src/main/java/com/devlin_n/dcplayer/activity/RecyclerViewAutoPlayActivity.java b/app/src/main/java/com/devlin_n/dcplayer/activity/AutoPlayRecyclerViewActivity.java
similarity index 98%
rename from app/src/main/java/com/devlin_n/dcplayer/activity/RecyclerViewAutoPlayActivity.java
rename to app/src/main/java/com/devlin_n/dcplayer/activity/AutoPlayRecyclerViewActivity.java
index 379b79ee..6d6b3658 100644
--- a/app/src/main/java/com/devlin_n/dcplayer/activity/RecyclerViewAutoPlayActivity.java
+++ b/app/src/main/java/com/devlin_n/dcplayer/activity/AutoPlayRecyclerViewActivity.java
@@ -29,7 +29,7 @@
* Created by Devlin_n on 2017/5/31.
*/
-public class RecyclerViewAutoPlayActivity extends AppCompatActivity {
+public class AutoPlayRecyclerViewActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
@@ -37,7 +37,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
setContentView(R.layout.activity_recycler_view);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
- actionBar.setTitle("RECYCLER");
+ actionBar.setTitle("AUTO PLAY RECYCLER VIEW");
actionBar.setDisplayHomeAsUpEnabled(true);
}
initView();
diff --git a/app/src/main/java/com/devlin_n/dcplayer/activity/DanmakuActivity.java b/app/src/main/java/com/devlin_n/dcplayer/activity/DanmakuActivity.java
index 9f3bcf84..91da3200 100644
--- a/app/src/main/java/com/devlin_n/dcplayer/activity/DanmakuActivity.java
+++ b/app/src/main/java/com/devlin_n/dcplayer/activity/DanmakuActivity.java
@@ -19,6 +19,7 @@
import android.view.View;
import android.widget.Toast;
+import com.devlin_n.dcplayer.widget.DanmukuVideoView;
import com.devlin_n.floatWindowPermission.FloatWindowManager;
import com.devlin_n.videoplayer.controller.StandardVideoController;
import com.devlin_n.videoplayer.player.IjkVideoView;
@@ -49,7 +50,7 @@ public class DanmakuActivity extends AppCompatActivity {
private DanmakuView mDanmakuView;
private DanmakuContext mContext;
private BaseDanmakuParser mParser;
- private IjkVideoView ijkVideoView;
+ private DanmukuVideoView danmukuVideoView;
private static final String URL_VOD = "http://mov.bn.netease.com/open-movie/nos/flv/2017/01/03/SC8U8K7BC_hd.flv";
// private static final String URL_VOD = "http://uploads.cutv.com:8088/video/data/201703/10/encode_file/515b6a95601ba6b39620358f2677a17358c2472411d53.mp4";
@@ -62,14 +63,14 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
actionBar.setTitle("弹幕");
actionBar.setDisplayHomeAsUpEnabled(true);
}
- ijkVideoView = (IjkVideoView) findViewById(R.id.player);
+ danmukuVideoView = findViewById(R.id.player);
initDanMuView();
- ijkVideoView
+ danmukuVideoView
+ .addDanmukuView(mDanmakuView, mContext, mParser)
// .enableCache()
// .useSurfaceView()
// .useAndroidMediaPlayer()
- .addDanmukuView(mDanmakuView, mContext, mParser)
.autoRotate()
.setVideoController(new StandardVideoController(this))
.setUrl(URL_VOD)
@@ -88,25 +89,25 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
protected void onPause() {
super.onPause();
- ijkVideoView.pause();
+ danmukuVideoView.pause();
}
@Override
protected void onResume() {
super.onResume();
- ijkVideoView.stopFloatWindow();
+ danmukuVideoView.stopFloatWindow();
}
@Override
protected void onDestroy() {
super.onDestroy();
- ijkVideoView.release();
+ danmukuVideoView.release();
}
@Override
public void onBackPressed() {
- if (!ijkVideoView.onBackPressed()) {
+ if (!danmukuVideoView.onBackPressed()) {
super.onBackPressed();
}
}
@@ -115,7 +116,7 @@ public void onBackPressed() {
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == FloatWindowManager.PERMISSION_REQUEST_CODE) {
if (FloatWindowManager.getInstance().checkPermission(this)) {
- ijkVideoView.startFloatWindow();
+ danmukuVideoView.startFloatWindow();
} else {
Toast.makeText(DanmakuActivity.this, "权限授予失败,无法开启悬浮窗", Toast.LENGTH_SHORT).show();
}
@@ -209,7 +210,7 @@ public void addDanmakuWithDrawable(View view) {
}
// for(int i=0;i<100;i++){
// }
- Drawable drawable = ContextCompat.getDrawable(this, R.mipmap.ic_launcher);
+ Drawable drawable = ContextCompat.getDrawable(this, R.mipmap.ic_launcher_round);
int size = WindowUtil.dp2px(this, 20);
drawable.setBounds(0, 0, size, size);
diff --git a/app/src/main/java/com/devlin_n/dcplayer/activity/VodPlayerActivity.java b/app/src/main/java/com/devlin_n/dcplayer/activity/VodPlayerActivity.java
index d2d5d6bd..22965290 100644
--- a/app/src/main/java/com/devlin_n/dcplayer/activity/VodPlayerActivity.java
+++ b/app/src/main/java/com/devlin_n/dcplayer/activity/VodPlayerActivity.java
@@ -49,7 +49,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
videos.add(new VideoModel(URL_VOD, "这是一个标题", new StandardVideoController(this)));
ijkVideoView
- .autoRotate()
+// .autoRotate()
// .enableCache()
// .useSurfaceView()
.useAndroidMediaPlayer()
diff --git a/app/src/main/java/com/devlin_n/dcplayer/widget/DanmukuVideoView.java b/app/src/main/java/com/devlin_n/dcplayer/widget/DanmukuVideoView.java
new file mode 100644
index 00000000..cc04f65b
--- /dev/null
+++ b/app/src/main/java/com/devlin_n/dcplayer/widget/DanmukuVideoView.java
@@ -0,0 +1,108 @@
+package com.devlin_n.dcplayer.widget;
+
+import android.content.Context;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.util.AttributeSet;
+
+import com.devlin_n.videoplayer.player.IjkVideoView;
+
+import master.flame.danmaku.danmaku.model.android.DanmakuContext;
+import master.flame.danmaku.danmaku.parser.BaseDanmakuParser;
+import master.flame.danmaku.ui.widget.DanmakuView;
+
+/**
+ * 包含弹幕的播放器
+ * Created by xinyu on 2017/12/23.
+ */
+
+public class DanmukuVideoView extends IjkVideoView {
+ private DanmakuView mDanmakuView;
+ private DanmakuContext mContext;
+ private BaseDanmakuParser mParser;
+
+
+ public DanmukuVideoView(@NonNull Context context) {
+ super(context);
+ }
+
+ public DanmukuVideoView(@NonNull Context context, @Nullable AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public DanmukuVideoView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ }
+
+ @Override
+ protected void initPlayer() {
+ super.initPlayer();
+ if (mDanmakuView != null) {
+ playerContainer.removeView(mDanmakuView);
+ playerContainer.addView(mDanmakuView, 1);
+ }
+ }
+
+
+ @Override
+ protected void startPrepare() {
+ super.startPrepare();
+ if (mDanmakuView != null) {
+ mDanmakuView.prepare(mParser, mContext);
+ }
+ }
+
+ @Override
+ protected void startInPlaybackState() {
+ super.startInPlaybackState();
+ if (mDanmakuView != null && mDanmakuView.isPrepared() && mDanmakuView.isPaused()) {
+ mDanmakuView.resume();
+ }
+ }
+
+ @Override
+ public void pause() {
+ super.pause();
+ if (isInPlaybackState()) {
+ if (mDanmakuView != null && mDanmakuView.isPrepared()) {
+ mDanmakuView.pause();
+ }
+ }
+ }
+
+ @Override
+ public void resume() {
+ super.resume();
+ if (mDanmakuView != null && mDanmakuView.isPrepared() && mDanmakuView.isPaused()) {
+ mDanmakuView.resume();
+ }
+ }
+
+ @Override
+ public void release() {
+ super.release();
+ if (mDanmakuView != null) {
+ // dont forget release!
+ mDanmakuView.release();
+ mDanmakuView = null;
+ }
+ }
+
+ @Override
+ public void seekTo(int pos) {
+ super.seekTo(pos);
+ if (isInPlaybackState()) {
+ if (mDanmakuView != null) mDanmakuView.seekTo((long) pos);
+ }
+ }
+
+ /**
+ * 添加弹幕
+ */
+ public IjkVideoView addDanmukuView(DanmakuView danmakuView, DanmakuContext context, BaseDanmakuParser parser) {
+ this.mDanmakuView = danmakuView;
+ this.mContext = context;
+ this.mParser = parser;
+ return this;
+ }
+}
diff --git a/app/src/main/res/layout/activity_danmaku_player.xml b/app/src/main/res/layout/activity_danmaku_player.xml
index ffc0dbd3..1c290e22 100644
--- a/app/src/main/res/layout/activity_danmaku_player.xml
+++ b/app/src/main/res/layout/activity_danmaku_player.xml
@@ -4,7 +4,7 @@
android:layout_height="match_parent"
android:orientation="vertical">
-
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index b1d25651..46eded65 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -42,7 +42,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="recyclerAutoPlay"
- android:text="RECYCLER VIEW AUTO PLAY" />
+ android:text="AUTO PLAY RECYCLER VIEW" />