YouTubePlayer: going fullscreen from portrait phone orientation can easily get out of fullscreen









up vote
1
down vote

favorite












If you hold the phone in portrait orientation and you click fullscreen button (of YouTubePlayerView) it easily can get you back (turns off fullscreen) if you shake the phone a little bit



Official YouTube app works normally: you press fullscreen button while holding the phone in portrait orientation and if you shake it a little bit it still stays in fullscreen landscape mode. And if you rotate your phone to landscape orientation and back again to portrait orientation only then it turns off fullscreen (as it should be)



So I would like to implement the same behavior from official YouTube app



I tried to set different Fullscreen flags for YouTubePlayer but it doesn't affect anything



activity manifest



<activity
android:label="@string/playerview_demo_name"
android:name=".PlayerViewDemoActivity"
android:screenOrientation="user"
android:configChanges="orientation|screenSize|keyboardHidden">
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>


activity java



public class PlayerViewDemoActivity extends YouTubeFailureRecoveryActivity {

@Override
public void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.playerview);
YouTubePlayerView youTubeView = findViewById(R.id.youtube_view);
youTubeView.initialize(DeveloperKey.DEVELOPER_KEY, this);


@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
boolean wasRestored)
if (!wasRestored)
player.cueVideo("wKJ9KzGQq0w");
/*
FULLSCREEN_FLAG_CONTROL_ORIENTATION;
FULLSCREEN_FLAG_CONTROL_SYSTEM_UI;
FULLSCREEN_FLAG_ALWAYS_FULLSCREEN_IN_LANDSCAPE;
FULLSCREEN_FLAG_CUSTOM_LAYOUT;
*/
player.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_ORIENTATION);



@Override
protected YouTubePlayer.Provider getYouTubePlayerProvider()
return (YouTubePlayerView) findViewById(R.id.youtube_view);




Mb YouTube app does something like this:



after pressing fullscreen button they set (only if programmatic phone display's orientation was in portrait mode)



setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);



then they use device sensors to detect approximate orientation (if you hold the phone in portrait/landscape orientation) - Detect Android device orientation (NOT screen orientation)



when you rotate the phone with your hands to landscape orientation they set



setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER);










