提交 7b53cba8 authored 作者: 汪显鹏's avatar 汪显鹏

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	app/build.gradle
#	app/src/main/AndroidManifest.xml
#	app/src/main/java/com/ubains/rtspdemo/MainActivity.java
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="JDK" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">
......
package com.ubains.rtspdemo;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.ViewCompat;
import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.WindowManager;
import com.shuyu.gsyvideoplayer.GSYVideoManager;
import com.shuyu.gsyvideoplayer.cache.CacheFactory;
import com.shuyu.gsyvideoplayer.cache.ProxyCacheManager;
import com.shuyu.gsyvideoplayer.model.VideoOptionModel;
import com.shuyu.gsyvideoplayer.player.IjkPlayerManager;
import com.shuyu.gsyvideoplayer.player.PlayerFactory;
import com.shuyu.gsyvideoplayer.utils.GSYVideoType;
import com.shuyu.gsyvideoplayer.utils.OrientationUtils;
import com.ubains.rtspdemo.vedio.EmptyControlVideo;
import java.util.ArrayList;
import java.util.List;
import tv.danmaku.ijk.media.exo2.Exo2PlayerManager;
import tv.danmaku.ijk.media.exo2.ExoPlayerCacheManager;
import tv.danmaku.ijk.media.player.IjkMediaPlayer;
public class EmptyActivity extends AppCompatActivity {
public final static String IMG_TRANSITION = "IMG_TRANSITION";
public final static String TRANSITION = "TRANSITION";
OrientationUtils orientationUtils;
private boolean isTransition;
private android.transition.Transition transition;
private EmptyControlVideo videoPlayer1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_empty);
//保持屏幕常亮
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
videoPlayer1 = findViewById(R.id.detail_player1);
isTransition = getIntent().getBooleanExtra(TRANSITION, false);
init();
}
private void init() {
//EXOPlayer内核,支持格式更多
PlayerFactory.setPlayManager(Exo2PlayerManager.class);
//系统内核模式
//PlayerFactory.setPlayManager(SystemPlayerManager.class);
//ijk内核,默认模式 ijk 模式才支持RTSP 播放
PlayerFactory.setPlayManager(IjkPlayerManager.class);
//exo缓存模式,支持m3u8,只支持exo
// CacheFactory.setCacheManager(ExoPlayerCacheManager.class);
//代理缓存模式,支持所有模式,不支持m3u8等,默认
CacheFactory.setCacheManager(ProxyCacheManager.class);
GSYVideoType.setShowType(GSYVideoType.SCREEN_MATCH_FULL);
GSYVideoType.setRenderType(GSYVideoType.TEXTURE);
List<VideoOptionModel> list = new ArrayList<>();
//设置RTSP 连接方式
VideoOptionModel videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "rtsp_transport", "tcp");
list.add(videoOptionModel);
videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "rtsp_flags", "prefer_tcp");
list.add(videoOptionModel);
//硬解码:1、打开,0、关闭
videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec", 1);
list.add(videoOptionModel);
//软解码:1、打开,0、关闭
videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "videotoolbox", 1);
list.add(videoOptionModel);
//根据媒体类型来配置
videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "allowed_media_types", "video");
list.add(videoOptionModel);
videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "timeout", 20000);
list.add(videoOptionModel);
videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "buffer_size", 1316);
list.add(videoOptionModel);
videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "infbuf", 1); // 无限读
list.add(videoOptionModel);
videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "analyzemaxduration", 100);
list.add(videoOptionModel);
videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "probesize", 4096);
list.add(videoOptionModel);
videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "analyzeduration", "2000000");
list.add(videoOptionModel);
videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "flush_packets", 1);
list.add(videoOptionModel);
// 关闭播放器缓冲,这个必须关闭,否则会出现播放一段时间后,一直卡主,控制台打印 FFP_MSG_BUFFERING_START
videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "packet-buffering", 0);
list.add(videoOptionModel);
GSYVideoManager.instance().setOptionModelList(list);
String url = "rtsp://admin:huawei@123@192.168.11.20/LiveMedia/ch1/Media1";
// String url = "rtsp://192.168.1.234:8556/channel=0";
videoPlayer1.setUp(url, true, "");
videoPlayer1.startPlayLogic();
//过渡动画
//initTransition();
}
@Override
protected void onPause() {
super.onPause();
}
@Override
protected void onResume() {
super.onResume();
}
@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
protected void onDestroy() {
super.onDestroy();
videoPlayer1.release();
if (orientationUtils != null)
orientationUtils.releaseListener();
}
@Override
public void onBackPressed() {
//释放所有
videoPlayer1.setVideoAllCallBack(null);
GSYVideoManager.releaseAllVideos();
if (isTransition && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
super.onBackPressed();
} else {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
finish();
overridePendingTransition(R.anim.abc_fade_in, R.anim.abc_fade_out);
}
}, 500);
}
}
private void initTransition() {
if (isTransition && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
postponeEnterTransition();
ViewCompat.setTransitionName(videoPlayer1, IMG_TRANSITION);
// addTransitionListener();
startPostponedEnterTransition();
} else {
videoPlayer1.startPlayLogic();
}
}
// @TargetApi(Build.VERSION_CODES.LOLLIPOP)
// private boolean addTransitionListener() {
// transition = getWindow().getSharedElementEnterTransition();
// if (transition != null) {
// transition.addListener(new OnTransitionListener(){
// @Override
// public void onTransitionEnd(Transition transition) {
// super.onTransitionEnd(transition);
// videoPlayer.startPlayLogic();
// Transition transition1 = transition.removeListener(this);
// }
// });
// return true;
// }
// return false;
// }
}
package com.ubains.rtspdemo;
import android.os.Build;
import android.os.Bundle;
import android.transition.Explode;
import android.view.Window;
import android.widget.AbsListView;
import android.widget.ListView;
import androidx.appcompat.app.AppCompatActivity;
import com.ubains.rtspdemo.vedio.ListMultiNormalAdapter;
import com.ubains.rtspdemo.vedio.manager.CustomManager;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* 多个同时播放的demo
*/
public class ListMultiVideoActivity extends AppCompatActivity {
ListMultiNormalAdapter listMultiNormalAdapter;
private boolean isPause;
private ListView videoList;
@Override
protected void onCreate(Bundle savedInstanceState) {
// 设置一个exit transition
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
getWindow().setEnterTransition(new Explode());
getWindow().setExitTransition(new Explode());
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_video);
videoList = findViewById(R.id.video_list);
listMultiNormalAdapter = new ListMultiNormalAdapter(this);
videoList.setAdapter(listMultiNormalAdapter);
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 (CustomManager.instance().size() >= 0) {
Map<String, CustomManager> map = CustomManager.instance();
List<String> removeKey = new ArrayList<>();
for (Map.Entry<String, CustomManager> customManagerEntry : map.entrySet()) {
CustomManager customManager = customManagerEntry.getValue();
//当前播放的位置
int position = customManager.getPlayPosition();
//对应的播放列表TAG
if (customManager.getPlayTag().equals(ListMultiNormalAdapter.TAG) && (position < firstVisibleItem || position > lastVisibleItem)) {
CustomManager.releaseAllVideos(customManagerEntry.getKey());
removeKey.add(customManagerEntry.getKey());
}
}
if(removeKey.size() > 0) {
for (String key : removeKey) {
map.remove(key);
}
listMultiNormalAdapter.notifyDataSetChanged();
}
}
}
});
}
@Override
public void onBackPressed() {
if (CustomManager.backFromWindowFull(this, listMultiNormalAdapter.getFullKey())) {
return;
}
super.onBackPressed();
}
@Override
protected void onPause() {
super.onPause();
CustomManager.onPauseAll();
isPause = true;
}
@Override
protected void onResume() {
super.onResume();
CustomManager.onResumeAll();
isPause = false;
}
@Override
protected void onDestroy() {
super.onDestroy();
CustomManager.clearAllVideo();
}
}
package com.ubains.rtspdemo;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Build;
import android.os.Bundle;
import android.transition.Explode;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import com.shuyu.gsyvideoplayer.GSYVideoManager;
import com.shuyu.gsyvideoplayer.cache.CacheFactory;
import com.shuyu.gsyvideoplayer.cache.ProxyCacheManager;
import com.shuyu.gsyvideoplayer.listener.GSYSampleCallBack;
import com.shuyu.gsyvideoplayer.model.VideoOptionModel;
import com.shuyu.gsyvideoplayer.player.IjkPlayerManager;
import com.shuyu.gsyvideoplayer.player.PlayerFactory;
import com.shuyu.gsyvideoplayer.utils.GSYVideoType;
import com.ubains.rtspdemo.vedio.MultiSampleVideo;
import com.ubains.rtspdemo.vedio.manager.CustomManager;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import tv.danmaku.ijk.media.exo2.Exo2PlayerManager;
import tv.danmaku.ijk.media.exo2.ExoPlayerCacheManager;
import tv.danmaku.ijk.media.player.IjkMediaPlayer;
public class MutliActivity extends AppCompatActivity {
MultiSampleVideo videoPlayer1, videoPlayer2, videoPlayer3, videoPlayer4;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//设置全屏
// getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//保持屏幕常亮
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
getWindow().setEnterTransition(new Explode());
getWindow().setExitTransition(new Explode());
}
setContentView(R.layout.activity_mutli);
videoPlayer1 = findViewById(R.id.detail_player1);
videoPlayer2 = findViewById(R.id.detail_player2);
videoPlayer3 = findViewById(R.id.detail_player3);
videoPlayer4 = findViewById(R.id.detail_player4);
init();
}
private void init() {
//EXOPlayer内核,支持格式更多
PlayerFactory.setPlayManager(Exo2PlayerManager.class);
//系统内核模式
//PlayerFactory.setPlayManager(SystemPlayerManager.class);
//ijk内核,默认模式 ijk 模式才支持RTSP 播放
PlayerFactory.setPlayManager(IjkPlayerManager.class);
//exo缓存模式,支持m3u8,只支持exo
// CacheFactory.setCacheManager(ExoPlayerCacheManager.class);
//代理缓存模式,支持所有模式,不支持m3u8等,默认
CacheFactory.setCacheManager(ProxyCacheManager.class);
GSYVideoType.setShowType(GSYVideoType.SCREEN_MATCH_FULL);
GSYVideoType.setRenderType(GSYVideoType.TEXTURE);
List<VideoOptionModel> list = new ArrayList<>();
//设置RTSP 连接方式
VideoOptionModel videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "rtsp_transport", "tcp");
list.add(videoOptionModel);
videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "rtsp_flags", "prefer_tcp");
list.add(videoOptionModel);
//硬解码:1、打开,0、关闭
videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec", 1);
list.add(videoOptionModel);
//软解码:1、打开,0、关闭
videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "videotoolbox", 1);
list.add(videoOptionModel);
//根据媒体类型来配置
videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "allowed_media_types", "video");
list.add(videoOptionModel);
videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "timeout", 20000);
list.add(videoOptionModel);
videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "buffer_size", 1316);
list.add(videoOptionModel);
videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "infbuf", 1); // 无限读
list.add(videoOptionModel);
videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "analyzemaxduration", 100);
list.add(videoOptionModel);
videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "probesize", 4096);
list.add(videoOptionModel);
videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "analyzeduration", "2000000");
list.add(videoOptionModel);
videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "flush_packets", 1);
list.add(videoOptionModel);
// 关闭播放器缓冲,这个必须关闭,否则会出现播放一段时间后,一直卡主,控制台打印 FFP_MSG_BUFFERING_START
videoOptionModel = new VideoOptionModel(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "packet-buffering", 0);
list.add(videoOptionModel);
GSYVideoManager.instance().setOptionModelList(list);
// String url = "rtsp://admin:huawei@123@192.168.11.16/LiveMedia/ch1/Media1";
// String url = "rtsp://admin:huawei@123@192.168.11.16/LiveMedia/ch1/Media2";
// String url = "rtsp://admin:huawei@123@192.168.11.19/LiveMedia/ch1/Media3";
String url = "rtsp://admin:HZ0000001988@192.168.10.26:554/h264/ch3/main/av_stream";
videoPlayer1.setPlayTag("videoPlayer1");
videoPlayer1.setPlayPosition(1);
boolean isPlaying = videoPlayer1.getCurrentPlayer().isInPlayingState();
if (!isPlaying) {
videoPlayer1.setUpLazy(url, false, null, null, "");
}
// videoPlayer1.setRotateViewAuto(true);
// videoPlayer1.setLockLand(true);
// videoPlayer1.setReleaseWhenLossAudio(false);
// videoPlayer1.setShowFullAnimation(true);
// videoPlayer1.setIsTouchWiget(false);
// videoPlayer1.setNeedLockFull(true);
videoPlayer1.startPlayLogic();
// String ur2 = "rtsp://admin:huawei@123@192.168.11.17/LiveMedia/ch1/Media1";
// String ur2 = "rtsp://admin:huawei@123@192.168.11.17/LiveMedia/ch1/Media2";
String ur2 = "rtsp://admin:huawei@123@192.168.11.17/LiveMedia/ch1/Media3";
videoPlayer2.setPlayTag("videoPlayer2");
videoPlayer2.setPlayPosition(2);
boolean isPlaying2 = videoPlayer2.getCurrentPlayer().isInPlayingState();
if (!isPlaying2) {
videoPlayer2.setUpLazy(ur2, false, null, null, "");
}
// videoPlayer2.setRotateViewAuto(true);
// videoPlayer2.setLockLand(true);
// videoPlayer2.setReleaseWhenLossAudio(false);
// videoPlayer2.setShowFullAnimation(true);
// videoPlayer2.setIsTouchWiget(false);
// videoPlayer2.setNeedLockFull(true);
videoPlayer2.startPlayLogic();
// String url3 = "rtsp://admin:huawei@123@192.168.11.19/LiveMedia/ch1/Media1";
// String url3 = "rtsp://admin:huawei@123@192.168.11.19/LiveMedia/ch1/Media2";
// String url3 = "rtsp://admin:HZ0000001988@192.168.10.21:554/h264/ch1/main/av_stream";
String url3 = "rtsp://admin:HZ0000001988@192.168.10.28:554/h264/ch1/main/av_stream";
videoPlayer3.setPlayTag("videoPlayer3");
videoPlayer3.setPlayPosition(3);
boolean isPlaying3 = videoPlayer3.getCurrentPlayer().isInPlayingState();
if (!isPlaying3) {
videoPlayer3.setUpLazy(url3, false, null, null, "");
}
// videoPlayer3.setRotateViewAuto(true);
// videoPlayer3.setLockLand(true);
// videoPlayer3.setReleaseWhenLossAudio(false);
// videoPlayer3.setShowFullAnimation(true);
// videoPlayer3.setIsTouchWiget(false);
// videoPlayer3.setNeedLockFull(true);
videoPlayer3.startPlayLogic();
// String url4 = "rtsp://admin:huawei@123@192.168.11.19/LiveMedia/ch1/Media1";
// String url4 = "rtsp://admin:huawei@123@192.168.11.23/LiveMedia/ch1/Media2";
String url4 = "rtsp://admin:huawei@123@192.168.11.23/LiveMedia/ch1/Media3";
// String url4 = "rtsp://192.168.1.234:8556/channel=0";
videoPlayer4.setPlayTag("videoPlayer4");
videoPlayer4.setPlayPosition(4);
boolean isPlaying4 = videoPlayer4.getCurrentPlayer().isInPlayingState();
if (!isPlaying4) {
videoPlayer4.setUpLazy(url4, false, null, null, "");
}
videoPlayer4.setIsTouchWiget(false);
// videoPlayer4.setRotateViewAuto(true);
// videoPlayer4.setLockLand(true);
// videoPlayer4.setReleaseWhenLossAudio(false);
// videoPlayer4.setShowFullAnimation(true);
// videoPlayer4.setIsTouchWiget(false);
// videoPlayer4.setNeedLockFull(true);
videoPlayer4.startPlayLogic();
}
private boolean isPause;
@Override
protected void onPause() {
super.onPause();
CustomManager.onPauseAll();
isPause = true;
}
@Override
protected void onResume() {
super.onResume();
CustomManager.onResumeAll();
isPause = false;
}
@Override
protected void onDestroy() {
super.onDestroy();
CustomManager.clearAllVideo();
}
}
package com.ubains.rtspdemo.vedio;
import android.content.Context;
import android.util.AttributeSet;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;
import com.ubains.rtspdemo.R;
public class EmptyControlVideo extends StandardGSYVideoPlayer {
public EmptyControlVideo(Context context, Boolean fullFlag) {
super(context, fullFlag);
}
public EmptyControlVideo(Context context) {
super(context);
}
public EmptyControlVideo(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public int getLayoutId() {
return R.layout.empty_video;
}
@Override
protected void touchSurfaceMoveFullLogic(float absDeltaX, float absDeltaY) {
super.touchSurfaceMoveFullLogic(absDeltaX, absDeltaY);
//不给触摸快进,如果需要,屏蔽下方代码即可
mChangePosition = false;
//不给触摸音量,如果需要,屏蔽下方代码即可
mChangeVolume = false;
//不给触摸亮度,如果需要,屏蔽下方代码即可
mBrightness = false;
}
@Override
protected void touchDoubleUp() {
//super.touchDoubleUp();
//不需要双击暂停
}
}
\ No newline at end of file
package com.ubains.rtspdemo.vedio;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import com.shuyu.gsyvideoplayer.listener.GSYSampleCallBack;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;
import com.ubains.rtspdemo.R;
import java.util.ArrayList;
import java.util.List;
/**
* 多个播放的listview adapter
* Created by shuyu on 2016/11/12.
*/
public class ListMultiNormalAdapter extends BaseAdapter {
public static final String TAG = "ListMultiNormalAdapter";
private List<VideoModel> list = new ArrayList<>();
private LayoutInflater inflater = null;
private Context context;
private String fullKey = "null";
public ListMultiNormalAdapter(Context context) {
super();
this.context = context;
inflater = LayoutInflater.from(context);
for (int i = 0; i < 3; i++) {
list.add(new VideoModel());
}
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
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_item_mutli, null);
holder.gsyVideoPlayer = (MultiSampleVideo) convertView.findViewById(R.id.video_item_player);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
final String url = "http://9890.vod.myqcloud.com/9890_4e292f9a3dd011e6b4078980237cc3d3.f20.mp4";
//final String url = "rtsp://admin:huawei@123@192.168.11.21/LiveMedia/ch1/Media1";
//多个播放时必须在setUpLazy、setUp和getGSYVideoManager()等前面设置
holder.gsyVideoPlayer.setPlayTag(TAG);
holder.gsyVideoPlayer.setPlayPosition(position);
boolean isPlaying = holder.gsyVideoPlayer.getCurrentPlayer().isInPlayingState();
if (!isPlaying) {
holder.gsyVideoPlayer.setUpLazy(url, false, null, null, "这是title");
}
//增加title
holder.gsyVideoPlayer.getTitleTextView().setVisibility(View.GONE);
//设置返回键
holder.gsyVideoPlayer.getBackButton().setVisibility(View.GONE);
//设置全屏按键功能
holder.gsyVideoPlayer.getFullscreenButton().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
resolveFullBtn(holder.gsyVideoPlayer);
}
});
holder.gsyVideoPlayer.setRotateViewAuto(true);
holder.gsyVideoPlayer.setLockLand(true);
holder.gsyVideoPlayer.setReleaseWhenLossAudio(false);
holder.gsyVideoPlayer.setShowFullAnimation(true);
holder.gsyVideoPlayer.setIsTouchWiget(false);
holder.gsyVideoPlayer.setNeedLockFull(true);
// if (position % 2 == 0) {
// holder.gsyVideoPlayer.loadCoverImage(url, R.mipmap.ic_launcher);
// } else {
// holder.gsyVideoPlayer.loadCoverImage(url, R.mipmap.ic_launcher);
// }
holder.gsyVideoPlayer.setVideoAllCallBack(new GSYSampleCallBack() {
@Override
public void onQuitFullscreen(String url, Object... objects) {
super.onQuitFullscreen(url, objects);
fullKey = "null";
}
@Override
public void onEnterFullscreen(String url, Object... objects) {
super.onEnterFullscreen(url, objects);
holder.gsyVideoPlayer.getCurrentPlayer().getTitleTextView().setText((String) objects[0]);
fullKey = holder.gsyVideoPlayer.getKey();
}
@Override
public void onAutoComplete(String url, Object... objects) {
super.onAutoComplete(url, objects);
}
});
return convertView;
}
/**
* 全屏幕按键处理
*/
private void resolveFullBtn(final StandardGSYVideoPlayer standardGSYVideoPlayer) {
standardGSYVideoPlayer.startWindowFullscreen(context, false, true);
}
class ViewHolder {
MultiSampleVideo gsyVideoPlayer;
}
public String getFullKey() {
return fullKey;
}
}
package com.ubains.rtspdemo.vedio;
import android.content.Context;
import android.graphics.Point;
import android.media.AudioManager;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.ImageView;
import com.shuyu.gsyvideoplayer.utils.Debuger;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;
import com.shuyu.gsyvideoplayer.video.base.GSYBaseVideoPlayer;
import com.shuyu.gsyvideoplayer.video.base.GSYVideoViewBridge;
import com.ubains.rtspdemo.R;
import com.ubains.rtspdemo.vedio.manager.CustomManager;
/**
* 多个同时播放的播放控件
* Created by guoshuyu on 2018/1/31.
*/
public class MultiSampleVideo extends StandardGSYVideoPlayer {
private final static String TAG = "MultiSampleVideo";
// ImageView mCoverImage;
String mCoverOriginUrl;
int mDefaultRes;
public MultiSampleVideo(Context context, Boolean fullFlag) {
super(context, fullFlag);
}
public MultiSampleVideo(Context context) {
super(context);
}
public MultiSampleVideo(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void init(Context context) {
super.init(context);
// mCoverImage = (ImageView) findViewById(R.id.thumbImage);
if (mThumbImageViewLayout != null &&
(mCurrentState == -1 || mCurrentState == CURRENT_STATE_NORMAL || mCurrentState == CURRENT_STATE_ERROR)) {
mThumbImageViewLayout.setVisibility(VISIBLE);
}
onAudioFocusChangeListener = new AudioManager.OnAudioFocusChangeListener() {
@Override
public void onAudioFocusChange(int focusChange) {
switch (focusChange) {
case AudioManager.AUDIOFOCUS_GAIN:
break;
case AudioManager.AUDIOFOCUS_LOSS:
//todo 判断如果不是外界造成的就不处理
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
//todo 判断如果不是外界造成的就不处理
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
break;
}
}
};
}
@Override
public GSYVideoViewBridge getGSYVideoManager() {
CustomManager.getCustomManager(getKey()).initContext(getContext().getApplicationContext());
return CustomManager.getCustomManager(getKey());
}
@Override
protected boolean backFromFull(Context context) {
return CustomManager.backFromWindowFull(context, getKey());
}
@Override
protected void releaseVideos() {
CustomManager.releaseAllVideos(getKey());
}
@Override
protected int getFullId() {
return CustomManager.FULLSCREEN_ID;
}
@Override
protected int getSmallId() {
return CustomManager.SMALL_ID;
}
@Override
public int getLayoutId() {
return R.layout.video_layout_cover;
}
// public void loadCoverImage(String url, int res) {
// mCoverOriginUrl = url;
// mDefaultRes = res;
// mCoverImage.setBackgroundResource(res);
// }
@Override
public GSYBaseVideoPlayer startWindowFullscreen(Context context, boolean actionBar, boolean statusBar) {
GSYBaseVideoPlayer gsyBaseVideoPlayer = super.startWindowFullscreen(context, actionBar, statusBar);
MultiSampleVideo multiSampleVideo = (MultiSampleVideo) gsyBaseVideoPlayer;
// multiSampleVideo.loadCoverImage(mCoverOriginUrl, mDefaultRes);
return multiSampleVideo;
}
@Override
public GSYBaseVideoPlayer showSmallVideo(Point size, boolean actionBar, boolean statusBar) {
//下面这里替换成你自己的强制转化
MultiSampleVideo multiSampleVideo = (MultiSampleVideo) super.showSmallVideo(size, actionBar, statusBar);
multiSampleVideo.mStartButton.setVisibility(GONE);
multiSampleVideo.mStartButton = null;
return multiSampleVideo;
}
public String getKey() {
if (mPlayPosition == -22) {
Debuger.printfError(getClass().getSimpleName() + " used getKey() " + "******* PlayPosition never set. ********");
}
if (TextUtils.isEmpty(mPlayTag)) {
Debuger.printfError(getClass().getSimpleName() + " used getKey() " + "******* PlayTag never set. ********");
}
return TAG + mPlayPosition + mPlayTag;
}
}
package com.ubains.rtspdemo.vedio;
/**
* Created by shuyu on 2016/11/11.
*/
public class VideoModel {
}
package com.ubains.rtspdemo.vedio.manager;
import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import com.shuyu.gsyvideoplayer.GSYVideoBaseManager;
import com.shuyu.gsyvideoplayer.player.IPlayerManager;
import com.shuyu.gsyvideoplayer.player.IjkPlayerManager;
import com.shuyu.gsyvideoplayer.utils.CommonUtil;
import com.shuyu.gsyvideoplayer.video.base.GSYVideoPlayer;
import com.ubains.rtspdemo.R;
import java.util.HashMap;
import java.util.Map;
import static com.shuyu.gsyvideoplayer.utils.CommonUtil.hideNavKey;
/**
* 多个播放的管理器
* Created by guoshuyu on 2018/1/31.
*/
public class CustomManager extends GSYVideoBaseManager {
public static final int SMALL_ID = R.id.custom_small_id;
public static final int FULLSCREEN_ID = R.id.custom_full_id;
public static String TAG = "GSYVideoManager";
private static Map<String, CustomManager> sMap = new HashMap<>();
public CustomManager() {
init();
}
@Override
protected IPlayerManager getPlayManager() {
return new IjkPlayerManager();
}
/**
* 退出全屏,主要用于返回键
*
* @return 返回是否全屏
*/
@SuppressWarnings("ResourceType")
public static boolean backFromWindowFull(Context context, String key) {
boolean backFrom = false;
ViewGroup vp = (ViewGroup) (CommonUtil.scanForActivity(context)).findViewById(Window.ID_ANDROID_CONTENT);
View oldF = vp.findViewById(FULLSCREEN_ID);
if (oldF != null) {
backFrom = true;
hideNavKey(context);
if (getCustomManager(key).lastListener() != null) {
getCustomManager(key).lastListener().onBackFullscreen();
}
}
return backFrom;
}
/**
* 页面销毁了记得调用是否所有的video
*/
public static void releaseAllVideos(String key) {
if (getCustomManager(key).listener() != null) {
getCustomManager(key).listener().onCompletion();
}
getCustomManager(key).releaseMediaPlayer();
}
/**
* 暂停播放
*/
public void onPause(String key) {
if (getCustomManager(key).listener() != null) {
getCustomManager(key).listener().onVideoPause();
}
}
/**
* 恢复播放
*/
public void onResume(String key) {
if (getCustomManager(key).listener() != null) {
getCustomManager(key).listener().onVideoResume();
}
}
/**
* 恢复暂停状态
*
* @param seek 是否产生seek动作,直播设置为false
*/
public void onResume(String key, boolean seek) {
if (getCustomManager(key).listener() != null) {
getCustomManager(key).listener().onVideoResume(seek);
}
}
/**
* 单例管理器
*/
public static synchronized Map<String, CustomManager> instance() {
return sMap;
}
/**
* 单例管理器
*/
public static synchronized CustomManager getCustomManager(String key) {
if (TextUtils.isEmpty(key)) {
throw new IllegalStateException("key not be empty");
}
CustomManager customManager = sMap.get(key);
if (customManager == null) {
customManager = new CustomManager();
sMap.put(key, customManager);
}
return customManager;
}
public static void onPauseAll() {
if (sMap.size() > 0) {
for (Map.Entry<String, CustomManager> header : sMap.entrySet()) {
header.getValue().onPause(header.getKey());
}
}
}
public static void onResumeAll() {
if (sMap.size() > 0) {
for (Map.Entry<String, CustomManager> header : sMap.entrySet()) {
header.getValue().onResume(header.getKey());
}
}
}
/**
* 恢复暂停状态
*
* @param seek 是否产生seek动作
*/
public static void onResumeAll(boolean seek) {
if (sMap.size() > 0) {
for (Map.Entry<String, CustomManager> header : sMap.entrySet()) {
header.getValue().onResume(header.getKey(), seek);
}
}
}
public static void clearAllVideo() {
if (sMap.size() > 0) {
for (Map.Entry<String, CustomManager> header : sMap.entrySet()) {
CustomManager.releaseAllVideos(header.getKey());
}
}
sMap.clear();
}
public static void removeManager(String key) {
sMap.remove(key);
}
/**
* 当前是否全屏状态
*
* @return 当前是否全屏状态, true代表是。
*/
@SuppressWarnings("ResourceType")
public static boolean isFullState(Activity activity) {
ViewGroup vp = (ViewGroup) (CommonUtil.scanForActivity(activity)).findViewById(Window.ID_ANDROID_CONTENT);
final View full = vp.findViewById(FULLSCREEN_ID);
GSYVideoPlayer gsyVideoPlayer = null;
if (full != null) {
gsyVideoPlayer = (GSYVideoPlayer) full;
}
return gsyVideoPlayer != null;
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.ubains.rtspdemo.vedio.EmptyControlVideo
android:id="@+id/detail_player1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
</RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_list_video"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/video_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<FrameLayout
android:id="@+id/video_full_container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity"> tools:context=".MainActivity">
<com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer <com.ubains.rtspdemo.vedio.EmptyControlVideo
android:id="@+id/detail_player" android:id="@+id/detail_player"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent" />
......
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MutliActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/ll_rtsp1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<com.ubains.rtspdemo.vedio.MultiSampleVideo
android:id="@+id/detail_player1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
<com.ubains.rtspdemo.vedio.MultiSampleVideo
android:id="@+id/detail_player3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_rtsp2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<com.ubains.rtspdemo.vedio.MultiSampleVideo
android:id="@+id/detail_player2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
<com.ubains.rtspdemo.vedio.MultiSampleVideo
android:id="@+id/detail_player4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black">
<FrameLayout
android:id="@+id/surface_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
</FrameLayout>
</RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.ubains.rtspdemo.vedio.MultiSampleVideo
android:id="@+id/video_item_player"
android:layout_width="match_parent"
android:layout_height="200dp" />
</RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black">
<FrameLayout
android:id="@+id/surface_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
</FrameLayout>
</RelativeLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="custom_full_id" type="id" />
<item name="custom_small_id" type="id" />
</resources>
\ No newline at end of file
...@@ -7,7 +7,7 @@ buildscript { ...@@ -7,7 +7,7 @@ buildscript {
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.4.1' classpath 'com.android.tools.build:gradle:3.5.0'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
......
#Sat Jun 22 14:39:40 CST 2019 #Mon Oct 28 16:57:02 CST 2019
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论