Issue #123 - improve player

This commit is contained in:
Thomas 2020-12-05 18:41:07 +01:00
parent de14e95e90
commit fbeb87e29e
7 changed files with 135 additions and 4 deletions

View File

@ -22,6 +22,7 @@
<string name="cast">ChromeCast</string>
<string name="set_cast_description">Permet de découvrir les appareils Chromecast sur le réseau.</string>
<string name="chromecast_choice">Choix de la ChromeCast</string>
<string name="please_wait">Veuillez patienter</string>
<string name="_retry">Réessayer</string>
<string name="refresh_token_failed">Échec de rafraîchissement du jeton d\'accès</string>
<string name="refresh_token_failed_message">Vous pouvez réessayer de le rafraîchir ou simplement déconnecter le compte</string>

View File

@ -1,5 +1,5 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<string name="app_name" translatable="false">Bittube</string>
<string name="app_name" translatable="false">bittube</string>
<string name="app_id" translatable="false">app.fedilab.bittube</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>
@ -13,6 +13,10 @@
<string name="set_fullscreen_choice" translatable="false">set_fullscreen_choice</string>
<string name="set_play_screen_lock_choice" translatable="false">set_play_screen_lock_choice</string>
<string name="set_video_in_list_choice" translatable="false">set_video_in_list_choice</string>
<string name="set_cast_choice" translatable="false">set_cast_choice</string>
<string name="set_cast">Enable Chromecast (beta)</string>
<string name="please_wait">Please wait</string>
<string name="set_cast_description">Allow to discover Chromecast devices on the network.</string>
<string name="set_video_sensitive_choice" translatable="false">set_video_sensitive_choice</string>
<string name="set_video_in_list">Videos in list</string>
<string name="set_video_in_list_description">Change the layout for displaying videos in a list</string>
@ -21,6 +25,7 @@
<string name="show_less">Show less</string>
<string name="cast">ChromeCast</string>
<string name="chromecast_choice">ChromeCast choice</string>
<string name="set_play_screen_lock">Screen lock</string>
<string name="set_play_screen_lock_description">Keep playing videos when the screen is locked</string>

View File

@ -15,6 +15,7 @@
<string name="set_video_in_list_choice" translatable="false">set_video_in_list_choice</string>
<string name="set_cast_choice" translatable="false">set_cast_choice</string>
<string name="set_cast">Enable Chromecast (beta)</string>
<string name="please_wait">Please wait</string>
<string name="set_cast_description">Allow to discover Chromecast devices on the network.</string>
<string name="set_video_sensitive_choice" translatable="false">set_video_sensitive_choice</string>
<string name="set_video_in_list">Videos in list</string>

View File

