Native Device Orientation issue in Flutter - flutter

I'm working with Flutter and I'm using Native Device Orientation Plugin
I'm trying to know the device orientation and manage my view based on that.
That plugin works really well, but I found an issue when I'm in page A which has a NativeDeviceOrientationReader and go to page B which has another NativeDeviceOrientationReader.
In this case, the page which is supposed to has a NativeDeviceOrientation.landscapeLeft will have NativeDeviceOrientation.landscapeRight even if I didn't change the orientation in the middle.
Note: If I rotate the phone after changing the page, it begins to work properly.
Also if I delete one of the NativeDeviceOrientationReader's it works ok too.
I'm using this code:
NativeDeviceOrientationReader(
builder: (context) {
NativeDeviceOrientation orientation = NativeDeviceOrientationReader.orientation(context);
var quarterTurns = 0;
if (orientation == NativeDeviceOrientation.landscapeLeft) {
quarterTurns = 3;
} else if (orientation == NativeDeviceOrientation.landscapeRight) {
quarterTurns = 1;
}
}
),
(...)
I don't know if somehow I have to close the reader or something.
Thanks in advance !
-------------- EDIT 1 --------------
Actually I didn't fix the issue, but I could resolve my problem changing one NativeOrientationReader to flutter OrientationBuilder, because I realized I didn't need the current rotation, I only wanted to know if the phone is landscape or portrait.
Thank you.

Related

Flutter - Stop audio playback from recorded video in the background

Essentially the app is like snapchat. I take pics and reset back to camera mode, the issue comes when I record video and reset, it goes back to camera mode but the audio form the video keeps playing in the background. The functions are somwhat exactly like the camera doc, with a few addition to reset the camera.
I added this:
_reset() {
if (mounted)
setState(() {
if (this._didCapture) {
this._didCapture = false;
this._isRecording = false;
this._isPosting = false;
this._file = File('');
this._fileType = null;
this._captions.clear();
this._textEditingControllers.clear();
this._videoController = null;
this._videoPlayerListener = null;
}
});
}
It works just fine but the audio in the background is still on. Also wondering if the video/picture is saved on the phone, which I don't want to...
i had been looking for a similar answer, but i didn´t find it. You could try to stop it adding this to your function:
this._controller.setVolume(0.0);
that´s what i did in my app

Phaser multitouch (on laptop trackpad)

I'm confused by how to skip the following condition when 1) holding down, and then 2) another tap on the screen to release the aim. I think the secondary tap becomes the activePointer so I'm quite puzzled.
var holding_down = game.input.activePointer.isDown;
if (holding_down && game.input.pointer2.isUp) { cue.aiming = true; }
UPDATE: Please note that for the solution accepted, I had to differentiate between desktop and mobile usage. pointer1 & pointer2 work fine on mobile, but on desktop I had to do the following.
if (desktop) {
var holding_down = game.input.activePointer.leftButton.isDown;
var second_tap = spacebar.isDown;
} else {
var holding_down = game.input.pointer1.isDown;
var second_tap = game.input.pointer2.isDown;
}
Also note you need to declare the desktop var after intantating the game object. I then set the var in the preload() function: desktop = game.device.desktop;, otherwise it was giving the wrong value. Thanks!
You're correct in that the secondary tap becomes the activePointer. Per the documentation, activePointer is "[t]he most recently active Pointer object."
Therefore, you'll want to make your checks against game.input.pointer1 and game.input.pointer2 instead.
So replace activePointer in your code with pointer1 and that might get you closer to what you were looking for.

Code will not work without CCLOG in Cocos2D

