提交 7abe5476 编写于 作者: S shuyu

1.4.9 列表播放

上级 d7c1fdd4
......@@ -51,6 +51,10 @@
android:name=".RecyclerView2Activity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="portrait" />
<activity
android:name=".DetailListPlayer"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="portrait" />
</application>
</manifest>
\ No newline at end of file
package com.example.gsyvideoplayer;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import com.example.gsyvideoplayer.listener.SampleListener;
import com.shuyu.gsyvideoplayer.GSYPreViewManager;
import com.shuyu.gsyvideoplayer.GSYVideoPlayer;
import com.shuyu.gsyvideoplayer.listener.LockClickListener;
import com.shuyu.gsyvideoplayer.model.GSYVideoModel;
import com.shuyu.gsyvideoplayer.utils.OrientationUtils;
import com.shuyu.gsyvideoplayer.video.ListGSYVideoPlayer;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
/**
* Created by shuyu on 2016/12/20.
*/
public class DetailListPlayer extends AppCompatActivity {
@BindView(R.id.post_detail_nested_scroll)
NestedScrollView postDetailNestedScroll;
@BindView(R.id.detail_player)
ListGSYVideoPlayer detailPlayer;
@BindView(R.id.activity_detail_player)
RelativeLayout activityDetailPlayer;
private boolean isPlay;
private boolean isPause;
private OrientationUtils orientationUtils;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_deatil_list_player);
ButterKnife.bind(this);
//String url = "http://baobab.wd jcdn.com/14564977406580.mp4";
List<GSYVideoModel> urls = new ArrayList<>();
urls.add(new GSYVideoModel("http://baobab.wdjcdn.com/14564977406580.mp4", "标题1"));
urls.add(new GSYVideoModel("http://9890.vod.myqcloud.com/9890_4e292f9a3dd011e6b4078980237cc3d3.f20.mp4", "标题2"));
urls.add(new GSYVideoModel("http://baobab.wdjcdn.com/14564977406580.mp4", "标题3"));
urls.add(new GSYVideoModel("http://9890.vod.myqcloud.com/9890_4e292f9a3dd011e6b4078980237cc3d3.f20.mp4", "标题4"));
detailPlayer.setUp(urls, true, 0, "");
//增加封面
ImageView imageView = new ImageView(this);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setImageResource(R.mipmap.xxx1);
detailPlayer.setThumbImageView(imageView);
resolveNormalVideoUI();
//外部辅助的旋转,帮助全屏
orientationUtils = new OrientationUtils(this, detailPlayer);
//初始化不打开外部的旋转
orientationUtils.setEnable(false);
detailPlayer.setIsTouchWiget(true);
//关闭自动旋转
detailPlayer.setRotateViewAuto(false);
detailPlayer.setLockLand(false);
detailPlayer.setShowFullAnimation(false);
detailPlayer.setNeedLockFull(true);
detailPlayer.getFullscreenButton().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//直接横屏
orientationUtils.resolveByClick();
//第一个true是否需要隐藏actionbar,第二个true是否需要隐藏statusbar
detailPlayer.startWindowFullscreen(DetailListPlayer.this, true, true);
}
});
detailPlayer.setStandardVideoAllCallBack(new SampleListener() {
@Override
public void onPrepared(String url, Object... objects) {
super.onPrepared(url, objects);
//开始播放了才能旋转和全屏
orientationUtils.setEnable(true);
isPlay = true;
}
@Override
public void onAutoComplete(String url, Object... objects) {
super.onAutoComplete(url, objects);
}
@Override
public void onClickStartError(String url, Object... objects) {
super.onClickStartError(url, objects);
}
@Override
public void onQuitFullscreen(String url, Object... objects) {
super.onQuitFullscreen(url, objects);
if (orientationUtils != null) {
orientationUtils.backToProtVideo();
}
}
});
detailPlayer.setLockClickListener(new LockClickListener() {
@Override
public void onClick(View view, boolean lock) {
if (orientationUtils != null) {
//配合下方的onConfigurationChanged
orientationUtils.setEnable(!lock);
}
}
});
}
@Override
public void onBackPressed() {
if (orientationUtils != null) {
orientationUtils.backToProtVideo();
}
if (StandardGSYVideoPlayer.backFromWindowFull(this)) {
return;
}
super.onBackPressed();
}
@Override
protected void onPause() {
super.onPause();
isPause = true;
}
@Override
protected void onResume() {
super.onResume();
isPause = false;
}
@Override
protected void onDestroy() {
super.onDestroy();
GSYVideoPlayer.releaseAllVideos();
GSYPreViewManager.instance().releaseMediaPlayer();
if (orientationUtils != null)
orientationUtils.releaseListener();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
//如果旋转了就全屏
if (isPlay && !isPause) {
if (newConfig.orientation == ActivityInfo.SCREEN_ORIENTATION_USER) {
if (!detailPlayer.isIfCurrentIsFullscreen()) {
detailPlayer.startWindowFullscreen(DetailListPlayer.this, true, true);
}
} else {
//新版本isIfCurrentIsFullscreen的标志位内部提前设置了,所以不会和手动点击冲突
if (detailPlayer.isIfCurrentIsFullscreen()) {
StandardGSYVideoPlayer.backFromWindowFull(this);
}
if (orientationUtils != null) {
orientationUtils.setEnable(true);
}
}
}
}
private void resolveNormalVideoUI() {
//增加title
detailPlayer.getTitleTextView().setVisibility(View.GONE);
detailPlayer.getTitleTextView().setText("测试视频");
detailPlayer.getBackButton().setVisibility(View.GONE);
}
}
......@@ -26,7 +26,7 @@ public class MainActivity extends AppCompatActivity {
ButterKnife.bind(this);
}
@OnClick({R.id.open_btn, R.id.list_btn, R.id.list_btn_2, R.id.list_detail, R.id.clear_cache, R.id.recycler_2})
@OnClick({R.id.open_btn, R.id.list_btn, R.id.list_btn_2, R.id.list_detail, R.id.clear_cache, R.id.recycler_2, R.id.list_detail_list})
public void onClick(View view) {
switch (view.getId()) {
case R.id.open_btn:
......@@ -48,6 +48,10 @@ public class MainActivity extends AppCompatActivity {
//支持全屏重力旋转的列表播放,滑动后不会被销毁
JumpUtils.goToDetailPlayer(this);
break;
case R.id.list_detail_list:
//支持全屏重力旋转的列表播放,滑动后不会被销毁
JumpUtils.goToDetailListPlayer(this);
break;
case R.id.clear_cache:
GSYVideoManager.clearAllDefaultCache(MainActivity.this);
//String url = "http://baobab.wdjcdn.com/14564977406580.mp4";
......
......@@ -7,6 +7,7 @@ import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.util.Pair;
import android.view.View;
import com.example.gsyvideoplayer.DetailListPlayer;
import com.example.gsyvideoplayer.DetailPlayer;
import com.example.gsyvideoplayer.ListVideo2Activity;
import com.example.gsyvideoplayer.ListVideoActivity;
......@@ -82,4 +83,14 @@ public class JumpUtils {
Intent intent = new Intent(activity, DetailPlayer.class);
activity.startActivity(intent);
}
/**
* 跳转到详情播放
*
* @param activity
*/
public static void goToDetailListPlayer(Activity activity) {
Intent intent = new Intent(activity, DetailListPlayer.class);
activity.startActivity(intent);
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_detail_player"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:id="@+id/post_detail_nested_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="@dimen/post_media_height" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/detail_text"
android:textSize="16sp" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<com.shuyu.gsyvideoplayer.video.ListGSYVideoPlayer
android:id="@+id/detail_player"
android:layout_width="match_parent"
android:layout_height="@dimen/post_media_height" />
</RelativeLayout>
......@@ -49,6 +49,13 @@
android:layout_marginTop="20dp"
android:text="Detail Video2" />
<Button
android:id="@+id/list_detail_list"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Detail List" />
<Button
android:id="@+id/clear_cache"
android:layout_width="120dp"
......
package com.shuyu.gsyvideoplayer.model;
/**
* Created by shuyu on 2016/12/20.
*/
public class GSYVideoModel {
private String mUrl;
private String mTitle;
public GSYVideoModel(String url, String title) {
mUrl = url;
mTitle = title;
}
public String getUrl() {
return mUrl;
}
public void setUrl(String url) {
this.mUrl = url;
}
public String getTitle() {
return mTitle;
}
public void setTitle(String title) {
this.mTitle = title;
}
}
package com.shuyu.gsyvideoplayer.video;
import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import com.shuyu.gsyvideoplayer.model.GSYVideoModel;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
/**
* Created by shuyu on 2016/12/20.
*/
public class ListGSYVideoPlayer extends StandardGSYVideoPlayer {
protected List<GSYVideoModel> mUriList = new ArrayList<>();
protected int mPlayPosition;
public ListGSYVideoPlayer(Context context) {
super(context);
}
public ListGSYVideoPlayer(Context context, AttributeSet attrs) {
super(context, attrs);
}
/**
* 设置播放URL
*
* @param url 播放url
* @param cacheWithPlay 是否边播边缓存
* @param objects object[0]目前为title
* @return
*/
public boolean setUp(List<GSYVideoModel> url, boolean cacheWithPlay, int position, Object... objects) {
mUriList = url;
mPlayPosition = position;
GSYVideoModel gsyVideoModel = url.get(position);
boolean set = setUp(gsyVideoModel.getUrl(), cacheWithPlay, objects);
if (!TextUtils.isEmpty(gsyVideoModel.getTitle())) {
mTitleTextView.setText(gsyVideoModel.getTitle());
}
return set;
}
/**
* 设置播放URL
*
* @param url 播放url
* @param cacheWithPlay 是否边播边缓存
* @param cachePath 缓存路径,如果是M3U8或者HLS,请设置为false
* @param objects object[0]目前为title
* @return
*/
public boolean setUp(List<GSYVideoModel> url, boolean cacheWithPlay, int position, File cachePath, Object... objects) {
mUriList = url;
mPlayPosition = position;
GSYVideoModel gsyVideoModel = url.get(position);
boolean set = setUp(gsyVideoModel.getUrl(), cacheWithPlay, cachePath, objects);
if (!TextUtils.isEmpty(gsyVideoModel.getTitle())) {
mTitleTextView.setText(gsyVideoModel.getTitle());
}
return set;
}
@Override
public GSYBaseVideoPlayer startWindowFullscreen(Context context, boolean actionBar, boolean statusBar) {
GSYBaseVideoPlayer gsyBaseVideoPlayer = super.startWindowFullscreen(context, actionBar, statusBar);
if (gsyBaseVideoPlayer != null) {
ListGSYVideoPlayer listGSYVideoPlayer = (ListGSYVideoPlayer) gsyBaseVideoPlayer;
listGSYVideoPlayer.mPlayPosition = mPlayPosition;
listGSYVideoPlayer.mUriList = mUriList;
GSYVideoModel gsyVideoModel = mUriList.get(mPlayPosition);
if (!TextUtils.isEmpty(gsyVideoModel.getTitle())) {
listGSYVideoPlayer.mTitleTextView.setText(gsyVideoModel.getTitle());
}
}
return gsyBaseVideoPlayer;
}
@Override
public void onCompletion() {
if (mPlayPosition < (mUriList.size() - 1)) {
return;
}
super.onCompletion();
}
@Override
public void onAutoCompletion() {
if (mPlayPosition < (mUriList.size() - 1)) {
mPlayPosition++;
GSYVideoModel gsyVideoModel = mUriList.get(mPlayPosition);
setUp(gsyVideoModel.getUrl(), mCache, mCachePath, mObjects);
if (!TextUtils.isEmpty(gsyVideoModel.getTitle())) {
mTitleTextView.setText(gsyVideoModel.getTitle());
}
startPlayLogic();
return;
}
super.onAutoCompletion();
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册