Skip to content

Commit 916f8d2

Browse files
author
kongdywang
committed
Fix an issue where releasing the player would close the global Picture-in-Picture mode
1 parent 92d0fdf commit 916f8d2

File tree

14 files changed

+98
-62
lines changed

14 files changed

+98
-62
lines changed

Flutter/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11

2+
#### Version: 12.4.2 2025.04.30
3+
4+
##### Features:
5+
6+
- Fix an issue where releasing the player would close the global Picture-in-Picture mode.
7+
8+
29
#### Version: 12.4.1 2025.04.02
310

411
##### Features:

Flutter/CI/buildVersionOnMac.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildLog() {
55
}
66

77
inputVersion=$1
8-
export VERSION_NAME="12.4.1"
8+
export VERSION_NAME="12.4.2"
99
if [ -n "$inputVersion" ]; then
1010
VERSION_NAME=$inputVersion
1111
fi

Flutter/android/config.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ rootProject.ext {
44
supportSdkVersion = "26.0.1"
55
minSdkVersion = 19
66
targetSdkVersion = 28
7-
playerVersion = "12.4.1"
7+
playerVersion = "12.4.2"
88
compat = "androidx.appcompat:appcompat:1.6.1"
99

1010
/**

Flutter/android/src/main/java/com/tencent/vod/flutter/FTXPIPManager.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,18 @@ public int enterPip(PipParams params, TXPlayerHolder playerHolder) {
125125
*
126126
* 通知退出当前pip
127127
*/
128-
public void exitPip() {
129-
if (mIsInPipMode) {
130-
final Activity curActivity = TXFlutterEngineHolder.getInstance().getCurActivity();
131-
if (null != curActivity) {
132-
Intent intent = new Intent(curActivity, FlutterPipImplActivity.class);
133-
intent.setAction(FTXEvent.PIP_ACTION_EXIT);
134-
curActivity.startActivity(intent);
135-
mIsInPipMode = false;
136-
}
128+
public void exitCurrentPip() {
129+
exitPipByPlayerId(-1);
130+
}
131+
132+
/**
133+
* @param playerId -1 is close anyway
134+
*/
135+
public void exitPipByPlayerId(int playerId) {
136+
if (isInPipMode()) {
137+
Bundle params = new Bundle();
138+
params.putInt(FTXEvent.EXTRA_NAME_PLAYER_ID, playerId);
139+
TXSimpleEventBus.getInstance().post(FTXEvent.PIP_ACTION_EXIT, params);
137140
}
138141
}
139142

@@ -238,14 +241,10 @@ public void releaseActivityListener() {
238241
* 更新PIP悬浮框按钮
239242
*/
240243
public void updatePipActions(PipParams params) {
241-
final Activity mAct = TXFlutterEngineHolder.getInstance().getCurActivity();
242-
if (null != mAct) {
243-
Intent intent = new Intent(mAct, FlutterPipImplActivity.class);
244+
if (isInPipMode()) {
244245
Bundle bundle = new Bundle();
245246
bundle.putParcelable(FTXEvent.EXTRA_NAME_PARAMS, params);
246-
intent.setAction(FTXEvent.PIP_ACTION_UPDATE);
247-
intent.putExtra("data", bundle);
248-
mAct.startActivity(intent);
247+
TXSimpleEventBus.getInstance().post(FTXEvent.PIP_ACTION_UPDATE, bundle);
249248
}
250249
}
251250

Flutter/android/src/main/java/com/tencent/vod/flutter/SuperPlayerPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
479479
}
480480
if (null != mTxPipManager) {
481481
mTxPipManager.releaseActivityListener();
482-
mTxPipManager.exitPip();
482+
mTxPipManager.exitCurrentPip();
483483
}
484484
// Close the solution to the problem of the picture-in-picture click restore
485485
// failure on some versions of Android 12.

Flutter/android/src/main/java/com/tencent/vod/flutter/player/FTXLivePlayer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ public IntMsg enterPictureInPictureMode(@NonNull PipParamsPlayerMsg pipParamsMsg
393393

394394
@Override
395395
public void exitPictureInPictureMode(@NonNull PlayerMsg playerMsg) {
396-
mPipManager.exitPip();
396+
mPipManager.exitPipByPlayerId(getPlayerId());
397397
}
398398

399399
@NonNull

Flutter/android/src/main/java/com/tencent/vod/flutter/player/FTXVodPlayer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ int stopPlay(boolean isNeedClearLastImg) {
297297
result = mVodPlayer.stopPlay(isNeedClearLastImg);
298298
}
299299
mUIHandler.removeCallbacksAndMessages(null);
300-
mPipManager.exitPip();
300+
mPipManager.exitPipByPlayerId(getPlayerId());
301301
releaseTXImageSprite();
302302
mHardwareDecodeFail = false;
303303
if (isNeedClearLastImg && null != mCurRenderView) {
@@ -723,7 +723,7 @@ public IntMsg enterPictureInPictureMode(@NonNull PipParamsPlayerMsg pipParamsMsg
723723

724724
@Override
725725
public void exitPictureInPictureMode(@NonNull PlayerMsg playerMsg) {
726-
mPipManager.exitPip();
726+
mPipManager.exitPipByPlayerId(getPlayerId());
727727
}
728728

729729
@Override

Flutter/android/src/main/java/com/tencent/vod/flutter/tools/TXSimpleEventBus.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.HashMap;
55
import java.util.List;
66
import java.util.Map;
7+
import java.util.Set;
78

89
/**
910
* use to communicate with Activities frequently
@@ -39,6 +40,16 @@ public void unregister(String eventType, EventSubscriber subscriber) {
3940
}
4041
}
4142

43+
public void unregisterAllType(EventSubscriber subscriber) {
44+
Set<String> keySets = subscribers.keySet();
45+
for (String key : keySets) {
46+
List<EventSubscriber> subscriberList = subscribers.get(key);
47+
if (subscriberList != null) {
48+
subscriberList.remove(subscriber);
49+
}
50+
}
51+
}
52+
4253
public void post(String eventType, Object data) {
4354
List<EventSubscriber> subscriberList = subscribers.get(eventType);
4455
if (subscriberList != null) {

Flutter/android/src/main/java/com/tencent/vod/flutter/ui/FlutterPipImplActivity.java

Lines changed: 55 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646

4747
public class FlutterPipImplActivity extends Activity implements ITXVodPlayListener,
48-
ServiceConnection {
48+
ServiceConnection, TXSimpleEventBus.EventSubscriber {
4949

5050
private static final String TAG = "FlutterPipImplActivity";
5151
private static TXPlayerHolder pipPlayerHolder;
@@ -159,7 +159,7 @@ protected void onCreate(Bundle savedInstanceState) {
159159
mPipContainer = findViewById(R.id.rl_pip_container);
160160
if (null == pipPlayerHolder) {
161161
LiteavLog.e(TAG, "lack pipPlayerHolder, please check the pip argument");
162-
finish();
162+
destroyPipAct();
163163
return;
164164
}
165165
mPlayerHolder = pipPlayerHolder;
@@ -169,15 +169,18 @@ protected void onCreate(Bundle savedInstanceState) {
169169
setLivePlayerListener();
170170
} else {
171171
LiteavLog.e(TAG, "lack pipPlayerHolder player, please check the pip argument");
172-
finish();
172+
destroyPipAct();
173+
return;
173174
}
175+
TXSimpleEventBus.getInstance().register(FTXEvent.PIP_ACTION_EXIT, this);
176+
TXSimpleEventBus.getInstance().register(FTXEvent.PIP_ACTION_UPDATE, this);
174177
Intent intent = getIntent();
175178
Bundle data = intent.getBundleExtra("data");
176179
if (null != data) {
177180
PipParams params = data.getParcelable(FTXEvent.EXTRA_NAME_PARAMS);
178181
if (null == params) {
179182
LiteavLog.e(TAG, "lack pip params,please check the argument");
180-
finish();
183+
destroyPipAct();
181184
} else {
182185
mCurrentParams = params;
183186
if (VERSION.SDK_INT >= VERSION_CODES.O) {
@@ -317,9 +320,11 @@ private void handlePipExitEvent() {
317320
}
318321
if (null != mPlayerHolder.getVodPlayer()) {
319322
mPlayerHolder.getVodPlayer().setSurface(null);
323+
mPlayerHolder.getVodPlayer().setVodListener(null);
320324
}
321325
if (null != mPlayerHolder.getLivePlayer()) {
322326
mPlayerHolder.getLivePlayer().setRenderView((TextureView) null);
327+
mPlayerHolder.getLivePlayer().setObserver(null);
323328
}
324329
mPlayerHolder.pause();
325330
int codeEvent = mIsNeedToStop ? FTXEvent.EVENT_PIP_MODE_ALREADY_EXIT : FTXEvent.EVENT_PIP_MODE_RESTORE_UI;
@@ -336,31 +341,48 @@ protected void onNewIntent(Intent intent) {
336341
private void handleIntent(Intent intent) {
337342
if (intent != null) {
338343
String action = intent.getAction();
339-
if (TextUtils.equals(action, FTXEvent.PIP_ACTION_START)) {
340-
startPipVideo();
341-
} else if (TextUtils.equals(action, FTXEvent.PIP_ACTION_EXIT)) {
344+
handleAction(action, intent.getExtras());
345+
}
346+
}
347+
348+
private void handleAction(String action, Bundle params) {
349+
if (TextUtils.equals(action, FTXEvent.PIP_ACTION_START)) {
350+
startPipVideo();
351+
} else if (TextUtils.equals(action, FTXEvent.PIP_ACTION_EXIT)) {
352+
int playerId = -1;
353+
if (null != params) {
354+
playerId = params.getInt(FTXEvent.EXTRA_NAME_PLAYER_ID, -1);
355+
}
356+
if (playerId == -1 || playerId == mCurrentParams.getCurrentPlayerId()) {
342357
mIsNeedToStop = true;
343358
handlePipExitEvent();
344-
} else if (TextUtils.equals(action, FTXEvent.PIP_ACTION_UPDATE)) {
345-
Bundle data = intent.getBundleExtra("data");
346-
if (null != data) {
347-
PipParams pipParams = data.getParcelable(FTXEvent.EXTRA_NAME_PARAMS);
348-
updatePip(pipParams);
349-
}
350-
} else if (TextUtils.equals(action, FTXEvent.PIP_ACTION_DO_EXIT)) {
351-
overridePendingTransition(0, 0);
352-
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
353-
FlutterPipImplActivity.this.finishAndRemoveTask();
354-
} else {
355-
FlutterPipImplActivity.this.finish();
356-
}
357-
mIsPipFinishing = false;
358359
} else {
359-
LiteavLog.e(TAG, "unknown pip action:" + action);
360+
LiteavLog.w(TAG, "close pip failed, playerId not found:" + playerId);
361+
}
362+
} else if (TextUtils.equals(action, FTXEvent.PIP_ACTION_UPDATE)) {
363+
if (null != params) {
364+
PipParams pipParams = params.getParcelable(FTXEvent.EXTRA_NAME_PARAMS);
365+
updatePip(pipParams);
360366
}
367+
} else if (TextUtils.equals(action, FTXEvent.PIP_ACTION_DO_EXIT)) {
368+
destroyPipAct();
369+
} else {
370+
LiteavLog.e(TAG, "unknown pip action:" + action);
361371
}
362372
}
363373

374+
private void destroyPipAct() {
375+
overridePendingTransition(0, 0);
376+
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
377+
FlutterPipImplActivity.this.finishAndRemoveTask();
378+
} else {
379+
FlutterPipImplActivity.this.finish();
380+
}
381+
mIsPipFinishing = false;
382+
pipPlayerHolder = null;
383+
isInPip = false;
384+
}
385+
364386
private void updatePip(PipParams pipParams) {
365387
if (null != pipParams && !isDestroyed() && !isFinishing()) {
366388
mCurrentParams = pipParams;
@@ -432,23 +454,11 @@ public void run() {
432454
it can display back to the original page.
433455
*/
434456
moveCurActToFront();
435-
overridePendingTransition(0, 0);
436-
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
437-
FlutterPipImplActivity.this.finishAndRemoveTask();
438-
} else {
439-
FlutterPipImplActivity.this.finish();
440-
}
441-
mIsPipFinishing = false;
457+
destroyPipAct();
442458
}
443459
}, 800);
444460
} else {
445-
overridePendingTransition(0, 0);
446-
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
447-
finishAndRemoveTask();
448-
} else {
449-
finish();
450-
}
451-
mIsPipFinishing = false;
461+
destroyPipAct();
452462
}
453463
}
454464
}
@@ -487,6 +497,7 @@ protected void onDestroy() {
487497
if (Build.VERSION.SDK_INT >= VERSION_CODES.Q) {
488498
unbindService(this);
489499
}
500+
TXSimpleEventBus.getInstance().unregister(FTXEvent.PIP_ACTION_EXIT, this);
490501
mPlayerHolder = null;
491502
pipPlayerHolder = null;
492503
isInPip = false;
@@ -650,4 +661,12 @@ public void onServiceConnected(ComponentName name, IBinder service) {
650661
@Override
651662
public void onServiceDisconnected(ComponentName name) {
652663
}
664+
665+
@Override
666+
public void onEvent(String eventType, Object data) {
667+
if (TextUtils.equals(FTXEvent.PIP_ACTION_EXIT, eventType)
668+
|| TextUtils.equals(FTXEvent.PIP_ACTION_UPDATE, eventType)) {
669+
handleAction(eventType, (Bundle) data);
670+
}
671+
}
653672
}

Flutter/ios/super_player.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
Pod::Spec.new do |s|
66
s.name = 'super_player'
7-
s.version = '12.4.1'
7+
s.version = '12.4.2'
88
s.summary = 'The super_player Flutter plugin is one of the sub-product SDKs of the audio/video terminal SDK (Tencent Cloud Video on Demand).'
99
s.description = <<-DESC
1010
player plugin.

0 commit comments

Comments
 (0)