diff --git a/app/src/main/java/com/shayu/phonelive/activity/LauncherActivity.java b/app/src/main/java/com/shayu/phonelive/activity/LauncherActivity.java index 0ea9f193a..d9ba9829d 100644 --- a/app/src/main/java/com/shayu/phonelive/activity/LauncherActivity.java +++ b/app/src/main/java/com/shayu/phonelive/activity/LauncherActivity.java @@ -33,6 +33,14 @@ import androidx.core.app.NotificationManagerCompat; import com.alibaba.android.arouter.facade.annotation.Route; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.blankj.utilcode.util.LogUtils; +import com.google.android.exoplayer2.ExoPlayer; +import com.google.android.exoplayer2.MediaItem; +import com.google.android.exoplayer2.PlaybackException; +import com.google.android.exoplayer2.Player; +import com.google.android.exoplayer2.ui.AspectRatioFrameLayout; +import com.google.android.exoplayer2.ui.StyledPlayerView; +import com.google.android.exoplayer2.video.VideoSize; import com.shayu.phonelive.AppContext; import com.tencent.rtmp.ITXLivePlayListener; import com.tencent.rtmp.TXLiveBase; @@ -106,12 +114,13 @@ public class LauncherActivity extends AppCompatActivity implements View.OnClickL private int mInterval = 2000; private View mBtnSkipImage; private View mBtnSkipVideo; - private TXCloudVideoView mTXCloudVideoView; - private TXLivePlayer mPlayer; private LauncherAdViewHolder mLauncherAdViewHolder; private boolean mPaused; private int mVideoLastProgress; private boolean mForward; + private StyledPlayerView mPlayerView; + private ExoPlayer mPlayerForExo; + @Override public Resources getResources() { @@ -183,6 +192,7 @@ public class LauncherActivity extends AppCompatActivity implements View.OnClickL //解压后的文件数量必须要有2个 //如果文件存在,解压后 文件数量一致,直接进入下一步 if (fileSo.exists() && getFileCount(fileSoList.getAbsolutePath()) == 2){ + mHandler.sendEmptyMessageDelayed(WHAT_GET_CONFIG, 1000); return; } // https://downs.yaoulive.com/androidLibs/t3/faceunity2-so-arm64-v8a.zip @@ -523,6 +533,9 @@ public class LauncherActivity extends AppCompatActivity implements View.OnClickL @Override protected void onDestroy() { + if (mPlayerForExo != null) { + mPlayerForExo.release(); + } EventBus.getDefault().unregister(this); if (mHandler != null) { mHandler.removeCallbacksAndMessages(null); @@ -602,11 +615,6 @@ public class LauncherActivity extends AppCompatActivity implements View.OnClickL } private void releaseVideo() { - if (mPlayer != null) { - mPlayer.stopPlay(false); - mPlayer.setPlayListener(null); - } - mPlayer = null; } @Override @@ -685,20 +693,16 @@ public class LauncherActivity extends AppCompatActivity implements View.OnClickL @Override protected void onPause() { mPaused = true; - if (mPlayer != null && mPlayer.isPlaying()) { - mPlayer.setMute(true); + if (mPlayerForExo != null) { + mPlayerForExo.pause(); } + super.onPause(); } @Override protected void onResume() { super.onResume(); - if (mPaused) { - if (mPlayer != null && mPlayer.isPlaying()) { - mPlayer.setMute(false); - } - } mPaused = false; } @@ -733,7 +737,9 @@ public class LauncherActivity extends AppCompatActivity implements View.OnClickL if (mBtnSkipVideo != null && mBtnSkipVideo.getVisibility() != View.VISIBLE) { mBtnSkipVideo.setVisibility(View.VISIBLE); } - mTXCloudVideoView = new TXCloudVideoView(mContext); + checkUidAndToken(); + + /* mTXCloudVideoView = new TXCloudVideoView(mContext); mTXCloudVideoView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); mTXCloudVideoView.setRenderMode(TXLiveConstants.RENDER_MODE_FULL_FILL_SCREEN); mContainer.addView(mTXCloudVideoView); @@ -789,6 +795,58 @@ public class LauncherActivity extends AppCompatActivity implements View.OnClickL }); mPlayer.startPlay(videoFile.getAbsolutePath(), TXLivePlayer.PLAY_TYPE_LOCAL_VIDEO); +*/ + /* mPlayerForExo.addListener(new Player.Listener() { + @Override + public void onIsPlayingChanged(boolean isPlaying) { + Player.Listener.super.onIsPlayingChanged(isPlaying); + } + @Override + public void onPlaybackStateChanged(int playbackState) { + Player.Listener.super.onPlaybackStateChanged(playbackState); + if (playbackState == Player.STATE_ENDED) { + // 播放完成的处理逻辑 + checkUidAndToken(); + } + + } + + @Override + public void onVideoSizeChanged(VideoSize videoSize) { + Player.Listener.super.onVideoSizeChanged(videoSize); + Bundle bundle = new Bundle(); + bundle.putInt("EVT_PARAM1", videoSize.width); + bundle.putInt("EVT_PARAM2", videoSize.height); + } + + @Override + public void onRenderedFirstFrame() { + Player.Listener.super.onRenderedFirstFrame(); + } + + @Override + public void onPlayerError(PlaybackException error) { + Player.Listener.super.onPlayerError(error); + LogUtils.e(error); + } + + @Override + public void onPlayerErrorChanged(@Nullable PlaybackException error) { + Player.Listener.super.onPlayerErrorChanged(error); + LogUtils.e(error); + } + }); + mPlayerView.setPlayer(mPlayerForExo);*/ + + + /* mPlayerView = new StyledPlayerView(mContext); + mPlayerView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); + mContainer.addView(mPlayerView); + // 准备媒体项并开始播放 + MediaItem mediaItem = MediaItem.fromUri(videoFile.getAbsolutePath()); + mPlayerForExo.setMediaItem(mediaItem); + mPlayerForExo.prepare(); + mPlayerForExo.play();*/ } @Subscribe(threadMode = ThreadMode.MAIN) @@ -803,4 +861,5 @@ public class LauncherActivity extends AppCompatActivity implements View.OnClickL this.finish(); } } + }