|
@@ -1,281 +0,0 @@
|
|
|
-package com.tencent.liteav.demo.player;
|
|
|
-
|
|
|
-import static android.view.View.GONE;
|
|
|
-import static android.view.View.VISIBLE;
|
|
|
-
|
|
|
-import android.app.Activity;
|
|
|
-import android.content.Intent;
|
|
|
-import android.os.Bundle;
|
|
|
-import android.util.Log;
|
|
|
-import android.view.View;
|
|
|
-import android.view.ViewGroup;
|
|
|
-import android.view.WindowInsets;
|
|
|
-import android.view.WindowManager;
|
|
|
-import android.widget.ImageView;
|
|
|
-import android.widget.LinearLayout;
|
|
|
-import android.widget.RelativeLayout;
|
|
|
-import android.widget.TextView;
|
|
|
-
|
|
|
-import androidx.annotation.Nullable;
|
|
|
-import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
-import androidx.recyclerview.widget.RecyclerView;
|
|
|
-
|
|
|
-import com.tencent.liteav.demo.player.databinding.ActivityPlayerBinding;
|
|
|
-import com.tencent.liteav.demo.player.ui.PlayerListAdapter;
|
|
|
-import com.tencent.liteav.demo.player.ui.PlayerListDecoration;
|
|
|
-import com.tencent.liteav.demo.player.util.PlayerModelProvider;
|
|
|
-import com.tencent.liteav.demo.superplayer.SuperPlayerDef;
|
|
|
-import com.tencent.liteav.demo.superplayer.SuperPlayerGlobalConfig;
|
|
|
-import com.tencent.liteav.demo.superplayer.SuperPlayerModel;
|
|
|
-import com.tencent.liteav.demo.superplayer.SuperPlayerView;
|
|
|
-import com.tencent.liteav.demo.superplayer.ui.view.PlayerRelativeLayout;
|
|
|
-import com.tencent.rtmp.TXLiveConstants;
|
|
|
-
|
|
|
-/**
|
|
|
- * Created by liyuejiao on 2018/7/3.
|
|
|
- * 超级播放器主Activity
|
|
|
- */
|
|
|
-
|
|
|
-public class PlayerActivity extends Activity implements View.OnClickListener,
|
|
|
- SuperPlayerView.OnSuperPlayerViewCallback,
|
|
|
- PlayerListAdapter.OnItemClickListener {
|
|
|
-
|
|
|
- private static final String TAG = "SuperPlayerActivity";
|
|
|
-
|
|
|
- private static final float sPlayerViewDisplayRatio = (float) 720 / 1280; //当前界面播放器view展示的宽高比,用主流的16:9
|
|
|
-
|
|
|
- private View activityLayout;
|
|
|
-
|
|
|
- private LinearLayout mLayoutTopBar;
|
|
|
- private RelativeLayout mLayoutList;
|
|
|
- private PlayerRelativeLayout mLayoutPlayer;
|
|
|
-
|
|
|
- private ImageView mImageBack;
|
|
|
- private TextView mTextTitle;
|
|
|
-
|
|
|
- private ImageView mImageLock;
|
|
|
- private ImageView mImageMenu;
|
|
|
-
|
|
|
- private SuperPlayerView mSuperPlayerView;
|
|
|
- private RecyclerView mVodPlayerListView;
|
|
|
-
|
|
|
- private PlayerListAdapter mVodPlayerListAdapter;
|
|
|
-
|
|
|
- private boolean mIsManualPause = false;
|
|
|
-
|
|
|
- private ViewInsets.ViewportMetrics viewInsets = new ViewInsets.ViewportMetrics();
|
|
|
-
|
|
|
- private int currentIndex = -1;
|
|
|
-
|
|
|
- private ActivityPlayerBinding binding;
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
- super.onCreate(savedInstanceState);
|
|
|
- binding = ActivityPlayerBinding.inflate(getLayoutInflater());
|
|
|
- setContentView(binding.getRoot());
|
|
|
-
|
|
|
- getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
|
|
- initView();
|
|
|
- initData();
|
|
|
-
|
|
|
- updateList();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onBackPressed() {
|
|
|
- if (isFullScreen) {
|
|
|
- mSuperPlayerView.switchPlayMode(SuperPlayerDef.PlayerMode.WINDOW);
|
|
|
- } else {
|
|
|
- super.onBackPressed();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 以16:9 比例显示播放器view,优先保证宽度完全填充
|
|
|
- */
|
|
|
- private void adjustSuperPlayerViewAndMaskHeight() {
|
|
|
- final int screenWidth = getWindowManager().getDefaultDisplay().getWidth();
|
|
|
- ViewGroup.LayoutParams layoutParams = mSuperPlayerView.getLayoutParams();
|
|
|
- layoutParams.width = screenWidth;
|
|
|
- layoutParams.height = (int) (screenWidth * sPlayerViewDisplayRatio);
|
|
|
- mSuperPlayerView.setLayoutParams(layoutParams);
|
|
|
-
|
|
|
- getWindow().getDecorView().setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
|
|
|
- @Override
|
|
|
- public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
|
|
|
- WindowInsets newInsets = insets;
|
|
|
- viewInsets = ViewInsets.applyWindowInsets(PlayerActivity.this, insets);
|
|
|
- setPadding();
|
|
|
- return newInsets;
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- private void initView() {
|
|
|
- activityLayout = findViewById(R.id.superplayer_activity);
|
|
|
-
|
|
|
- mLayoutTopBar = (LinearLayout) findViewById(R.id.superplayer_tc_action_bar);
|
|
|
- mLayoutList = (RelativeLayout) findViewById(R.id.superplayer_rb_list);
|
|
|
- mLayoutPlayer = (PlayerRelativeLayout) findViewById(R.id.superplayer_bl_player);
|
|
|
-
|
|
|
- mImageBack = (ImageView) findViewById(R.id.superplayer_tc_back);
|
|
|
- mImageBack.setOnClickListener(this);
|
|
|
-
|
|
|
- mTextTitle = (TextView) findViewById(R.id.superplayer_tc_url);
|
|
|
- mTextTitle.setOnClickListener(this);
|
|
|
-
|
|
|
- mImageLock = (ImageView) findViewById(R.id.superplayer_tc_lock);
|
|
|
- mImageLock.setOnClickListener(this);
|
|
|
-
|
|
|
- mImageMenu = (ImageView) findViewById(R.id.superplayer_tc_menu);
|
|
|
- mImageMenu.setOnClickListener(this);
|
|
|
-
|
|
|
- mSuperPlayerView = (SuperPlayerView) findViewById(R.id.superVodPlayerView);
|
|
|
- mSuperPlayerView.setPlayerViewCallback(this);
|
|
|
-
|
|
|
- mVodPlayerListView = (RecyclerView) findViewById(R.id.superplayer_recycler_view);
|
|
|
- mVodPlayerListView.setLayoutManager(new LinearLayoutManager(this));
|
|
|
- mVodPlayerListAdapter = new PlayerListAdapter(this);
|
|
|
- mVodPlayerListAdapter.setOnItemClickListener(this);
|
|
|
- mVodPlayerListView.setAdapter(mVodPlayerListAdapter);
|
|
|
- mVodPlayerListView.addItemDecoration(new PlayerListDecoration());
|
|
|
-
|
|
|
- binding.superplayerTcVerify.setOnClickListener(this);
|
|
|
- adjustSuperPlayerViewAndMaskHeight();
|
|
|
- }
|
|
|
-
|
|
|
- private void initData() {
|
|
|
- initSuperVodGlobalSetting();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 初始化超级播放器全局配置
|
|
|
- */
|
|
|
- private void initSuperVodGlobalSetting() {
|
|
|
- SuperPlayerGlobalConfig prefs = SuperPlayerGlobalConfig.getInstance();
|
|
|
- prefs.maxCacheItem = 5;
|
|
|
- prefs.enableHWAcceleration = true;
|
|
|
- prefs.renderMode = TXLiveConstants.RENDER_MODE_ADJUST_RESOLUTION;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onResume() {
|
|
|
- super.onResume();
|
|
|
- if (mSuperPlayerView.getPlayerState() == SuperPlayerDef.PlayerState.PLAYING
|
|
|
- || mSuperPlayerView.getPlayerState() == SuperPlayerDef.PlayerState.PAUSE) {
|
|
|
- Log.i(TAG, "onResume state :" + mSuperPlayerView.getPlayerState());
|
|
|
- if (!mIsManualPause) {
|
|
|
- mSuperPlayerView.onResume();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- mSuperPlayerView.setNeedToPause(false);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onPause() {
|
|
|
- super.onPause();
|
|
|
- Log.i(TAG, "onPause state :" + mSuperPlayerView.getPlayerState());
|
|
|
-
|
|
|
- mIsManualPause = mSuperPlayerView.getPlayerState() == SuperPlayerDef.PlayerState.PAUSE;
|
|
|
- mSuperPlayerView.onPause();
|
|
|
- mSuperPlayerView.setNeedToPause(true);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- protected void onDestroy() {
|
|
|
- super.onDestroy();
|
|
|
- mSuperPlayerView.release();
|
|
|
- mSuperPlayerView.resetPlayer();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onItemClick(SuperPlayerModel videoModel, int index) {
|
|
|
- playVideoModel(index);
|
|
|
- }
|
|
|
-
|
|
|
- private void playVideoModel(int index) {
|
|
|
- mSuperPlayerView.playWithModelList(PlayerModelProvider.getList(), false, index);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- int id = v.getId();
|
|
|
- if (id == R.id.superplayer_tc_back) {
|
|
|
- finish();
|
|
|
- } else if (id == R.id.superplayer_tc_lock) {
|
|
|
- mSuperPlayerView.switchPlayMode(SuperPlayerDef.PlayerMode.FULLSCREEN);
|
|
|
- } else if (id == R.id.superplayer_tc_menu) {
|
|
|
- PlayerMenu.start(PlayerActivity.this, "");
|
|
|
- } else if (id == binding.superplayerTcVerify.getId()) {
|
|
|
- PlayerVerify.start(PlayerActivity.this);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void updateList() {
|
|
|
- mVodPlayerListAdapter.clear();
|
|
|
-
|
|
|
- for (SuperPlayerModel videoModel : PlayerModelProvider.getList()) {
|
|
|
- mVodPlayerListAdapter.addSuperPlayerModel(videoModel);
|
|
|
- }
|
|
|
-
|
|
|
- mSuperPlayerView.playWithModelList(PlayerModelProvider.getList(), false, 0);
|
|
|
- }
|
|
|
-
|
|
|
- private boolean isFullScreen = false;
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onStartFullScreenPlay() {
|
|
|
- // 隐藏其他元素实现全屏
|
|
|
- mLayoutPlayer.onFullScreenMode();
|
|
|
- mLayoutTopBar.setVisibility(GONE);
|
|
|
- mLayoutList.setVisibility(GONE);
|
|
|
- isFullScreen = true;
|
|
|
- setPadding();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onStopFullScreenPlay() {
|
|
|
- // 恢复原有元素
|
|
|
- mLayoutPlayer.onWindowMode();
|
|
|
- mLayoutTopBar.setVisibility(VISIBLE);
|
|
|
- mLayoutList.setVisibility(VISIBLE);
|
|
|
- isFullScreen = false;
|
|
|
- setPadding();
|
|
|
- }
|
|
|
-
|
|
|
- private void setPadding() {
|
|
|
- if (!isFullScreen) {
|
|
|
- activityLayout.setPadding(
|
|
|
- viewInsets.viewPaddingLeft,
|
|
|
- viewInsets.viewPaddingTop,
|
|
|
- viewInsets.viewPaddingRight,
|
|
|
- viewInsets.viewPaddingBottom
|
|
|
- );
|
|
|
- } else {
|
|
|
- activityLayout.setPadding(0, 0, 0, 0);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onPlaying() {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onPlayIndex(int index, SuperPlayerModel model) {
|
|
|
- mVodPlayerListAdapter.setIndex(index);
|
|
|
- ((LinearLayoutManager) mVodPlayerListView.getLayoutManager()).scrollToPositionWithOffset(index * 200, 0);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onPlayEnd() {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onError(int code) {
|
|
|
-
|
|
|
- }
|
|
|
-}
|