react-native-youtube
react-native-youtube copied to clipboard
locking orientation after closing YouTubeStandaloneAndroid player
My app is portrait locked and I implemented YouTubeStandaloneAndroid for my button. The Library works fine with lightboxMode. I can change device's orientation to landscape for full screen player. However it's unlocked my app's orientation lock on componentDidMount. I have tried to lock orientation again when player exited, but it's not work.
YouTubeStandaloneAndroid.playVideo({ apiKey: 'YOUR_API_KEY', // Your YouTube Developer API Key videoId: '2MpUj-Aua48', // YouTube video ID autoplay: true, // Autoplay the video lightboxMode: true, }) .then(() => {console.log('Standalone Player Exited');}) .catch(errorMessage => console.error(errorMessage)) .finally(() => { this.setState({ isPlayingVideo: false }); Orientation.lockToPortrait(); });
"react-native": "0.51.0" "react-native-youtube": "^1.1.0" "react-native-orientation": "^3.1.0",
Edit:
I tried to disable lightboxMode
, tried to play a video without tilting device (keep in portrait mode), then close the video. Then app rotated twice, first to landscape, then back to portrait.
I also tried not to call Orientation.lockToPotrait()
after player exited. App still rotated twice by itself, then it wouldn't rotate anymore even if i switch device's orientation by hand.
YouTubeStandaloneAndroid present portrait video as with landscape. How can it play vertical fullscreen?? iOS works well
I got portrait fullscreen with this solution - https://medium.com/@mridx/youtubestandaloneandroid-play-youtube-videos-in-portrait-mode-in-android-react-native-hack-edd0fdce6088 But I can't go back to portrait after toggling landscape
@kofsiwon thanks for the solution. It works!