Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - Start to add Android video Picture-in-Picture #2131

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@
android:launchMode="singleTask"
android:label="@string/app_name"
android:exported="true"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode|screenLayout|smallestScreenSize"
android:windowSoftInputMode="adjustResize">
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode|screenLayout|smallestScreenSize|locale|layoutDirection|fontScale|density"
android:windowSoftInputMode="adjustResize"
android:resizeableActivity="true"
android:supportsPictureInPicture="true">
<intent-filter android:label="import">
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.GET_CONTENT" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ protected List<ReactPackage> getPackages() {
List<ReactPackage> packages = new PackageList(this).getPackages();
// Packages that cannot be autolinked yet can be added manually here, for example:
packages.add(new PodversePackage());
packages.add(new PipPackage());
return packages;
}

Expand Down
31 changes: 31 additions & 0 deletions android/app/src/main/java/com/podverse/PipModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.podverse;

import android.app.PictureInPictureParams;
import android.os.Build;
import android.util.Rational;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;

public class PipModule extends ReactContextBaseJavaModule {
private Rational aspectRatio;
PipModule(ReactApplicationContext context){
super(context);
aspectRatio = new Rational(3, 4);
}

@Override
public String getName(){
return "PipModule";
}

@ReactMethod
public void EnterPipMode(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
PictureInPictureParams params = new PictureInPictureParams.Builder()
.setAspectRatio(this.aspectRatio)
.build();
getCurrentActivity().enterPictureInPictureMode(params);
}
}
}
24 changes: 24 additions & 0 deletions android/app/src/main/java/com/podverse/PipPackage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.podverse;

import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class PipPackage implements ReactPackage {

@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}

@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();
modules.add(new PipModule(reactContext));
return modules;
}
}
8 changes: 7 additions & 1 deletion src/screens/PodcastsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ export class PodcastsScreen extends React.Component<Props, State> {
playback-queue-ended should remove the nowPlayingItem from state and storage.
*/
if (!!lastItem || !!currentItem) {
await playerUpdateUserPlaybackPosition()
playerUpdateUserPlaybackPosition()
}

if (nextAppState === 'active' && !isInitialLoadPodcastsScreen) {
Expand Down Expand Up @@ -535,6 +535,12 @@ export class PodcastsScreen extends React.Component<Props, State> {
if (playerActiveType === PV.Player.playerTypes.isAudio) {
await audioUpdateTrackPlayerCapabilities()
}
} else if (Platform.OS === 'android') {
const { PipModule } = NativeModules
const playerType = await playerCheckActiveType()
if (playerType === PV.Player.playerTypes.isVideo) {
PipModule.EnterPipMode()
}
}
}

Expand Down