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

Wrong Direction for forwarding #15

Closed
AdisAlagic opened this issue Apr 7, 2021 · 6 comments
Closed

Wrong Direction for forwarding #15

AdisAlagic opened this issue Apr 7, 2021 · 6 comments

Comments

@AdisAlagic
Copy link

When doubleclick on left side of the screen, it starts to forwarding in a positive diraction.
ezgif com-gif-maker (1)

@AdisAlagic
Copy link
Author

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>

@vkay94
Copy link
Owner

vkay94 commented Apr 7, 2021

Hmm, I tried your XML and it works as expected. Could you give some more information? Like:

  • Android version of the tested device (e.g. 8.0, 10.0, 11 etc.)
  • manufacturer (e.g. Samsung, Xioami, Huawei etc.)
  • type of the media (e.g. MP4, HLS, DASH)

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

@AdisAlagic
Copy link
Author

AdisAlagic commented Apr 7, 2021

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
   }

@vkay94
Copy link
Owner

vkay94 commented Apr 7, 2021

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.

@AdisAlagic
Copy link
Author

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;
            }

@vkay94
Copy link
Owner

vkay94 commented Apr 7, 2021

Great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@vkay94 @AdisAlagic and others