Screen orientation change in specific page

Hey everyone,I’m develop an app in ionic, My requirement is play the video in landscape mode. rest of my app in portrait mode . I fix the app into portrait mode by using
it works well. but i want to play video in landscape only. Please help to solve this Issue.

Thanks in advance…

Hi,

have you tried
screen.lockOrientation("landscape");

Hi @whizzkey, Thanks for your reply, I tried with this code, but not worked, if you have any other solution please forward me

Thanks…

How did you fix the app in portrait?

set tag
preference name=“orientation” value="portrait"
in config.xml

I wouldn’t set screen direction in config.xml,

In your inital controller put:
screen.lockOrientation("portrait")

Then when you open your video put:
screen.lockOrientation("landscape")

and when you close your video:
screen.lockOrientation("portrait")

1 Like

I tried with code, i got an error “screen.lockOrientation is not a function” . If any plugin is required to implement this code. please forward to me. screen is dependency injection or not.

Sorry, I forgot to point out the plugin…

got same error after add plugin

try
window.screen.lockOrientation("portrait")

ios needs this, on android I have not encountered it.

again got same error window.screen.lockOrientation is not a function

In your index.html try and add
<script type="text/javascript" src="cordova.js"></script> <script type="text/javascript" src="plugins/cordova-plugin-screen-orientation/www/screenorientation.js"></script>

(check if the plugin name is correct).

then try with screen.lockOrientation(…)

add this code in index.html, but not working…

Are you calling it on deviceReady?
document.addEventListener("deviceready", onDeviceReady, false); function onDeviceReady(){ screen.lockOrientation('landscape'); }

@nani_madepalli

use screen orientation plugin for specific page rotation

and then try this code

$rootScope.$on(’$locationChangeSuccess’, function (event, newUrl, oldUrl) {
try {
if(newUrl.indexOf(’/statename’)>0){
screen.unlockOrientation();
}
else {
screen.lockOrientation(‘portrait’);
}
} catch(ex) { console.log(ex); }

        });
1 Like

Thanks to @whizzkey,@nitishrajput01 , my problem is solved with screen.lockOrientation(‘landscape’)

Hi I am having the same problem for screen.lockOrientation(‘landscape’); is not a function . I have added this plugin https://github.com/apache/cordova-plugin-screen-orientation.

Android version v6.1.2
Cordova : v6
ionic framework : v1

I am trying this for the last couple of days and i am stuck. I see you have solved the issue. Could you please help me to fix the issue