3 Replies Latest reply on Oct 28, 2011 12:05 PM by alinator11

    Best way to Set Mobile device to landscape when video plays?

    JAXIMFLASH Level 1

      I have a video player mobile app. When it starts playing video, I want to force it to switch to landscape mode. If the device is already in landscape mode, then I don't want to do anything. Once the device is in landscpae mode, then I want to turn off the auto rotate feature.

      I have found that I do not want to set stage.autoOrients to false as that may rotate the device to is default state. For example, if I turn off the autoOrients feature on a Motorola Xoom, then it rotates to its default landscae mode even if it is already in its upsideDown landscape mode - again, I don;'t wish to rotate the device if it is already in landscape mode. So to turn off the autoRotate feature, i am listening to the orientation events and stopping them from propagation.

       

      But my code isn't working properly. Sometimes it works and other times, it still plays in portrait orientation.

       

      Below is a sample of my code. Any tips on maintaining landscape orientation?

       

                          protected function onOrientationChange(e:StageOrientationEvent):void {

                                         e.preventDefault();

                                         e.stopImmediatePropagation();

                          }

                          override protected function playVideo(sURL:String):void {

                                         super.playVideo(sURL);

                                         stage.displayState = StageDisplayState.FULL_SCREEN;

                                         NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;

                                         stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING, onOrientationChange);

                                         stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, onOrientationChange);

       

                                         //if the device is not in landscape mode, then set it to landscape mode.

                                         if(stage.stageWidth < stage.stageHeight){

                                                        stage.setOrientation(StageOrientation.DEFAULT);

                                                        if(stage.stageWidth < stage.stageHeight){

                                                                       if(stage.deviceOrientation == StageOrientation.DEFAULT || stage.deviceOrientation == StageOrientation.UPSIDE_DOWN){

                                                                                      stage.setOrientation(StageOrientation.ROTATED_RIGHT);

                                                                       } else {

                                                                                      stage.setOrientation(StageOrientation.DEFAULT);

                                                                       }

                                                        }

                                         }

                          }

        • 1. Re: Best way to Set Mobile device to landscape when video plays?
          alinator11 Level 2

          You can also find out what the current width and height of your screen is to determine how the device is positioned and then react accordingly.

          • 2. Re: Best way to Set Mobile device to landscape when video plays?
            JAXIMFLASH Level 1

            I am checking for the screen's width and height.

            Actually I changed the code to include a switch statement and it works much better.

             

                                override protected function playVideo(sURL:String):void {

                                               super.playVideo(sURL);

                                               stage.displayState = StageDisplayState.FULL_SCREEN;

                                               NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;

                                               stage.addEventListener(StageOrientationEvent.ORIENTATI ON_CHANGING, onOrientationChange);

                                               stage.addEventListener(StageOrientationEvent.ORIENTATI ON_CHANGE, onOrientationChange);

             

                                               //if the device is not in landscape mode, then set it to landscape mode.

                                               if(stage.stageWidth < stage.stageHeight){

                                                      switch(applicationFacade.stage.deviceOrientation){

                                                           case StageOrientation.DEFAULT:

                                                                applicationFacade.stage.setOrientation(StageOrientation.ROTATED_RIGHT);

                                                                break;

                                                           case StageOrientation.ROTATED_RIGHT:

                                                                applicationFacade.stage.setOrientation(StageOrientation.DEFAULT);

                                                                break;

                                                           case StageOrientation.ROTATED_LEFT:

                                                                applicationFacade.stage.setOrientation(StageOrientation.DEFAULT);

                                                                break;

                                                           case StageOrientation.UPSIDE_DOWN:

                                                                applicationFacade.stage.setOrientation(StageOrientation.ROTATED_RIGHT);

                                                                break;

                                                  }

             

             


                                               }

                                }

            • 3. Re: Best way to Set Mobile device to landscape when video plays?
              alinator11 Level 2

              Thanks for the follow up!

               

              Speaking of the width/height functions. I tried using Capabilities.screenResolutionX() and Y and then orrienting my SWF in the view based on that - expecting that the app would only report the landscape width and height when I had the app-xml set to landsape... I was wrong. To maintain my app orrientation using those values, I had to test for which value was greater between X and Y and make X the larger of the two and Y the smaller.

               

              I also found that Capabilities.screenResolutionX() will report 0 if you call it before anything is loaded to screen...

               

              In any event, glad you fixed your problem and it's good for my edification. Thus far I've always set the apps to orrient in one direction only and have done so via the *-app.xml.