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

Add method to change playback speed #101

Closed
PierfrancescoSoffritti opened this issue Mar 25, 2018 · 34 comments
Closed

Add method to change playback speed #101

PierfrancescoSoffritti opened this issue Mar 25, 2018 · 34 comments

Comments

@PierfrancescoSoffritti
Copy link
Owner

No description provided.

@PierfrancescoSoffritti
Copy link
Owner Author

the method setPlaybackRate seem not to be working on mobile.

@leavjenn
Copy link

leavjenn commented Apr 3, 2018

Hi, it can be achieved by changing the WebView user agent, i.e. in WebViewYouTubePlayer:

String desktopAgent = "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0";
getSettings().setUserAgentString(desktopAgent);

Great lib, thanks for your work!

@PierfrancescoSoffritti
Copy link
Owner Author

Hi, interesting! I didn't know that. It's a nice little hack.

The problem with hacks is that they are usually not reliable long term. Therefore not the best solution for a library.
What happens if after a few years Google changes something in WebView or in the IFrame API? that feature (or the entire library) may broke. This will result in every app using the lib being broken.

I will try to find a way to integrate this as an option (not the default implementation), so that who enables it must know what he's doing.

@leavjenn
Copy link

leavjenn commented Apr 3, 2018

Yeah, make it as an option would be an throughly consideration.

@thesultanster
Copy link

Dude you are so awesome. I will literally send you money @PierfrancescoSoffritti if you implement this.

@PierfrancescoSoffritti
Copy link
Owner Author

PierfrancescoSoffritti commented May 25, 2018

The problem with this is that if I implement it, it will be a broken feature for everyone not using the hack of changing the user agent. Therefore the YouTubePlayer interface would have to expose a bunch of methods that will work only sometimes. It doesn't look to me like a particularly elegant solution.

@anmolgooded
Copy link

Any updates on this issue? Did someone find a workaround to achieve it?

Hi, it can be achieved by changing the WebView user agent, i.e. in WebViewYouTubePlayer:

String desktopAgent = "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0";
getSettings().setUserAgentString(desktopAgent);

Great lib, thanks for your work!

Hi, how can I implement it?

@PierfrancescoSoffritti
Copy link
Owner Author

This is still not possible without using hacks.

If you want to use the solution suggested by @leavjenn feel free to fork the library and make the change yourself.

@anmolgooded
Copy link

This is still not possible without using hacks.

If you want to use the solution suggested by @leavjenn feel free to fork the library and make the change yourself.

Thanks! I implemented it.

@zanynik
Copy link

zanynik commented Mar 26, 2019

Hi guys, any progress on this ?
Waiting for this feature eagerly.

@PierfrancescoSoffritti
Copy link
Owner Author

Hi @zanynik unfortunately this is still not possible.

@sanjeev00
Copy link

Can I someone guide me on how to change playback speed. I am beginner and I am desparately in need of this of feature.Any Help would be highly appreciated

@prakashraooo
Copy link

Plz add playback speed change option .
Really great work

@akhilgite
Copy link

Its April 2020. Still I don't see any api for playback speed. @PierfrancescoSoffritti can you please suggest anything to add playback speed in youtube player view in android?

@PierfrancescoSoffritti
Copy link
Owner Author

I think it's still not possible, but haven't tried recently. You're welcome to explore the YouTube IFrame player api and submitting a pull request, in case things changed.

@t104360088
Copy link

@PierfrancescoSoffritti
Hi, you can use setPlaybackRate in IFrame

@sajithlaldev
Copy link

This is still not possible without using hacks.
If you want to use the solution suggested by @leavjenn feel free to fork the library and make the change yourself.

Thanks! I implemented it.

How? can you explain?? contact mail : sajithlal65@gmail.com

@tarungupta810
Copy link

@leavjenn @sajithlaldev @anmolgooded Hi if any of you implemented this please share a sample code and other details , it would be very helpful for me.
Thanks in Advance

