Some changes

This commit is contained in:
Thomas 2024-01-22 17:16:09 +01:00
parent c778c71306
commit e18db746a0
7 changed files with 53 additions and 17 deletions

View file

@ -139,9 +139,11 @@ dependencies {
annotationProcessor "com.github.bumptech.glide:compiler:4.12.0" annotationProcessor "com.github.bumptech.glide:compiler:4.12.0"
implementation 'jp.wasabeef:glide-transformations:4.3.0' implementation 'jp.wasabeef:glide-transformations:4.3.0'
implementation 'com.github.penfeizhou.android.animation:glide-plugin:2.23.0' implementation 'com.github.penfeizhou.android.animation:glide-plugin:2.23.0'
implementation 'androidx.media3:media3-exoplayer-hls:1.2.1'
implementation "androidx.media3:media3-exoplayer:1.2.1" implementation "androidx.media3:media3-exoplayer:1.2.1"
implementation "androidx.media3:media3-exoplayer-dash:1.2.1" implementation "androidx.media3:media3-exoplayer-dash:1.2.1"
implementation "androidx.media3:media3-ui:1.2.1" implementation "androidx.media3:media3-ui:1.2.1"
implementation "androidx.media3:media3-session:1.2.1"
implementation "androidx.viewpager2:viewpager2:1.0.0" implementation "androidx.viewpager2:viewpager2:1.0.0"

View file

@ -29,6 +29,7 @@ import android.webkit.MimeTypeMap;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.media3.common.Player; import androidx.media3.common.Player;
import androidx.media3.exoplayer.ExoPlayer;
import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.dialog.MaterialAlertDialogBuilder;
@ -53,7 +54,7 @@ public class BasePeertubeActivity extends BaseBarActivity {
protected ActivityPeertubeBinding binding; protected ActivityPeertubeBinding binding;
protected VideoData.Video peertube; protected VideoData.Video peertube;
protected Player player; protected ExoPlayer player;
protected String videoURL; protected String videoURL;
protected String subtitlesStr; protected String subtitlesStr;

View file

@ -47,12 +47,12 @@ import android.content.res.Configuration;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.media.session.PlaybackState;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.support.v4.media.session.MediaSessionCompat;
import android.text.Html; import android.text.Html;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.Spanned; import android.text.Spanned;
@ -77,6 +77,7 @@ import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.LinearLayoutCompat; import androidx.appcompat.widget.LinearLayoutCompat;
@ -86,6 +87,7 @@ import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.DrawableCompat; import androidx.core.graphics.drawable.DrawableCompat;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.media3.common.C;
import androidx.media3.common.Format; import androidx.media3.common.Format;
import androidx.media3.common.MediaItem; import androidx.media3.common.MediaItem;
import androidx.media3.common.MimeTypes; import androidx.media3.common.MimeTypes;
@ -96,19 +98,23 @@ import androidx.media3.common.VideoSize;
import androidx.media3.datasource.DataSource; import androidx.media3.datasource.DataSource;
import androidx.media3.datasource.DefaultDataSource; import androidx.media3.datasource.DefaultDataSource;
import androidx.media3.exoplayer.ExoPlayer; import androidx.media3.exoplayer.ExoPlayer;
import androidx.media3.exoplayer.hls.HlsMediaSource;
import androidx.media3.exoplayer.source.MergingMediaSource; import androidx.media3.exoplayer.source.MergingMediaSource;
import androidx.media3.exoplayer.source.ProgressiveMediaSource; import androidx.media3.exoplayer.source.ProgressiveMediaSource;
import androidx.media3.exoplayer.source.SingleSampleMediaSource; import androidx.media3.exoplayer.source.SingleSampleMediaSource;
import androidx.media3.exoplayer.trackselection.AdaptiveTrackSelection; import androidx.media3.exoplayer.trackselection.AdaptiveTrackSelection;
import androidx.media3.exoplayer.trackselection.DefaultTrackSelector; import androidx.media3.exoplayer.trackselection.DefaultTrackSelector;
import androidx.media3.exoplayer.trackselection.TrackSelector; import androidx.media3.exoplayer.trackselection.TrackSelector;
import androidx.media3.session.MediaSession;
import androidx.media3.ui.AspectRatioFrameLayout; import androidx.media3.ui.AspectRatioFrameLayout;
import androidx.media3.ui.PlayerControlView; import androidx.media3.ui.PlayerControlView;
import androidx.media3.ui.DefaultTimeBar;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.github.vkay94.dtpv.DoubleTapPlayerView;
import com.github.vkay94.dtpv.youtube.YouTubeOverlay; import com.github.vkay94.dtpv.youtube.YouTubeOverlay;
import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
@ -203,7 +209,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
private Status status; private Status status;
private int flags; private int flags;
private boolean humanInteraction; private boolean humanInteraction;
private MediaSession mediaSession;
public static void hideKeyboard(Activity activity) { public static void hideKeyboard(Activity activity) {
if (activity != null && activity.getWindow() != null) { if (activity != null && activity.getWindow() != null) {
activity.getWindow().getDecorView(); activity.getWindow().getDecorView();
@ -368,6 +374,26 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
binding.doubleTapPlayerView.setDoubleTapEnabled(true); binding.doubleTapPlayerView.setDoubleTapEnabled(true);
binding.doubleTapPlayerView.setControllerShowTimeoutMs(0); binding.doubleTapPlayerView.setControllerShowTimeoutMs(0);
binding.mediaVideo.performListener(new YouTubeOverlay.PerformListener() { binding.mediaVideo.performListener(new YouTubeOverlay.PerformListener() {
@Nullable
@Override
public Boolean shouldForward(@NonNull Player player, @NonNull DoubleTapPlayerView playerView, float posX) {
if (player.getPlaybackState() == PlaybackState.STATE_ERROR ||
player.getPlaybackState() == PlaybackState.STATE_NONE ||
player.getPlaybackState() == Player.STATE_ENDED) {
playerView.cancelInDoubleTapMode();
return null;
}
if (player.getCurrentPosition() > 500 && posX < playerView.getWidth() * 0.35)
return false;
if (player.getCurrentPosition() < player.getDuration() && posX > playerView.getWidth() * 0.65)
return true;
return null;
}
@Override @Override
public void onAnimationStart() { public void onAnimationStart() {
binding.mediaVideo.setVisibility(View.VISIBLE); binding.mediaVideo.setVisibility(View.VISIBLE);
@ -1533,6 +1559,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
binding = null; binding = null;
if (player != null) { if (player != null) {
player.release(); player.release();
mediaSession = null;
} }
unregisterReceiver(); unregisterReceiver();
} }
@ -1612,13 +1639,10 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
if (playInMinimized && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && player != null) { if (playInMinimized && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && player != null) {
isPlayInMinimized = true; isPlayInMinimized = true;
setRequestedOrientationCustom(initialOrientation); setRequestedOrientationCustom(initialOrientation);
MediaSessionCompat mediaSession = new MediaSessionCompat(this, getPackageName()); mediaSession = new MediaSession.Builder(this, player).build();
MediaSessionConnector mediaSessionConnector = new MediaSessionConnector(mediaSession);
mediaSessionConnector.setPlayer(player);
PlayerControlView controlView = binding.doubleTapPlayerView.findViewById(R.id.exo_controller); PlayerControlView controlView = binding.doubleTapPlayerView.findViewById(R.id.exo_controller);
controlView.hide(); controlView.hide();
binding.doubleTapPlayerView.setControllerAutoShow(false); binding.doubleTapPlayerView.setControllerAutoShow(false);
mediaSession.setActive(true);
PictureInPictureParams params = new PictureInPictureParams.Builder().build(); PictureInPictureParams params = new PictureInPictureParams.Builder().build();
enterPictureInPictureMode(params); enterPictureInPictureMode(params);
} }

View file

@ -125,7 +125,7 @@
android:textColor="#FFBEBEBE" android:textColor="#FFBEBEBE"
android:textSize="12sp" /> android:textSize="12sp" />
<com.google.android.exoplayer2.ui.DefaultTimeBar <androidx.media3.ui.DefaultTimeBar
android:id="@id/exo_progress" android:id="@id/exo_progress"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="26dp" android:layout_height="26dp"

View file

@ -1,4 +1,5 @@
apply plugin: 'com.android.library' apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
android { android {
compileSdk 34 compileSdk 34
@ -22,10 +23,18 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8
} }
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
}
namespace 'com.github.vkay94.dtpv' namespace 'com.github.vkay94.dtpv'
} }
// Add a new configuration to hold your dependencies
configurations {
libConfig
}
dependencies { dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "androidx.appcompat:appcompat:1.6.1" implementation "androidx.appcompat:appcompat:1.6.1"

View file

@ -33,7 +33,7 @@ open class DoubleTapPlayerView @JvmOverloads constructor(
private var controllerRef: Int = -1 private var controllerRef: Int = -1
init { init {
gestureDetector = GestureDetectorCompat(context, gestureListener) gestureDetector = GestureDetectorCompat(context!!, gestureListener)
// Check whether controller is set through XML // Check whether controller is set through XML
attrs?.let { attrs?.let {

View file

@ -169,16 +169,16 @@ internal class CircleClipTapView(context: Context?, attrs: AttributeSet) :
} }
addListener(object : Animator.AnimatorListener { addListener(object : Animator.AnimatorListener {
override fun onAnimationStart(animation: Animator?) { override fun onAnimationStart(animation: Animator) {
visibility = VISIBLE visibility = VISIBLE
} }
override fun onAnimationEnd(animation: Animator?) { override fun onAnimationEnd(animation: Animator) {
if (!forceReset) performAtEnd() if (!forceReset) performAtEnd()
} }
override fun onAnimationRepeat(animation: Animator?) {} override fun onAnimationRepeat(animation: Animator) {}
override fun onAnimationCancel(animation: Animator?) {} override fun onAnimationCancel(animation: Animator) {}
}) })
} }
} }
@ -208,14 +208,14 @@ internal class CircleClipTapView(context: Context?, attrs: AttributeSet) :
updatePathShape() updatePathShape()
} }
override fun onDraw(canvas: Canvas?) { override fun onDraw(canvas: Canvas) {
super.onDraw(canvas) super.onDraw(canvas)
// Background // Background
canvas?.clipPath(shapePath) canvas.clipPath(shapePath)
canvas?.drawPath(shapePath, backgroundPaint) canvas.drawPath(shapePath, backgroundPaint)
// Circle // Circle
canvas?.drawCircle(cX, cY, currentRadius, circlePaint) canvas.drawCircle(cX, cY, currentRadius, circlePaint)
} }
} }