share|improve this question



























    up vote
    1
    down vote

    favorite












    If you hold the phone in portrait orientation and you click fullscreen button (of YouTubePlayerView) it easily can get you back (turns off fullscreen) if you shake the phone a little bit



    Official YouTube app works normally: you press fullscreen button while holding the phone in portrait orientation and if you shake it a little bit it still stays in fullscreen landscape mode. And if you rotate your phone to landscape orientation and back again to portrait orientation only then it turns off fullscreen (as it should be)



    So I would like to implement the same behavior from official YouTube app



    I tried to set different Fullscreen flags for YouTubePlayer but it doesn't affect anything



    activity manifest



    <activity
    android:label="@string/playerview_demo_name"
    android:name=".PlayerViewDemoActivity"
    android:screenOrientation="user"
    android:configChanges="orientation|screenSize|keyboardHidden">
    <intent-filter >
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    </activity>


    activity java



    public class PlayerViewDemoActivity extends YouTubeFailureRecoveryActivity {

    @Override
    public void onCreate(Bundle savedInstanceState)
    super.onCreate(savedInstanceState);
    setContentView(R.layout.playerview);
    YouTubePlayerView youTubeView = findViewById(R.id.youtube_view);
    youTubeView.initialize(DeveloperKey.DEVELOPER_KEY, this);


    @Override
    public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
    boolean wasRestored)
    if (!wasRestored)
    player.cueVideo("wKJ9KzGQq0w");
    /*
    FULLSCREEN_FLAG_CONTROL_ORIENTATION;
    FULLSCREEN_FLAG_CONTROL_SYSTEM_UI;
    FULLSCREEN_FLAG_ALWAYS_FULLSCREEN_IN_LANDSCAPE;
    FULLSCREEN_FLAG_CUSTOM_LAYOUT;
    */
    player.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_ORIENTATION);



    @Override
    protected YouTubePlayer.Provider getYouTubePlayerProvider()
    return (YouTubePlayerView) findViewById(R.id.youtube_view);




    Mb YouTube app does something like this:



    after pressing fullscreen button they set (only if programmatic phone display's orientation was in portrait mode)



    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);



    then they use device sensors to detect approximate orientation (if you hold the phone in portrait/landscape orientation) - Detect Android device orientation (NOT screen orientation)



    when you rotate the phone with your hands to landscape orientation they set



    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER);










    share|improve this question

























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      If you hold the phone in portrait orientation and you click fullscreen button (of YouTubePlayerView) it easily can get you back (turns off fullscreen) if you shake the phone a little bit



      Official YouTube app works normally: you press fullscreen button while holding the phone in portrait orientation and if you shake it a little bit it still stays in fullscreen landscape mode. And if you rotate your phone to landscape orientation and back again to portrait orientation only then it turns off fullscreen (as it should be)



      So I would like to implement the same behavior from official YouTube app



      I tried to set different Fullscreen flags for YouTubePlayer but it doesn't affect anything



      activity manifest



      <activity
      android:label="@string/playerview_demo_name"
      android:name=".PlayerViewDemoActivity"
      android:screenOrientation="user"
      android:configChanges="orientation|screenSize|keyboardHidden">
      <intent-filter >
      <action android:name="android.intent.action.MAIN" />
      <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
      </activity>


      activity java



      public class PlayerViewDemoActivity extends YouTubeFailureRecoveryActivity {

      @Override
      public void onCreate(Bundle savedInstanceState)
      super.onCreate(savedInstanceState);
      setContentView(R.layout.playerview);
      YouTubePlayerView youTubeView = findViewById(R.id.youtube_view);
      youTubeView.initialize(DeveloperKey.DEVELOPER_KEY, this);


      @Override
      public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
      boolean wasRestored)
      if (!wasRestored)
      player.cueVideo("wKJ9KzGQq0w");
      /*
      FULLSCREEN_FLAG_CONTROL_ORIENTATION;
      FULLSCREEN_FLAG_CONTROL_SYSTEM_UI;
      FULLSCREEN_FLAG_ALWAYS_FULLSCREEN_IN_LANDSCAPE;
      FULLSCREEN_FLAG_CUSTOM_LAYOUT;
      */
      player.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_ORIENTATION);



      @Override
      protected YouTubePlayer.Provider getYouTubePlayerProvider()
      return (YouTubePlayerView) findViewById(R.id.youtube_view);




      Mb YouTube app does something like this:



      after pressing fullscreen button they set (only if programmatic phone display's orientation was in portrait mode)



      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);



      then they use device sensors to detect approximate orientation (if you hold the phone in portrait/landscape orientation) - Detect Android device orientation (NOT screen orientation)



      when you rotate the phone with your hands to landscape orientation they set



      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER);










      share|improve this question















      If you hold the phone in portrait orientation and you click fullscreen button (of YouTubePlayerView) it easily can get you back (turns off fullscreen) if you shake the phone a little bit



      Official YouTube app works normally: you press fullscreen button while holding the phone in portrait orientation and if you shake it a little bit it still stays in fullscreen landscape mode. And if you rotate your phone to landscape orientation and back again to portrait orientation only then it turns off fullscreen (as it should be)



      So I would like to implement the same behavior from official YouTube app



      I tried to set different Fullscreen flags for YouTubePlayer but it doesn't affect anything



      activity manifest



      <activity
      android:label="@string/playerview_demo_name"
      android:name=".PlayerViewDemoActivity"
      android:screenOrientation="user"
      android:configChanges="orientation|screenSize|keyboardHidden">
      <intent-filter >
      <action android:name="android.intent.action.MAIN" />
      <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
      </activity>


      activity java



      public class PlayerViewDemoActivity extends YouTubeFailureRecoveryActivity {

      @Override
      public void onCreate(Bundle savedInstanceState)
      super.onCreate(savedInstanceState);
      setContentView(R.layout.playerview);
      YouTubePlayerView youTubeView = findViewById(R.id.youtube_view);
      youTubeView.initialize(DeveloperKey.DEVELOPER_KEY, this);


      @Override
      public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
      boolean wasRestored)
      if (!wasRestored)
      player.cueVideo("wKJ9KzGQq0w");
      /*
      FULLSCREEN_FLAG_CONTROL_ORIENTATION;
      FULLSCREEN_FLAG_CONTROL_SYSTEM_UI;
      FULLSCREEN_FLAG_ALWAYS_FULLSCREEN_IN_LANDSCAPE;
      FULLSCREEN_FLAG_CUSTOM_LAYOUT;
      */
      player.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_CONTROL_ORIENTATION);



      @Override
      protected YouTubePlayer.Provider getYouTubePlayerProvider()
      return (YouTubePlayerView) findViewById(R.id.youtube_view);




      Mb YouTube app does something like this:



      after pressing fullscreen button they set (only if programmatic phone display's orientation was in portrait mode)



      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);



      then they use device sensors to detect approximate orientation (if you hold the phone in portrait/landscape orientation) - Detect Android device orientation (NOT screen orientation)



      when you rotate the phone with your hands to landscape orientation they set



      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER);







      android android-youtube-api






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 20:38

























      asked Nov 10 at 20:08









      user924

      490221




      490221



























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242972%2fyoutubeplayer-going-fullscreen-from-portrait-phone-orientation-can-easily-get-o%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242972%2fyoutubeplayer-going-fullscreen-from-portrait-phone-orientation-can-easily-get-o%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Top Tejano songwriter Luis Silva dead of heart attack at 64

          ReactJS Fetched API data displays live - need Data displayed static

          政党