@vkfan
Copy link

vkfan commented Aug 2, 2021

@PierfrancescoSoffritti document.querySelector('video').playbackRate = 0.5; I just applied this js while playing youtube video in webview. Can you use the same in this library?

@PierfrancescoSoffritti
Copy link
Owner Author

You can, but it's not using public API, so it will inevitably break eventually.

@Serkali-sudo
Copy link
Contributor

Serkali-sudo commented Nov 26, 2021

i added video speed function in my fork : https://github.com/Serkali-sudo/android-youtube-player (it is default iframe setPlayback rate implementation but it works)
https://github.com/Serkali-sudo/android-youtube-player#setting-video-speed

@rahulsain-ingeniumedu
Copy link

i added video speed function in my fork : https://github.com/Serkali-sudo/android-youtube-player (it is default iframe setPlayback rate implementation but it works) https://github.com/Serkali-sudo/android-youtube-player#setting-video-speed

can you make a PR and merge it @PierfrancescoSoffritti

@Serkali-sudo
Copy link
Contributor

Serkali-sudo commented Nov 30, 2021

i added video speed function in my fork : https://github.com/Serkali-sudo/android-youtube-player (it is default iframe setPlayback rate implementation but it works) https://github.com/Serkali-sudo/android-youtube-player#setting-video-speed

can you make a PR and merge it @PierfrancescoSoffritti

you can just download my fork and add as a module in android studio.There is no any new update anyways

@rahulsain
Copy link

i added video speed function in my fork : https://github.com/Serkali-sudo/android-youtube-player (it is default iframe setPlayback rate implementation but it works) https://github.com/Serkali-sudo/android-youtube-player#setting-video-speed

can you make a PR and merge it @PierfrancescoSoffritti

you can just download my fork and add as a module in android studio.There is no any new update anyways

how to add it as a module can you guide me?

@Serkali-sudo
Copy link
Contributor

i added video speed function in my fork : https://github.com/Serkali-sudo/android-youtube-player (it is default iframe setPlayback rate implementation but it works) https://github.com/Serkali-sudo/android-youtube-player#setting-video-speed

can you make a PR and merge it @PierfrancescoSoffritti

you can just download my fork and add as a module in android studio.There is no any new update anyways

how to add it as a module can you guide me?

There is 2 or more ways of doing this :

1 - In android studio select "File -> New -> Import Module" after selecting that it is going to ask for file path of module.Select "core" folder on the project(in my fork) and after that click finish and it should be added.

But if you are using Arctic Fox version of android studio and first method didnt worked. Then you can add it manually as explained below

2-(Alternative Way): First of all you need to download my fork and move "core" folder and "dependencies.gradle" file to your project file path.After that open "settings.gradle" from gradle script in android studio.after that add: include ':core'
and then go to "build gradle(module version)" and below dependencies add: implementation project(path: ':core')

Now click "sync now" and it should work now For more info :https://stackoverflow.com/a/69678559

@PierfrancescoSoffritti
Copy link
Owner Author

PierfrancescoSoffritti commented Dec 1, 2021

hey @Serkali-sudo , so you're calling the public API method of the iframe player? or did you make some custom implementation?

Last time i tried this wasn't working on mobile phones, but maybe YouTube fixed it since then. Over the Christmas holidays i can play with it. If it works I will add it to the main lib.

Feel free to send a pull request if you want :)

@Serkali-sudo
Copy link
Contributor

Serkali-sudo commented Dec 1, 2021

hey @Serkali-sudo , so you're calling the public API method of the iframe player? or did you make some custom implementation?

Last time i tried this wasn't working on mobile phones, but maybe YouTube fixed it since then. Over the Christmas holidays i can play with it. If it works I will add it to the main lib.

Feel free to send a pull request if you want :)

@PierfrancescoSoffritti Public API method works now.I just added player.setPlaybackRate method from iframe api. See doc : https://developers.google.com/youtube/iframe_api_reference

