Skip to content

Commit

Permalink
初级版本无缝列表到详情
Browse files Browse the repository at this point in the history
  • Loading branch information
CarGuoSmall committed Jun 7, 2018
1 parent 557dab0 commit b009b08
Show file tree
Hide file tree
Showing 18 changed files with 722 additions and 16 deletions.
13 changes: 13 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,24 @@
android:theme="@style/Theme.AppCompat.Translucent"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="portrait" />

<activity
android:name=".simple.SimpleActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="portrait" />

<activity
android:name=".switchplay.SwitchListVideoActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="@style/Theme.AppCompat.Translucent"
android:screenOrientation="portrait" />

<activity
android:name=".switchplay.SwitchDetailActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="@style/Theme.AppCompat.Translucent"
android:screenOrientation="portrait" />

<meta-data
android:name="android.max_aspect"
android:value="2.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis

@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, R.id.recycler_2, R.id.list_detail_list, R.id.web_detail, R.id.danmaku_video, R.id.fragment_video,
R.id.more_type, R.id.input_type, R.id.open_btn_empty, R.id.open_control, R.id.open_filter, R.id.open_btn_pick, R.id.open_btn_auto, R.id.open_scroll, R.id.open_window, R.id.open_btn_ad,
R.id.open_btn_multi, R.id.open_btn_ad2, R.id.open_list_ad, R.id.open_custom_exo, R.id.open_simple})
R.id.open_btn_multi, R.id.open_btn_ad2, R.id.open_list_ad, R.id.open_custom_exo, R.id.open_simple, R.id.open_switch})
public void onClick(View view) {
switch (view.getId()) {
case R.id.open_simple:
Expand Down Expand Up @@ -154,6 +154,9 @@ public void onClick(View view) {
//多个同时播放
JumpUtils.goToDetailExoListPlayer(this);
break;
case R.id.open_switch:
JumpUtils.goToSwitch(this);
break;
case R.id.clear_cache:
//清理缓存
GSYVideoManager.instance().clearAllDefaultCache(MainActivity.this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import android.widget.ListView;

import com.example.gsyvideoplayer.R;
import com.example.gsyvideoplayer.simple.adapter.SimpleListVideoModelAdapter;
import com.example.gsyvideoplayer.simple.adapter.SimpleListVideoModeAdapter;
import com.shuyu.gsyvideoplayer.GSYVideoManager;

/**
Expand All @@ -16,7 +16,7 @@ public class SimpleListVideoActivityMode1 extends AppCompatActivity {

ListView videoList;

SimpleListVideoModelAdapter listNormalAdapter;
SimpleListVideoModeAdapter listNormalAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -25,7 +25,7 @@ protected void onCreate(Bundle savedInstanceState) {

videoList = (ListView)findViewById(R.id.video_list);

listNormalAdapter = new SimpleListVideoModelAdapter(this);
listNormalAdapter = new SimpleListVideoModeAdapter(this);
videoList.setAdapter(listNormalAdapter);

videoList.setOnScrollListener(new AbsListView.OnScrollListener() {
Expand All @@ -41,7 +41,7 @@ public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCoun
//当前播放的位置
int position = GSYVideoManager.instance().getPlayPosition();
//对应的播放列表TAG
if (GSYVideoManager.instance().getPlayTag().equals(SimpleListVideoModelAdapter.TAG)
if (GSYVideoManager.instance().getPlayTag().equals(SimpleListVideoModeAdapter.TAG)
&& (position < firstVisibleItem || position > lastVisibleItem)) {
if(GSYVideoManager.isFullState(SimpleListVideoActivityMode1.this)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import android.widget.RelativeLayout;

import com.example.gsyvideoplayer.R;
import com.example.gsyvideoplayer.simple.adapter.SimpleListVideoModel2Adapter;
import com.example.gsyvideoplayer.simple.adapter.SimpleListVideoMode2Adapter;
import com.shuyu.gsyvideoplayer.GSYVideoManager;
import com.shuyu.gsyvideoplayer.listener.GSYSampleCallBack;
import com.shuyu.gsyvideoplayer.utils.CommonUtil;
Expand All @@ -26,7 +26,7 @@ public class SimpleListVideoActivityMode2 extends AppCompatActivity {

GSYVideoHelper smallVideoHelper;

SimpleListVideoModel2Adapter listVideoAdapter;
SimpleListVideoMode2Adapter listVideoAdapter;

GSYVideoHelper.GSYVideoHelperBuilder gsySmallVideoHelperBuilder;

Expand Down Expand Up @@ -59,7 +59,7 @@ protected void onCreate(Bundle savedInstanceState) {
public void onQuitSmallWidget(String url, Object... objects) {
super.onQuitSmallWidget(url, objects);
//大于0说明有播放,//对应的播放列表TAG
if (smallVideoHelper.getPlayPosition() >= 0 && smallVideoHelper.getPlayTAG().equals(SimpleListVideoModel2Adapter.TAG)) {
if (smallVideoHelper.getPlayPosition() >= 0 && smallVideoHelper.getPlayTAG().equals(SimpleListVideoMode2Adapter.TAG)) {
//当前播放的位置
int position = smallVideoHelper.getPlayPosition();
//不可视的是时候
Expand All @@ -75,7 +75,7 @@ public void onQuitSmallWidget(String url, Object... objects) {

smallVideoHelper.setGsyVideoOptionBuilder(gsySmallVideoHelperBuilder);

listVideoAdapter = new SimpleListVideoModel2Adapter(this, smallVideoHelper, gsySmallVideoHelperBuilder);
listVideoAdapter = new SimpleListVideoMode2Adapter(this, smallVideoHelper, gsySmallVideoHelperBuilder);
listVideoAdapter.setRootView(activityListVideo);
videoList.setAdapter(listVideoAdapter);

Expand All @@ -89,7 +89,7 @@ public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCoun
SimpleListVideoActivityMode2.this.firstVisibleItem = firstVisibleItem;
lastVisibleItem = firstVisibleItem + visibleItemCount;
//大于0说明有播放,//对应的播放列表TAG
if (smallVideoHelper.getPlayPosition() >= 0 && smallVideoHelper.getPlayTAG().equals(SimpleListVideoModel2Adapter.TAG)) {
if (smallVideoHelper.getPlayPosition() >= 0 && smallVideoHelper.getPlayTAG().equals(SimpleListVideoMode2Adapter.TAG)) {
//当前播放的位置
int position = smallVideoHelper.getPlayPosition();
//不可视的是时候
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.ArrayList;
import java.util.List;

public class SimpleListVideoModel2Adapter extends BaseAdapter {
public class SimpleListVideoMode2Adapter extends BaseAdapter {

public final static String TAG = "TT22";

Expand All @@ -34,7 +34,7 @@ public class SimpleListVideoModel2Adapter extends BaseAdapter {

private GSYVideoHelper.GSYVideoHelperBuilder gsySmallVideoHelperBuilder;

public SimpleListVideoModel2Adapter(Context context, GSYVideoHelper smallVideoHelper, GSYVideoHelper.GSYVideoHelperBuilder gsySmallVideoHelperBuilder) {
public SimpleListVideoMode2Adapter(Context context, GSYVideoHelper smallVideoHelper, GSYVideoHelper.GSYVideoHelperBuilder gsySmallVideoHelperBuilder) {
super();
this.context = context;
this.smallVideoHelper = smallVideoHelper;
Expand Down Expand Up @@ -67,7 +67,7 @@ public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.list_video_simple_model2, null);
convertView = inflater.inflate(R.layout.list_video_simple_mode2, null);
holder.videoContainer = (FrameLayout) convertView.findViewById(R.id.list_item_container);
holder.playerBtn = (ImageView) convertView.findViewById(R.id.list_item_btn);
holder.imageView = new ImageView(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.util.ArrayList;
import java.util.List;

public class SimpleListVideoModelAdapter extends BaseAdapter {
public class SimpleListVideoModeAdapter extends BaseAdapter {

public static final String TAG = "ListNormalAdapter22";

Expand All @@ -31,7 +31,7 @@ public class SimpleListVideoModelAdapter extends BaseAdapter {

protected boolean isFull;

public SimpleListVideoModelAdapter(Context context) {
public SimpleListVideoModeAdapter(Context context) {
super();
this.context = context;
inflater = LayoutInflater.from(context);
Expand Down Expand Up @@ -61,7 +61,7 @@ public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.list_video_simple_model1, null);
convertView = inflater.inflate(R.layout.list_video_simple_mode1, null);
holder.gsyVideoPlayer = (SampleCoverVideo) convertView.findViewById(R.id.video_item_player);
convertView.setTag(holder);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package com.example.gsyvideoplayer.switchplay;

import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;

import com.example.gsyvideoplayer.R;
import com.shuyu.gsyvideoplayer.GSYVideoManager;
import com.shuyu.gsyvideoplayer.builder.GSYVideoOptionBuilder;
import com.shuyu.gsyvideoplayer.listener.GSYSampleCallBack;
import com.shuyu.gsyvideoplayer.listener.LockClickListener;
import com.shuyu.gsyvideoplayer.utils.OrientationUtils;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;

/**
* 切换详情
*/
public class SwitchDetailActivity extends AppCompatActivity {

public static final String URL = "url";

SwitchVideo detailPlayer;

private boolean isPlay = true;
private boolean isPause;

private OrientationUtils orientationUtils;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.switch_activity_detail_player);

detailPlayer = (SwitchVideo) findViewById(R.id.detail_player);


//增加title
detailPlayer.getTitleTextView().setVisibility(View.GONE);
detailPlayer.getBackButton().setVisibility(View.GONE);

//外部辅助的旋转,帮助全屏
orientationUtils = new OrientationUtils(this, detailPlayer);
//初始化不打开外部的旋转
orientationUtils.setEnable(false);

SwitchUtil.optionPlayer(detailPlayer, getIntent().getStringExtra(URL), true, "这是title");

SwitchUtil.clonePlayState(detailPlayer);

detailPlayer.setIsTouchWiget(true);

detailPlayer.setVideoAllCallBack(new GSYSampleCallBack() {
@Override
public void onPrepared(String url, Object... objects) {
super.onPrepared(url, objects);
//开始播放了才能旋转和全屏
orientationUtils.setEnable(true);
}

@Override
public void onQuitFullscreen(String url, Object... objects) {
super.onQuitFullscreen(url, objects);
if (orientationUtils != null) {
orientationUtils.backToProtVideo();
}
}
});

detailPlayer.getFullscreenButton().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//直接横屏
orientationUtils.resolveByClick();
//第一个true是否需要隐藏actionbar,第二个true是否需要隐藏statusbar
detailPlayer.startWindowFullscreen(SwitchDetailActivity.this, true, true);
}
});

detailPlayer.setSurfaceToPlay();
}

