Closed AdisAlagic closed 3 years ago
XML
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.github.vkay94.dtpv.DoubleTapPlayerView
android:id="@+id/player"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000"
app:controller_layout_id="@layout/video_controls"
app:dtpv_controller="@id/youtube_overlay"
/>
<com.github.vkay94.dtpv.youtube.YouTubeOverlay
android:id="@+id/youtube_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible"
app:yt_backgroundCircleColor="#608E4EC7"
app:yt_seekSeconds="15"
app:yt_playerView="@id/player" />
<ProgressBar
android:id="@+id/load"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Hmm, I tried your XML and it works as expected. Could you give some more information? Like:
Regarding the Android version and manufacturer: it would be nice if you could check whether you encounter the problem in the sample app: https://github.com/vkay94/DoubleTapPlayerView/releases/download/1.0.1/dtpv_demo_1.0.1.apk
Regarding the media type: I checked MP4 (and HLS in the past) and it works without problems, but I didn't try other formats. Do you mind share the loading code? Something like this, so I can check.
Thanks
I use Warmhole 29
as compileSDK and 29 SDK (Android 10) on my phone.
HLS for video.
My phone is Xiaomi but OS is PixelExperience.
There is no problem with your demo app.
Here is my loading code:
private HlsMediaSource hlsFromURI(Uri uri) {
if (currentVideo != null) {
return (HlsMediaSource) currentVideo;
}
if (uri == null) {
return null;
}
DataSource.Factory factory = new DefaultDataSourceFactory(this, userAgent);
return new HlsMediaSource.Factory(factory).createMediaSource(MediaItem.fromUri(uri));
}
I initialize DoubleTapView and YouTubeOverlay like this:
protected void onCreate(@Nullable Bundle savedInstanceState) {
playerView = findViewById(R.id.player);
youTubeOverlay = findViewById(R.id.youtube_overlay);
youTubeOverlay.performListener(new YouTubeOverlay.PerformListener() {
@Override
public void onAnimationStart() {
youTubeOverlay.setVisibility(View.VISIBLE);
}
@Override
public void onAnimationEnd() {
youTubeOverlay.setVisibility(View.INVISIBLE);
}
@NotNull
@Override
public Boolean shouldForward(@NotNull Player player, @NotNull DoubleTapPlayerView doubleTapPlayerView, float v) {
return true;
}
});
//Some code
initPlayer();
}
private void initPlayer() {
exoPlayer = new SimpleExoPlayer.Builder(this).setTrackSelector(trackSelector).build();
exoPlayer.addListener(listener);
playerView.getSubtitleView().setStyle(STANDARD_CAPTION_STYLE);
youTubeOverlay.player(exoPlayer);
exoPlayer.addTextOutput(textOutput);
AudioAttributes audioAttributes = new AudioAttributes.Builder().setUsage(C.USAGE_MEDIA).setContentType(C.CONTENT_TYPE_MOVIE).build();
exoPlayer.setAudioAttributes(audioAttributes, true);
playerView.setPlayer(exoPlayer);
playerView.getSubtitleView().setApplyEmbeddedFontSizes(USE_SSA_STANDARD_PARSER);
playerView.getSubtitleView().setApplyEmbeddedStyles(USE_SSA_STANDARD_PARSER);
//A lot of code
}
protected void onCreate(@Nullable Bundle savedInstanceState) { @NotNull @Override public Boolean shouldForward(@NotNull Player player, @NotNull DoubleTapPlayerView doubleTapPlayerView, float v) { return true; <= this line } }); //Some code initPlayer(); }
The reason lies in the shouldForward
overriden method that returns true
in any case (that's why in the video it is forwarding).
The method has a default implementation written in Kotlin (see here). I think you have to override it in Java (unfortunately). You could try to copy the code and apply changes to match Java (it's not much).
The method is documented. I'll think about something to make it working in Java without self-overriding in the future.
Yeah, overriting solved issue. Here is Java code:
@Override
public Boolean shouldForward(@NotNull Player player, @NotNull DoubleTapPlayerView doubleTapPlayerView, float v) {
if (player.getPlaybackState() == PlaybackState.STATE_ERROR ||
player.getPlaybackState() == PlaybackState.STATE_NONE ||
player.getPlaybackState() == PlaybackState.STATE_STOPPED) {
playerView.cancelInDoubleTapMode();
return null;
}
if (player.getCurrentPosition() > 500 && v < playerView.getWidth() * 0.35)
return false;
if (player.getCurrentPosition() < player.getDuration() && v > playerView.getWidth() * 0.65)
return true;
return null;
}
Great!
When doubleclick on left side of the screen, it starts to forwarding in a positive diraction.![ezgif com-gif-maker (1)](https://user-images.githubusercontent.com/26526921/113864444-93d3bf00-97b3-11eb-825b-c63743c7e534.gif)