@ -152,6 +152,7 @@ import app.fedilab.fedilabtube.webview.MastalabWebChromeClient;
import app.fedilab.fedilabtube.webview.MastalabWebViewClient;
import es.dmoral.toasty.Toasty;
import su.litvak.chromecast.api.v2.ChromeCast;
import su.litvak.chromecast.api.v2.MediaStatus;
import su.litvak.chromecast.api.v2.Status;
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.ADD_COMMENT;
@ -446,6 +447,35 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
});
binding.castPlay.setOnClickListener(v -> {
binding.castLoader.setVisibility(View.VISIBLE);
if (chromeCast != null) {
new Thread(() -> {
try {
int icon = -1;
if (chromeCast.getMediaStatus().playerState == MediaStatus.PlayerState.PLAYING) {
chromeCast.pause();
icon = R.drawable.ic_baseline_play_arrow_32;
} else if (chromeCast.getMediaStatus().playerState == MediaStatus.PlayerState.PAUSED) {
chromeCast.play();
icon = R.drawable.ic_baseline_pause_32;
}
if (icon != -1) {
Handler mainHandler = new Handler(Looper.getMainLooper());
int finalIcon = icon;
Runnable myRunnable = () -> binding.castPlay.setImageResource(finalIcon);
mainHandler.post(myRunnable);
}
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> binding.castLoader.setVisibility(View.GONE);
mainHandler.post(myRunnable);
} catch (IOException e) {
e.printStackTrace();
}
}).start();
}
});
}
private void manageVIewVideos(APIResponse apiResponse) {
@ -713,6 +743,13 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
try {
chromeCast.disconnect();
chromeCast = null;
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> {
binding.doubleTapPlayerView.setVisibility(View.VISIBLE);
binding.castController.setVisibility(View.GONE);
};
mainHandler.post(myRunnable);
} catch (IOException e) {
e.printStackTrace();
}
@ -721,24 +758,35 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> {
invalidateOptionsMenu();
binding.castLoader.setVisibility(View.VISIBLE);
player.setPlayWhenReady(false);
binding.doubleTapPlayerView.setVisibility(View.GONE);
binding.castController.setVisibility(View.VISIBLE);
dialog.dismiss();
};
mainHandler.post(myRunnable);
if (!chromeCast.isConnected()) {
chromeCast.connect();
}
myRunnable = this::invalidateOptionsMenu;
mainHandler.post(myRunnable);
Status status = chromeCast.getStatus();
if (chromeCast.isAppAvailable(CAST_ID) && !status.isAppRunning(CAST_ID)) {
chromeCast.launchApp(CAST_ID);
}
mainHandler.post(myRunnable);
if (chromeCastVideoURL != null) {
if (player != null && player.getCurrentPosition() > 0) {
chromeCastVideoURL += "?start=" + (player.getCurrentPosition() / 1000);
}
String mime = MimeTypeMap.getFileExtensionFromUrl(chromeCastVideoURL);
chromeCast.setRequestTimeout(120000);
chromeCast.load(peertube.getTitle(), null, chromeCastVideoURL, mime);
chromeCast.play();
binding.castPlay.setImageResource(R.drawable.ic_baseline_pause_32);
}
myRunnable = () -> binding.castLoader.setVisibility(View.GONE);
mainHandler.post(myRunnable);
} catch (IOException | GeneralSecurityException e) {
e.printStackTrace();
}
@ -1301,6 +1349,9 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
@Override
public void onConfigurationChanged(@NotNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (binding.castController.getVisibility() == View.VISIBLE) {
return;
}
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
if (mode != Helper.VIDEO_MODE_WEBVIEW) {
openFullscreenDialog();
@ -1376,7 +1427,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
if (player != null && (!isPlayInMinimized || !playInMinimized)) {
player.setPlayWhenReady(false);
} else if (playInMinimized) {
} else if (playInMinimized && binding.castController.getVisibility() != View.VISIBLE) {
enterVideoMode();
}
}

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32dp"
android:height="32dp"
android:tint="#FFFFFF"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M6,19h4L10,5L6,5v14zM14,5v14h4L18,5h-4z" />
</vector>

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32dp"
android:height="32dp"
android:tint="#FFFFFF"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M8,5v14l11,-7z" />
</vector>

View File

@ -67,6 +67,59 @@
app:yt_playerView="@+id/doubleTapPlayerView"
android:gravity="center" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/cast_controller"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
android:visibility="gone">
<ImageView
android:id="@+id/cast_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/play"
android:src="@drawable/ic_baseline_play_arrow_32"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/cast_loader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<TextView
android:id="@+id/cast_loader_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/please_wait"
android:textColor="?colorAccent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/cast_loader_small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.github.ybq.android.spinkit.SpinKitView
android:id="@+id/cast_loader_small"
style="@style/progressBottom"
android:layout_width="wrap_content"
android:layout_height="18dp"
android:layout_gravity="center"
android:layout_marginStart="5dp"
app:SpinKit_Color="?colorAccent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/cast_loader_text"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<app.fedilab.fedilabtube.webview.CustomWebview
android:id="@+id/webview_video"
android:layout_width="match_parent"