PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, April 15, 2022

[FIXED] How to switch to full screen(rotate to landscape on click of full-screen button on YouTube player gui) in React Native youtube iframe?

 April 15, 2022     expo, iframe, react-native, youtube-api, youtube-iframe-api     No comments   

Issue

I want to switch the player to landscape mode on click of the full-screen button on the player gui. I am using expo so i used expo orientation, I am able to switch to the landscape mode by calling a function on onfullscreenchange prop, but after exiting fullscreen mode the app is locked in landscape mode. How do i fix it?

my code:

VideoPlayer.js

    import React from "react";
    import { View, Dimensions } from "react-native";
    import YoutubePlayer from "react-native-youtube-iframe";
    
    import * as ScreenOrientation from "expo-screen-orientation";
    
    const VideoPlayer = () => {
      function setOrientation() {
        if (Dimensions.get("window").height > Dimensions.get("window").width) {
          //Device is in portrait mode, rotate to landscape mode.
          ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.LANDSCAPE);
        } else {
          //Device is in landscape mode, rotate to portrait mode.
          ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.PORTRAIT);
        }
      }
    
      return (
        <View
          style={{
            width: "100%",
            height: 220,
          }}
        >
          <YoutubePlayer
            height={300}
            play={false}
            videoId={"Dv7gLpW91DM"}
            onFullScreenChange={setOrientation}
          />
        </View>
      );
    };
    
    export default VideoPlayer;

Solution

You can use the boolean returned from onFullScreenChange to determine if the player is in fullscreen or not and from there, set the correct orientation, I'm unable to test now but it should be something like that

onFullScreenChange={isFullscreen => { 
    if(isFullscreen) { setOrientationToPortrait() } 
    else { setOrientationToLandscape() }
}


Answered By - yemd
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing