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

Autoplay does not work upon videoId changes #176

Closed
hoangvvo opened this issue Aug 15, 2021 · 8 comments
Closed

Autoplay does not work upon videoId changes #176

hoangvvo opened this issue Aug 15, 2021 · 8 comments
Labels
bug Something isn't working

Comments

@hoangvvo
Copy link
Contributor

Describe the bug

If videoId is changed after the first render of YoutubePlayer, the video will not autoplay despite play prop being true

To Reproduce

https://snack.expo.dev/zeiphINXa

Steps to reproduce the behavior:

  1. Click Toggle Render -> see that video is autoplayed.
  2. Click Switch video -> video is no longer played
  3. Click Toggle Render twice to unmount and remount component -> video is autoplayed

Expected behavior

Video should always be played or paused based on the play prop

I tested this on both Expo and bare React Native project.

Smartphone (Expo):

  • Device: n/a
  • OS + version: Android/iOS
  • react-native-youtube-iframe version 11.6.2
  • react-native-webview version ^2.1.1
  • Expo version 42.0.0

Smartphone (Bare):

  • Device: Poco X3 Pro
  • OS + version: Android 11
  • react-native-youtube-iframe version 11.6.2
  • react-native-webview version ^2.1.1
  • Expo version 42.0.0

Thank you.

@hoangvvo hoangvvo changed the title Autoplay not working upon videoId changes Autoplay does not work upon videoId changes Aug 15, 2021
@LonelyCpp LonelyCpp added the bug Something isn't working label Aug 15, 2021
@LonelyCpp
Copy link
Owner

hmm yes.

A whole new js player instance is created when the videoId is changed. But the RN code was not taking this into consideration.

this seems to have fixed it - dad252a, but I couldn't fully test it.

I'll release a patch version as soon as I test it for a bit :)

@hoangvvo
Copy link
Contributor Author

hoangvvo commented Aug 17, 2021

Thanks for the response. I have a question though, why would we recreate the js player instead of just asking the existed player to call player.loadVideoById, possible via injectJavaScript? That is probably also applicable to other props changes.

@LonelyCpp
Copy link
Owner

@hoangvvo the fix is published in v2.1.2. let me know if it works :)


call player.loadVideoById

yep, this is definitely a better way to do it. I've added this to a todo list of APIs to port in a future update!

(https://github.com/LonelyCpp/react-native-youtube-iframe/projects/3)

@hoangvvo
Copy link
Contributor Author

@hoangvvo the fix is published in v2.1.2. let me know if it works :)


call player.loadVideoById

yep, this is definitely a better way to do it. I've added this to a todo list of APIs to port in a future update!

(https://github.com/LonelyCpp/react-native-youtube-iframe/projects/3)

Awesome, I'd love to open a PR for that too if you don't mind

@LonelyCpp
Copy link
Owner

PRs are welcome! 💯

@hoangvvo
Copy link
Contributor Author

@LonelyCpp I can confirm that the new version works! I will try to put together a PR some time soon for the discussed refactor though.

Thanks for the work!

@vishwadeepghimirezph
Copy link

vishwadeepghimirezph commented Nov 16, 2021

Thank you @LonelyCpp and @hoangvvo. Issue exist for iOS simulator. Working well in physical iOS device. @LonelyCpp @hoangvvo

@LonelyCpp
Copy link
Owner

@vishwadeepghimirezph this was published with v2.2.0

try it out and let me know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants