Play Minimized video when app in background
This commit is contained in:
parent
645c9fa240
commit
118c2175f5
|
@ -110,4 +110,5 @@ dependencies {
|
||||||
implementation "net.gotev:uploadservice:3.5.2"
|
implementation "net.gotev:uploadservice:3.5.2"
|
||||||
implementation "net.gotev:uploadservice-okhttp:3.5.2"
|
implementation "net.gotev:uploadservice-okhttp:3.5.2"
|
||||||
implementation "com.google.code.gson:gson:2.8.6"
|
implementation "com.google.code.gson:gson:2.8.6"
|
||||||
|
|
||||||
}
|
}
|
|
@ -193,6 +193,7 @@
|
||||||
|
|
||||||
|
|
||||||
<string name="set_video_mode_choice" translatable="false">set_video_mode_choice</string>
|
<string name="set_video_mode_choice" translatable="false">set_video_mode_choice</string>
|
||||||
|
<string name="set_video_minimize_choice" translatable="false">set_video_minimize_choice</string>
|
||||||
<string name="set_video_mode_description">Permet de changer le mode de lecture pour les vidéos (normal, streaming ou via un navigateur).</string>
|
<string name="set_video_mode_description">Permet de changer le mode de lecture pour les vidéos (normal, streaming ou via un navigateur).</string>
|
||||||
<string name="register_account">Créer un compte</string>
|
<string name="register_account">Créer un compte</string>
|
||||||
<string name="preview">Aperçu</string>
|
<string name="preview">Aperçu</string>
|
||||||
|
@ -238,4 +239,13 @@
|
||||||
<string name="notification_channel_name">Mise à jour des informations</string>
|
<string name="notification_channel_name">Mise à jour des informations</string>
|
||||||
|
|
||||||
<string name="list_of_accounts">Liste des comptes</string>
|
<string name="list_of_accounts">Liste des comptes</string>
|
||||||
|
|
||||||
|
<string name="pause">Pause</string>
|
||||||
|
<string name="play">Lecture</string>
|
||||||
|
<string name="minimize">Réduire</string>
|
||||||
|
<string name="fast_rewind">Retour rapide</string>
|
||||||
|
<string name="fast_forward">Avance rapide</string>
|
||||||
|
|
||||||
|
<string name="set_video_minimize">Réduire la taille des vidéos</string>
|
||||||
|
<string name="set_video_minimize_description">Réduit la taille des vidéos quand l\'application est en arrière plan (Android N+)</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -135,6 +135,8 @@
|
||||||
<string name="edit">Edit</string>
|
<string name="edit">Edit</string>
|
||||||
|
|
||||||
<string name="set_video_mode_choice" translatable="false">set_video_mode_choice</string>
|
<string name="set_video_mode_choice" translatable="false">set_video_mode_choice</string>
|
||||||
|
<string name="set_video_minimize_choice" translatable="false">set_video_minimize_choice</string>
|
||||||
|
|
||||||
<string name="set_video_mode_description">Allows to change mode for playing videos (default, streaming or via a browser).</string>
|
<string name="set_video_mode_description">Allows to change mode for playing videos (default, streaming or via a browser).</string>
|
||||||
|
|
||||||
|
|
||||||
|
@ -255,4 +257,12 @@
|
||||||
|
|
||||||
<string name="add_account">Add an account</string>
|
<string name="add_account">Add an account</string>
|
||||||
<string name="list_of_accounts">List of accounts</string>
|
<string name="list_of_accounts">List of accounts</string>
|
||||||
|
<string name="pause">Pause</string>
|
||||||
|
<string name="play">Play</string>
|
||||||
|
<string name="minimize">Minimize</string>
|
||||||
|
<string name="fast_rewind">Fast rewind</string>
|
||||||
|
<string name="fast_forward">Fast forward</string>
|
||||||
|
|
||||||
|
<string name="set_video_minimize">Minimize videos size</string>
|
||||||
|
<string name="set_video_minimize_description">Minize videos size when the app is in background (Android N+)</string>
|
||||||
</resources>
|
</resources>
|
|
@ -18,6 +18,7 @@
|
||||||
<application
|
<application
|
||||||
android:name=".FedilabTube"
|
android:name=".FedilabTube"
|
||||||
android:allowBackup="false"
|
android:allowBackup="false"
|
||||||
|
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
|
@ -37,8 +38,11 @@
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".PeertubeActivity"
|
android:name=".PeertubeActivity"
|
||||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
|
||||||
android:label="@string/app_name" />
|
android:label="@string/app_name"
|
||||||
|
android:resizeableActivity="true"
|
||||||
|
android:supportsPictureInPicture="true"
|
||||||
|
tools:targetApi="n" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".PeertubeEditUploadActivity"
|
android:name=".PeertubeEditUploadActivity"
|
||||||
android:configChanges="orientation|screenSize"
|
android:configChanges="orientation|screenSize"
|
||||||
|
|
|
@ -48,6 +48,7 @@ import android.widget.ScrollView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.RequiresApi;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.appcompat.widget.AppCompatImageView;
|
import androidx.appcompat.widget.AppCompatImageView;
|
||||||
import androidx.appcompat.widget.PopupMenu;
|
import androidx.appcompat.widget.PopupMenu;
|
||||||
|
@ -132,6 +133,8 @@ public class PeertubeActivity extends AppCompatActivity {
|
||||||
private List<PlaylistElement> playlistForVideo;
|
private List<PlaylistElement> playlistForVideo;
|
||||||
private List<Playlist> playlists;
|
private List<Playlist> playlists;
|
||||||
private PlaylistsVM playlistsViewModel;
|
private PlaylistsVM playlistsViewModel;
|
||||||
|
private boolean playInMinimized;
|
||||||
|
private boolean onStopCalled;
|
||||||
|
|
||||||
public static void hideKeyboard(Activity activity) {
|
public static void hideKeyboard(Activity activity) {
|
||||||
if (activity != null && activity.getWindow() != null) {
|
if (activity != null && activity.getWindow() != null) {
|
||||||
|
@ -145,6 +148,7 @@ public class PeertubeActivity extends AppCompatActivity {
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||||
fullscreen = FullScreenMediaController.fullscreen.OFF;
|
fullscreen = FullScreenMediaController.fullscreen.OFF;
|
||||||
fullScreenMode = false;
|
fullScreenMode = false;
|
||||||
|
@ -169,7 +173,11 @@ public class PeertubeActivity extends AppCompatActivity {
|
||||||
peertube_playlist = findViewById(R.id.peertube_playlist);
|
peertube_playlist = findViewById(R.id.peertube_playlist);
|
||||||
send = findViewById(R.id.send);
|
send = findViewById(R.id.send);
|
||||||
|
|
||||||
|
playInMinimized = sharedpreferences.getBoolean(getString(R.string.set_video_minimize_choice), true);
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N
|
||||||
|
&& !getPackageManager().hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)) {
|
||||||
|
playInMinimized = false;
|
||||||
|
}
|
||||||
peertube_playlist.setVisibility(View.VISIBLE);
|
peertube_playlist.setVisibility(View.VISIBLE);
|
||||||
peertube_bookmark.setVisibility(View.GONE);
|
peertube_bookmark.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
@ -674,22 +682,52 @@ public class PeertubeActivity extends AppCompatActivity {
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
if (player != null)
|
if (player != null) {
|
||||||
|
player.setPlayWhenReady(false);
|
||||||
player.release();
|
player.release();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
if (player != null) {
|
if (player != null && !playInMinimized) {
|
||||||
player.setPlayWhenReady(false);
|
player.setPlayWhenReady(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@RequiresApi(api = Build.VERSION_CODES.N)
|
||||||
|
@Override
|
||||||
|
public void onUserLeaveHint() {
|
||||||
|
if (playInMinimized) {
|
||||||
|
enterPictureInPictureMode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) {
|
||||||
|
if (isInPictureInPictureMode) {
|
||||||
|
setFullscreen(FullScreenMediaController.fullscreen.ON);
|
||||||
|
} else {
|
||||||
|
setFullscreen(FullScreenMediaController.fullscreen.OFF);
|
||||||
|
if (onStopCalled) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStop() {
|
||||||
|
super.onStop();
|
||||||
|
onStopCalled = true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
if (player != null) {
|
onStopCalled = false;
|
||||||
|
if (player != null && !playInMinimized) {
|
||||||
player.setPlayWhenReady(true);
|
player.setPlayWhenReady(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import androidx.fragment.app.FragmentActivity;
|
||||||
import androidx.preference.ListPreference;
|
import androidx.preference.ListPreference;
|
||||||
import androidx.preference.PreferenceFragmentCompat;
|
import androidx.preference.PreferenceFragmentCompat;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
import androidx.preference.SwitchPreference;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -57,24 +58,33 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||||
if (key.compareTo(getString(R.string.set_video_mode_choice)) == 0) {
|
|
||||||
ListPreference set_video_mode_choice = findPreference(getString(R.string.set_video_mode_choice));
|
if (getActivity() != null) {
|
||||||
if (set_video_mode_choice != null && getActivity() != null) {
|
SharedPreferences sharedpreferences = getActivity().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
SharedPreferences sharedpreferences = getActivity().getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
||||||
switch (set_video_mode_choice.getValue()) {
|
if (key.compareTo(getString(R.string.set_video_mode_choice)) == 0) {
|
||||||
case "0":
|
ListPreference set_video_mode_choice = findPreference(getString(R.string.set_video_mode_choice));
|
||||||
editor.putInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_NORMAL);
|
if (set_video_mode_choice != null) {
|
||||||
break;
|
switch (set_video_mode_choice.getValue()) {
|
||||||
case "1":
|
case "0":
|
||||||
editor.putInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_STREAMING);
|
editor.putInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_NORMAL);
|
||||||
break;
|
break;
|
||||||
case "2":
|
case "1":
|
||||||
editor.putInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_WEBVIEW);
|
editor.putInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_STREAMING);
|
||||||
break;
|
break;
|
||||||
|
case "2":
|
||||||
|
editor.putInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_WEBVIEW);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
editor.apply();
|
|
||||||
}
|
}
|
||||||
|
if (key.compareTo(getString(R.string.set_video_minimize_choice)) == 0) {
|
||||||
|
SwitchPreference set_video_minimize_choice = findPreference(getString(R.string.set_video_minimize_choice));
|
||||||
|
editor.putBoolean(getString(R.string.set_video_minimize_choice), set_video_minimize_choice.isChecked());
|
||||||
|
}
|
||||||
|
editor.apply();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,5 +115,8 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
|
||||||
set_video_mode_choice.setValueIndex(video_mode);
|
set_video_mode_choice.setValueIndex(video_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean minimized = sharedpref.getBoolean(getString(R.string.set_video_minimize_choice), true);
|
||||||
|
SwitchPreference set_video_minimize_choice = findPreference(getString(R.string.set_video_minimize_choice));
|
||||||
|
set_video_minimize_choice.setChecked(minimized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:tint="?attr/colorControlNormal"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M21,3L3,3c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h18c1.1,0 2,-0.9 2,-2L23,5c0,-1.1 -0.9,-2 -2,-2zM12,12L3,12L3,5h9v7z" />
|
||||||
|
</vector>
|
|
@ -8,4 +8,10 @@
|
||||||
android:key="@string/set_video_mode_choice"
|
android:key="@string/set_video_mode_choice"
|
||||||
android:summary="@string/set_video_mode_description"
|
android:summary="@string/set_video_mode_description"
|
||||||
android:title="@string/set_video_mode" />
|
android:title="@string/set_video_mode" />
|
||||||
|
|
||||||
|
<androidx.preference.SwitchPreference
|
||||||
|
android:icon="@drawable/ic_baseline_featured_video_24"
|
||||||
|
android:key="@string/set_video_minimize_choice"
|
||||||
|
android:summary="@string/set_video_minimize_description"
|
||||||
|
android:title="@string/set_video_minimize" />
|
||||||
</androidx.preference.PreferenceScreen>
|
</androidx.preference.PreferenceScreen>
|
Loading…
Reference in New Issue