@Override
public void onBackPressed() {
if (orientationUtils != null) {
orientationUtils.backToProtVideo();
}
if (GSYVideoManager.backFromWindowFull(this)) {
return;
}
super.onBackPressed();
}


@Override
protected void onPause() {
detailPlayer.getCurrentPlayer().onVideoPause();
super.onPause();
isPause = true;
}

@Override
protected void onResume() {
detailPlayer.getCurrentPlayer().onVideoResume(false);
super.onResume();
isPause = false;
}

@Override
protected void onDestroy() {
super.onDestroy();
detailPlayer.getGSYVideoManager().setListener(detailPlayer.getGSYVideoManager().lastListener());
detailPlayer.getGSYVideoManager().setLastListener(null);
GSYVideoManager.releaseAllVideos();
if (orientationUtils != null)
orientationUtils.releaseListener();

SwitchUtil.release();
}



@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
//如果旋转了就全屏
if (isPlay && !isPause) {
detailPlayer.onConfigurationChanged(this, newConfig, orientationUtils, true, true);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.example.gsyvideoplayer.switchplay;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.AbsListView;
import android.widget.ListView;

import com.example.gsyvideoplayer.R;
import com.example.gsyvideoplayer.simple.adapter.SimpleListVideoModeAdapter;
import com.shuyu.gsyvideoplayer.GSYVideoManager;

/**
* 可切换列表
*/
public class SwitchListVideoActivity extends AppCompatActivity {

ListView videoList;

SwitchListVideoAdapter listNormalAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_video);

videoList = (ListView)findViewById(R.id.video_list);

listNormalAdapter = new SwitchListVideoAdapter(this);
videoList.setAdapter(listNormalAdapter);

videoList.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}

@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
int lastVisibleItem = firstVisibleItem + visibleItemCount;
//大于0说明有播放
if (GSYVideoManager.instance().getPlayPosition() >= 0) {
//当前播放的位置
int position = GSYVideoManager.instance().getPlayPosition();
//对应的播放列表TAG
if (GSYVideoManager.instance().getPlayTag().equals(SwitchListVideoAdapter.TAG)
&& (position < firstVisibleItem || position > lastVisibleItem)) {
if(GSYVideoManager.isFullState(SwitchListVideoActivity.this)) {
return;
}
//如果滑出去了上面和下面就是否,和今日头条一样
GSYVideoManager.releaseAllVideos();
listNormalAdapter.notifyDataSetChanged();
}
}
}
});

}

@Override
public void onBackPressed() {
if (GSYVideoManager.backFromWindowFull(this)) {
return;
}
super.onBackPressed();
}

@Override
protected void onPause() {
super.onPause();
//GSYVideoManager.onPause();
}

@Override
protected void onResume() {
super.onResume();
//GSYVideoManager.onResume();
}

@Override
protected void onDestroy() {
super.onDestroy();
GSYVideoManager.releaseAllVideos();
}
}
Loading

0 comments on commit b009b08

Please sign in to comment.