Skip to content

Commit

Permalink
小窗播放改为手动开启
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaoRanLiu3119 committed Nov 9, 2023
1 parent f084275 commit 7b4d752
Show file tree
Hide file tree
Showing 9 changed files with 320 additions and 351 deletions.
3 changes: 0 additions & 3 deletions app/src/main/java/com/github/tvbox/osc/base/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,4 @@ public void dismissLoadingDialog() {
}
}

public boolean supportsPiPMode() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
}
}
17 changes: 17 additions & 0 deletions app/src/main/java/com/github/tvbox/osc/constant/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.github.tvbox.osc.constant;

/**
* @Author : Liu XiaoRan
* @Email : [email protected]
* @Date : on 2023/8/16 09:53.
* @Description :
*/
public class Constants {

/**
* 画中画事件
*/
public static final int PIP_BOARDCAST_ACTION_PREV = 0;
public static final int PIP_BOARDCAST_ACTION_PLAYPAUSE = 1;
public static final int PIP_BOARDCAST_ACTION_NEXT = 2;
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public void run() {
@Override
protected void initView() {
super.initView();
findViewById(R.id.pip).setVisibility(GONE);
findViewById(R.id.cast).setVisibility(GONE);
mMyBatteryView = findViewById(R.id.battery);
findViewById(R.id.container_top_right_device_info).setVisibility(VISIBLE);
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import com.github.tvbox.osc.bean.SourceBean;
import com.github.tvbox.osc.bean.VodInfo;
import com.github.tvbox.osc.cache.RoomDataManger;
import com.github.tvbox.osc.constant.Constants;
import com.github.tvbox.osc.databinding.ActivityDetailBinding;
import com.github.tvbox.osc.event.RefreshEvent;
import com.github.tvbox.osc.receiver.BatteryReceiver;
Expand All @@ -61,6 +62,7 @@
import com.github.tvbox.osc.util.HawkConfig;
import com.github.tvbox.osc.util.SearchHelper;
import com.github.tvbox.osc.util.SubtitleHelper;
import com.github.tvbox.osc.util.Utils;
import com.github.tvbox.osc.viewmodel.SourceViewModel;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
Expand Down Expand Up @@ -123,12 +125,6 @@ public class DetailActivity extends BaseVbActivity<ActivityDetailBinding> {
* 是否开启后台播放标记,不在广播开启,onPause根据标记开启
*/
boolean openBackgroundPlay;
/**
* 画中画事件
*/
private static final int PIP_BOARDCAST_ACTION_PREV = 0;
private static final int PIP_BOARDCAST_ACTION_PLAYPAUSE = 1;
private static final int PIP_BOARDCAST_ACTION_NEXT = 2;
private BroadcastReceiver mPipActionReceiver;

@Override
Expand Down Expand Up @@ -850,10 +846,16 @@ public void onClick(DialogInterface dialog, int which) {
}
}

@Override
public void onUserLeaveHint() {
/**
* 画中画模式
*/
public void enterPip() {
if (Utils.supportsPiPMode()) {
// 创建一个Intent对象,模拟按下Home键
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);

if (supportsPiPMode() && Hawk.get(HawkConfig.BACKGROUND_PLAY_TYPE, 0) == 2 && playFragment.getPlayer().isPlaying()) {
// Calculate Video Resolution
int vWidth = playFragment.getPlayer().getVideoSize()[0];
int vHeight = playFragment.getPlayer().getVideoSize()[1];
Expand All @@ -867,23 +869,25 @@ public void onUserLeaveHint() {
ratio = new Rational(16, 9);
}
List<RemoteAction> actions = new ArrayList<>();
actions.add(generateRemoteAction(android.R.drawable.ic_media_previous, PIP_BOARDCAST_ACTION_PREV, "Prev", "Play Previous"));
actions.add(generateRemoteAction(android.R.drawable.ic_media_play, PIP_BOARDCAST_ACTION_PLAYPAUSE, "Play", "Play/Pause"));
actions.add(generateRemoteAction(android.R.drawable.ic_media_next, PIP_BOARDCAST_ACTION_NEXT, "Next", "Play Next"));
actions.add(generateRemoteAction(android.R.drawable.ic_media_previous, Constants.PIP_BOARDCAST_ACTION_PREV, "Prev", "Play Previous"));
actions.add(generateRemoteAction(android.R.drawable.ic_media_play, Constants.PIP_BOARDCAST_ACTION_PLAYPAUSE, "Play", "Play/Pause"));
actions.add(generateRemoteAction(android.R.drawable.ic_media_next, Constants.PIP_BOARDCAST_ACTION_NEXT, "Next", "Play Next"));
PictureInPictureParams params = new PictureInPictureParams.Builder()
.setAspectRatio(ratio)
.setActions(actions).build();
if (!fullWindows) {
toggleFullPreview();
}
playFragment.getPlayer().postDelayed(() -> {//代码模拟home键时会立即执行,toggleFullPreview中竖屏有切换横屏操作,
if (!fullWindows) {
toggleFullPreview();
}
},300);
enterPictureInPictureMode(params);
playFragment.getController().hideBottom();

playFragment.getPlayer().postDelayed(() -> {
if (!playFragment.getPlayer().isPlaying()){
playFragment.getController().togglePlay();
}
},300);
},400);
}
super.onUserLeaveHint();
}
Expand All @@ -903,7 +907,7 @@ private RemoteAction generateRemoteAction(int iconResId, int actionCode, String
@Override
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) {
super.onPictureInPictureModeChanged(isInPictureInPictureMode);
if (supportsPiPMode() && isInPictureInPictureMode) {
if (Utils.supportsPiPMode() && isInPictureInPictureMode) {
mPipActionReceiver = new BroadcastReceiver() {

@Override
Expand All @@ -913,11 +917,11 @@ public void onReceive(Context context, Intent intent) {
}

int currentStatus = intent.getIntExtra("action", 1);
if (currentStatus == PIP_BOARDCAST_ACTION_PREV) {
if (currentStatus == Constants.PIP_BOARDCAST_ACTION_PREV) {
playFragment.playPrevious();
} else if (currentStatus == PIP_BOARDCAST_ACTION_PLAYPAUSE) {
} else if (currentStatus == Constants.PIP_BOARDCAST_ACTION_PLAYPAUSE) {
playFragment.getController().togglePlay();
} else if (currentStatus == PIP_BOARDCAST_ACTION_NEXT) {
} else if (currentStatus == Constants.PIP_BOARDCAST_ACTION_NEXT) {
playFragment.playNext(false);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.graphics.Color;
Expand Down Expand Up @@ -329,6 +330,11 @@ public void showSetting() {
mPlayingControlDialog.show();
}
}

@Override
public void pip() {
activity.enterPip();
}
});
mVideoView.setVideoController(mController);
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/com/github/tvbox/osc/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.res.Configuration;
import android.database.Cursor;
import android.os.Build;
import android.provider.MediaStore;

import androidx.appcompat.app.AppCompatDelegate;
Expand All @@ -24,6 +25,10 @@
*/
public class Utils {

public static boolean supportsPiPMode() {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
}

public static int getSeriesSpanCount(List<VodInfo.VodSeries> list) {
int spanCount = 4;
int total = 0;
Expand Down
Binary file added app/src/main/res/drawable-xxhdpi/ic_pip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions app/src/main/res/layout/player_vod_control_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@
android:layout_height="wrap_content"
android:gravity="end">

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/pip"
android:layout_width="34dp"
android:layout_height="34dp"
android:layout_marginEnd="8dp"
android:padding="3dp"
android:scaleType="centerCrop"
android:src="@drawable/ic_pip"
app:tint="@color/white" />

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/cast"
android:layout_width="34dp"
Expand All @@ -126,6 +136,7 @@
android:padding="4dp"
android:scaleType="centerCrop"
android:src="@drawable/ic_cast"
android:layout_marginStart="4dp"
app:tint="@color/white" />

<androidx.appcompat.widget.AppCompatImageView
Expand Down

0 comments on commit 7b4d752

Please sign in to comment.