提交 b4f04064 authored 作者: kongdywang's avatar kongdywang

fix the issue of black screen appearing in pip window on some devices & pip…

fix the issue of black screen appearing in pip window on some devices & pip window can adjust window radio by video radio
上级 393292ea
......@@ -10,10 +10,10 @@
android:supportsPictureInPicture="true"
android:screenOrientation="portrait"
android:excludeFromRecents="true"
android:configChanges="orientation|keyboardHidden|screenSize|smallestScreenSize|screenLayout"
android:exported="true"
android:resizeableActivity="true"
android:launchMode="singleTask"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:resizeableActivity="true"
android:windowSoftInputMode="stateHidden"
tools:ignore="UnusedAttribute" >
<intent-filter>
......
......@@ -23,6 +23,8 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.Log;
import android.util.Rational;
import androidx.annotation.RequiresApi;
import com.tencent.vod.flutter.model.PipResult;
import com.tencent.vod.flutter.model.VideoModel;
......@@ -261,6 +263,8 @@ public class FTXPIPManager {
private final boolean mIsNeedPlayControl;
private boolean mIsPlaying = false;
private float mCurrentPlayTime = 0;
private int mViewWith = 16;
private int mViewHeight = 9;
/**
* 画中画参数
......@@ -334,6 +338,19 @@ public class FTXPIPManager {
this.mCurrentPlayTime = mCurrentPlayTime;
}
public void setRadio(int width, int height) {
mViewWith = width;
mViewHeight = height;
}
public int geiRadioWith() {
return mViewWith;
}
public int getRadioHeight() {
return mViewHeight;
}
/**
* 构造画中画参数
*/
......@@ -382,6 +399,11 @@ public class FTXPIPManager {
Builder mPipParams = new Builder();
mPipParams.setActions(actions);
mPipParams.setAspectRatio(new Rational(mViewWith, mViewHeight));
if (Build.VERSION.SDK_INT >= VERSION_CODES.S) {
mPipParams.setAutoEnterEnabled(false);
mPipParams.setSeamlessResizeEnabled(false);
}
return mPipParams.build();
}
......
......@@ -651,6 +651,9 @@ public class FTXVodPlayer extends FTXBasePlayer implements ITXVodPlayListener, F
getPlayerId());
mPipParams.setIsPlaying(isPlayerPlaying());
mPipParams.setCurrentPlayTime(getPlayerCurrentPlaybackTime());
if (null != mVodPlayer) {
mPipParams.setRadio(mVodPlayer.getWidth(), mVodPlayer.getHeight());
}
int pipResult = mPipManager.enterPip(mPipParams, mVideoModel);
// 启动成功之后,暂停当前界面视频
if (pipResult == FTXEvent.NO_ERROR) {
......
......@@ -12,10 +12,12 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.res.Configuration;
import android.graphics.PixelFormat;
import android.os.Build;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.text.TextUtils;
import android.util.Log;
......@@ -25,7 +27,9 @@ import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;
import android.view.View;
import android.widget.ProgressBar;
import androidx.annotation.NonNull;
import com.tencent.rtmp.ITXLivePlayListener;
import com.tencent.rtmp.ITXVodPlayListener;
import com.tencent.rtmp.TXLiveConstants;
......@@ -63,6 +67,7 @@ public class FlutterPipImplActivity extends Activity implements Callback, ITXVod
private VideoModel mVideoModel;
private boolean mIsRegisterReceiver = false;
private PipParams mCurrentParams;
private Handler mMainHandler;
private final BroadcastReceiver pipActionReceiver = new BroadcastReceiver() {
@Override
......@@ -94,6 +99,8 @@ public class FlutterPipImplActivity extends Activity implements Callback, ITXVod
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mMainHandler = new Handler(getMainLooper());
bindAndroid12BugServiceIfNeed();
Intent intent = getIntent();
PipParams params = intent.getParcelableExtra(FTXEvent.EXTRA_NAME_PARAMS);
if (null == params) {
......@@ -108,7 +115,6 @@ public class FlutterPipImplActivity extends Activity implements Callback, ITXVod
}
}
registerPipBroadcast();
handleIntent(intent);
setContentView(R.layout.activity_flutter_pip_impl);
mVodPlayer = new TXVodPlayer(this);
mLivePlayer = new TXLivePlayer(this);
......@@ -117,7 +123,7 @@ public class FlutterPipImplActivity extends Activity implements Callback, ITXVod
mVideoSurface.getHolder().addCallback(this);
setVodPlayerListener();
setLivePlayerListener();
bindAndroid12BugServiceIfNeed();
handleIntent(intent);
}
private void setVodPlayerListener() {
......@@ -272,25 +278,29 @@ public class FlutterPipImplActivity extends Activity implements Callback, ITXVod
* @param closeImmediately 立刻关闭,不执行延迟,在android 12以上,如果画中画处于非当前app界面下,立刻关闭可能会造成无法返回app问题
*/
private void exitPip(boolean closeImmediately) {
if (!isFinishing() && !isDestroyed()) {
if (!isDestroyed()) {
// 由于android 12 的前台服务启动限制,导致画中画返回后,过早关闭activity界面的话,无法正常拉起app。所以这里增加延时处理
if (Build.VERSION.SDK_INT >= VERSION_CODES.S && !closeImmediately) {
if (VERSION.SDK_INT >= VERSION_CODES.S && !closeImmediately) {
mVodPlayer.stopPlay(true);
mLivePlayer.stopPlay(true);
mVideoSurface.setVisibility(View.GONE);
mVideoProgress.setVisibility(View.GONE);
mVideoProgress.postDelayed(new Runnable() {
mMainHandler.postDelayed(new Runnable() {
@Override
public void run() {
overridePendingTransition(0, 0);
finish();
finishAndRemoveTask();
}
}, 400);
} else {
overridePendingTransition(0, 0);
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
finishAndRemoveTask();
} else {
finish();
}
}
}
}
......@@ -332,6 +342,7 @@ public class FlutterPipImplActivity extends Activity implements Callback, ITXVod
@Override
public void surfaceCreated(SurfaceHolder holder) {
mIsSurfaceCreated = true;
holder.setFormat(PixelFormat.TRANSLUCENT);
attachSurface(holder.getSurface());
startPlay();
}
......@@ -453,6 +464,13 @@ public class FlutterPipImplActivity extends Activity implements Callback, ITXVod
mVideoProgress.setVisibility(View.VISIBLE);
}
private void controlPipPlayStatus(boolean isPlaying) {
if (null != mCurrentParams) {
mCurrentParams.setIsPlaying(isPlaying);
updatePip(mCurrentParams);
}
}
@Override
public void onPlayEvent(TXVodPlayer txVodPlayer, int event, Bundle bundle) {
if (VERSION.SDK_INT >= VERSION_CODES.N && isInPictureInPictureMode()) {
......@@ -466,7 +484,13 @@ public class FlutterPipImplActivity extends Activity implements Callback, ITXVod
}
updatePip(mCurrentParams);
}
if (event == TXLiveConstants.PLAY_EVT_PLAY_PROGRESS) {
if (event == TXLiveConstants.PLAY_EVT_PLAY_END) {
// 播放完毕的时候,自动将播放按钮置为播放
controlPipPlayStatus(false);
} else if (event == TXLiveConstants.PLAY_EVT_PLAY_BEGIN) {
// 播放开始的时候,自动将播放按钮置为暂停
controlPipPlayStatus(true);
} else if (event == TXLiveConstants.PLAY_EVT_PLAY_PROGRESS) {
int progress = bundle.getInt(TXLiveConstants.EVT_PLAY_PROGRESS_MS);
int duration = bundle.getInt(TXLiveConstants.EVT_PLAY_DURATION_MS);
float percentage = (progress / 1000F) / (duration / 1000F);
......
......@@ -13,6 +13,7 @@
android:id="@+id/sv_video_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:visibility="gone"/>
<ProgressBar
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论