feathersui / feathersui-starling

User interface components for Starling Framework and Adobe AIR
https://feathersui.com/learn/as3-starling/
Other
914 stars 386 forks source link

VideoPlayer and screen rotation. #1806

Closed Adrian-S closed 3 years ago

Adrian-S commented 4 years ago

Hey,

My application is fullscreen and portrait. I've tried to use the VideoPlayer and FullScreenToggleButton and trigger a change on aspect ratio for the app. Unfortunately this crashes the app on Android ONLY with: ArgumentError: Error #3672: Buffer creation failed. Internal error. at flash.display3D::Context3D/createVertexBuffer(). and also: RangeError: Error #1125 at BatchProcessor/getBatchAt(). Desktop simulator and iOS work fine. Tested on 2 phones with Android 7 on both, latest releases of FeathersUI and Starling, air 32.0 and 33.1.

I've created a class VideoPlayerHolder that extends LayoutGroup and on initialize I create the VideoPlayer and controls. It's mostly similar to the Video example provided, just layout a bit different since I need to give dimensions to the holder.

Code goes like this:

this._videoPlayer.addEventListener(MediaPlayerEventType.DISPLAY_STATE_CHANGE, fullScreenChangedHandler);
...
private function fullScreenChangedHandler():void
{
    if(this._videoPlayer.isFullScreen) {
        Starling.current.nativeStage.setAspectRatio(StageAspectRatio.LANDSCAPE);
    } else {
        Starling.current.nativeStage.setAspectRatio(StageAspectRatio.PORTRAIT);
    }
}

Immediately after calling setAspectRatio I get this:

[Starling] Context restored.
ArgumentError: Error #3672: Buffer creation failed. Internal error.
    at flash.display3D::Context3D/createVertexBuffer()

And usually I get Error #3672 twice and Error #1125 once. I've suppressed the error #3672 and if it happens I call Starling.current.context.clear(); and Starling.current.context.present(); but it made no difference with or without.

The result looks a bit like this (I've cut it for size): Screenshot_20200805-132758_small

At this point I have an Error #3672 loop, it hits multiple times a second. Usually I get to this the second time I press the FullScreenToggleButton, or exit fullscreen, and after this I can't press anything. I've been testing rotation with a simple button, and I still get errors but they recover much better, and I don't get #3672 error loop. I've removed the code about nativeStage.displayState since it exited fullscreen, but no luck there.

Now I'm not set in changing the aspect ratio, although that would be logical, but I failed to rotate the player too.

Any advice? Thank you.

joshtynjala commented 4 years ago

ArgumentError: Error #3672: Buffer creation failed. Internal error.

This is an AIR bug. As I understand it, some people have found workarounds, but I personally don't know what they are. There may be threads in the Starling forums, or in the Gamua/Adobe-Runtime-Support tracker.

joshtynjala commented 4 years ago

That said, one thing that might be worth trying is delaying your call to setAspectRatio() until a bit after switching to full screen. My thought is that switching to full screen will cause a context loss, and maybe it hasn't fully restored by the time that you switch the aspect ratio. It might work better after everything is restored.

You could probably listen for Event.CONTEXT3D_CREATE. Alternatively, you could start a timer and wait somewhere between 0.5 and 2.0 seconds (you probably need to play around with the exact time a bit, but a longer wait may be better for slower devices).