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