I'm currently working on a game that will randomly generate a dungeon for the player. This is made up of a whole heap of different methods being called from different files. I seem to have the code working to be able to calculate how much space is available on the other side of the door.
There is a catch however; the code only seems to work when I am outputting to the console using CCLOG. I wrote a good chunk of the code without testing and decided to then work through it in steps to see how the code worked (I figured I would just get it to run without bugs and next I will check my values).
After I had established that the code was successfully checking available space in each direction, while listing the locations it had checked, I decided that I would like to remove the CCLOG output. Unfortunately though, doing this caused the code to stop working.
//First check "forward"
bottom = CGPointMake(startLocation.x + forwardDirectionModifier.x, startLocation.y + forwardDirectionModifier.y);
top = bottom;
do
{
currentLocation = CGPointMake(top.x + forwardDirectionModifier.x, top.y + forwardDirectionModifier.y);
tileType = [tileCache getTileType:currentLocation];
if (tileType == TileTypeFiller)
{
top = currentLocation;
CCLOG(#"Top location is %#", NSStringFromCGPoint(top));
}
} while (tileType == TileTypeFiller || top.y != 63);
This is a small snippet from the code; It is the section of code I think is most likely the issue. Essentially the problem is that if I comment out or delete the line CCLOG(#"Top location is %#", NSStringFromCGPoint(top)); it will stop working.
Here are some more details:
I have several little chunks of code like this, as long as I CCLOG in each one, it will be able to move to the next. If i were to comment out any of them, it would stop progress to the next chunk.
I can change the CCLOG to output anything and it will still work, it just has to be there.
I have tried cleaning the project.
There are more CCLOG's that aren't used inside any loops and they can be removed without consequence.
Does anyone have a solution to this? As far as I can tell, whether I do or do not output something to the console,it shouldn't have an effect on whether or not the code will execute.
Thanks in advance.
EDIT: At Ben Trengrove's suggestion, I am adding in further examples of where the CCLOG is being used.
This code immediately follows the previously listed code.
//Check left relative to door
farLeft = CGPointMake(startLocation.x + leftDirectionModifier.x, startLocation.y + leftDirectionModifier.y);
do
{
currentLocation = CGPointMake(farLeft.x + leftDirectionModifier.x, farLeft.y + leftDirectionModifier.y);
tileType = [tileCache getTileType:currentLocation];
if (tileType == TileTypeFiller)
{
farLeft = currentLocation;
CCLOG(#"Far Left location is %#", NSStringFromCGPoint(farLeft));
}
} while (tileType == TileTypeFiller || farLeft.x !=0);
//Check forwards from far left
top2 = farLeft;
do
{
currentLocation = CGPointMake(top2.x + forwardDirectionModifier.x, top2.y + forwardDirectionModifier.y);
tileType = [tileCache getTileType:currentLocation];
if (tileType == TileTypeFiller)
{
top2 = currentLocation;
CCLOG(#"Top2 location is %#", NSStringFromCGPoint(top2));
}
} while ((tileType == TileTypeFiller)|| (top2.y != 63));
What does your tile cache return as a tileType when there is no tile at currentLocation ? TileTypeFiller by any chance ? if yes, you have an almost certain never ending loop there, under the right circumstances..
EDIT :
please add a line after the loop
CCLOG(#"");
and place a breakpoint on that line. See if the program stops there.
So the problem has now been solved, it seems that in part there was a fault in my logic.
Here is what I've done that now works:
do
{
currentLocation = CGPointMake(top.x + forwardDirectionModifier.x, top.y + forwardDirectionModifier.y);
tileType = [tileCache getTileType:currentLocation];
if (tileType == TileTypeFiller)
{
top = currentLocation;
}
locationCount++;
} while ((tileType == TileTypeFiller) && (locationCount != 15));
CCLOG(#"Top location is %#", NSStringFromCGPoint(top));
The change is that I've switched to AND as opposed to OR. I also changed the second part of the while as I realised that due to my max room size, I never needed to check more than 15 locations in any given direction.
Thanks a lot to everyone that has helped. I'm still not entirely sure though how the use of CCLOG was somehow able to help get past a fault in logic but at least it is working now.

Navigation based on screen orientation (landscape or portrait) in Flash CS6

I'm creating an app that will have a different menu if the phone is held landscape, or portrait.
I figure I have to tell flash to move to a new frame when the phone moves from landscape to portrait or vice versa, but I'm not sure the exact code to after creating the orientation event listener.
There are two ways. Listen for a StageOrientationEvent or listen for Event.RESIZE. I personally prefer to use RESIZE as it is called slightly more often and keeps your interface in sync more.
var landscapeNav:Sprite; // this would be your landscape nav. Obviously does not have to be a Sprite
var portraitNav:Sprite; // same as landscapeNav, but this represents your portrait nav
stage.addEventListener( Event.RESIZE, this.stageResizeHandler );
function stageResizeHandler( e:Event ):void {
if ( stage ) { //just to make sure the stage is loaded in this class so we avoid null refs
if ( stage.stageWidth >= stage.stageHeight ) {
landscapeNav.visible = true;
portraitNav.visible = false;
}
else {
landscapeNav.visible = false;
portraitNav.visible = true;
}
}
}
This could definitely be cleaned up (landscapeNav.visible = stage.stageWidth > stage.stageHeight) but this should give you something to go on. If you want to do an animation as Atriace suggested, you would do a TweenLite/Max call within the conditional in the function instead of setting visible to true/false (after the animation is done, though, you should set visible to false just for the same of optimzation)
You don't need to create a new frame. In fact, it may be more visually appealing to watch the old menu slide off, and the new one to animate in (like with TweenLite).
The documentation on orientation change can be found # Adobe's ActionScript APIs specific to mobile AIR applications: "Screen Orientation", and the API.

Code doesn't work on iPhone but works on simulator

I have this code in my live chat.
if (TRUE && (balloonsOn != NO || !htmlStart)) {
balloonsOn = TRUE;
htmlStart = [self createChatLines: balloonsOn ? #"htmlformat-balloons" : #"htmlformat"];
if (chatLines > 0){
chatLines = 0;
[self updateView];
}
}
On the simulator it works fine but on the phone it doesn't work. It has worked before many times but now it stopped working on the phone. Why is this happening?
As far as I can see, there should be nothing that wouldn't work on the iPhone.. The only thing I can suppose, is you are using that strings without caring of the case-sensitiveness of iOs. The simulator is case insensitive but iOs is.. Let me know :)
What is the variable 'TRUE' ? I think having that as a variable name is probably the issue, rename it something else and see if it works.