@PierfrancescoSoffritti
Copy link
Owner Author

Nice, then i will take a look before the new year.

@rahulsain-ingeniumedu
Copy link

rahulsain-ingeniumedu commented Dec 2, 2021

@Serkali-sudo can you add setVideoSpeed function in this file too?

https://github.com/Serkali-sudo/android-youtube-player/blob/master/core/src/main/java/com/pierfrancescosoffritti/androidyoutubeplayer/core/player/views/YouTubePlayerView.kt

@Serkali-sudo
Copy link
Contributor

@Serkali-sudo can you add setVideoSpeed function in this file too?

https://github.com/Serkali-sudo/android-youtube-player/blob/master/core/src/main/java/com/pierfrancescosoffritti/androidyoutubeplayer/core/player/views/YouTubePlayerView.kt

@rahulsain-ingeniumedu There is no need to add that you can just call that function from YoutubePlayer just like using play() or pause()
Here's basic sample:

public class SpeedExample extends AppCompatActivity {
    private YouTubePlayer mYoutubePlayer;
    private YouTubePlayerView youTubePlayerView;
    private Button setVideoSpeed;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        youTubePlayerView = findViewById(R.id.youtube_player_view);
        setVideoSpeed = findViewById(R.id.setVideoSpeed);

        setVideoSpeed.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mYoutubePlayer != null) {
                    mYoutubePlayer.setVideoSpeed(0.5);
                }
            }
        });

        getLifecycle().addObserver(youTubePlayerView);
        youTubePlayerView.addYouTubePlayerListener(new AbstractYouTubePlayerListener() {
            @Override
            public void onReady(@NonNull YouTubePlayer youTubePlayer) {
                String videoId = "dQw4w9WgXcQ";
                youTubePlayer.loadVideo(videoId, 0);
                mYoutubePlayer = youTubePlayer;
            }
        });
    }
}

@rahulsain-ingeniumedu
Copy link

rahulsain-ingeniumedu commented Dec 3, 2021

@Serkali-sudo can you add setVideoSpeed function in this file too?
https://github.com/Serkali-sudo/android-youtube-player/blob/master/core/src/main/java/com/pierfrancescosoffritti/androidyoutubeplayer/core/player/views/YouTubePlayerView.kt

@rahulsain-ingeniumedu There is no need to add that you can just call that function from YoutubePlayer just like using play() or pause() Here's basic sample:

public class SpeedExample extends AppCompatActivity {
    private YouTubePlayer mYoutubePlayer;
    private YouTubePlayerView youTubePlayerView;
    private Button setVideoSpeed;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        youTubePlayerView = findViewById(R.id.youtube_player_view);
        setVideoSpeed = findViewById(R.id.setVideoSpeed);

        setVideoSpeed.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mYoutubePlayer != null) {
                    mYoutubePlayer.setVideoSpeed(0.5);
                }
            }
        });

        getLifecycle().addObserver(youTubePlayerView);
        youTubePlayerView.addYouTubePlayerListener(new AbstractYouTubePlayerListener() {
            @Override
            public void onReady(@NonNull YouTubePlayer youTubePlayer) {
                String videoId = "dQw4w9WgXcQ";
                youTubePlayer.loadVideo(videoId, 0);
                mYoutubePlayer = youTubePlayer;
            }
        });
    }
}

yes it is working, we can add speed from 0.1f to 2f?

@PierfrancescoSoffritti
Copy link
Owner Author

PierfrancescoSoffritti commented Dec 5, 2021

Hi, I have added support for changing playback speed both to core and chromecast library: 687ecf0

Thanks a lot @Serkali-sudo for the help!

@PierfrancescoSoffritti
Copy link
Owner Author

The change is available in version 11.0.0

@baokiinkk
Copy link

@PierfrancescoSoffritti how to change speed 0.75, you can more enum. please

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

No branches or pull requests