Adobe-Runtime-Support
Adobe-Runtime-Support copied to clipboard
[Android] Video flickering on application activate
Problem Description
Activate already launched application causes video flickering. It also happens when you return from Alarm Clock or unlock device, turn on screen or switch from another application. It has been tested with many different AIR versions from 13.0.0.83 to latests AIR 32.0.0.144 beta and AIR 33.0.2.315 with different Android devices and Android OS versions. With armv7 and armv8 build targets. Same problem in all cases with different H.264 (MP4) videos. Same problem in all cases. The same problem with Video and StageVideo. It works fine with Windows, macOS and iOS.
Changing renderMode and containsVideo in application manifest doesn't help.
NetStream::useHardwareDecoder=true doesn't help - video doesn't playback at all (for AIR 33).
<disableMediaCodec>true</disableMediaCodec> doesn't help or show black rectangle instead of video when activate application.
Changing hardwareAccelerated in Android application manifest doesn't help.
Change stage quality - didn't solve it
Tracker link: https://tracker.adobe.com/#/view/AIR-3840991 Related issues (not the same): https://tracker.adobe.com/#/view/AIR-3840983 http://forum.starling-framework.org/topic/ane-fix-for-blackblank-screen-bug-when-returning-to-air-android-apps https://github.com/Gamua/Adobe-Runtime-Support/issues/87 https://github.com/Gamua/Adobe-Runtime-Support/issues/82 https://github.com/Gamua/Adobe-Runtime-Support/issues/79
Steps to Reproduce
- Launch code below on any Android device, it will start video playback.
- Deactivate application (minimize it or switch to other app or home launcher or lock device/turn off screen) when video playback.
- Activate application again (unlock screen/open app from Recent). *There could be different behavior by different ways of application deactivation/activation.
Application example with sources and example of video attached. video_flickers_bug.zip
package {
import flash.display.Sprite;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.events.NetStatusEvent;
import flash.media.StageVideo;
import flash.events.Event;
import flash.geom.Rectangle;
public class VideoFlickersBug extends Sprite {
var nc:NetConnection;
var ns:NetStream;
var stageVideo:StageVideo;
public function VideoFlickersBug() {
addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
if (stage.stageVideos.length > 0){
stageVideo = stage.stageVideos[0];
stageVideo.viewPort = new Rectangle(200, 200, 640, 480);
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, ncHandler);
nc.connect(null);
}
}
private function ncHandler(e:NetStatusEvent):void {
if (e.info.code == "NetConnection.Connect.Success"){
ns = new NetStream(nc);
ns.client = {onMetaData:getMeta, onPlayStatus:onPlayStatus};
ns.addEventListener(NetStatusEvent.NET_STATUS, nsHandler);
stageVideo.attachNetStream(ns);
ns.play("video.mp4");
}
}
private function nsHandler(e:NetStatusEvent):void { trace("ns", e.info.code); }
private function getMeta(mdata:Object):void { }
private function onPlayStatus(infoObject:Object):void {
if (infoObject.code == "NetStream.Play.Complete"){
ns.seek(0);
}
}
}
}
Actual Result:
Video flickers few frames. Sometimes (on some devices) it could flickers for a second with deformations.
Sometimes it could just continue to show white screen (no video) but sound of video continue playback.
Sometimes it could stop video playback (white screen).
Sometimes NetStream could dispatch NetStream.Play.Failed and stop playback.
Expected Result: Video continue playback correctly without artifacts, deformation, flickering, stops etc.
Known Workarounds
none
Same problem. It was an old problem and has been solved, but it seems to happen again on the new generation of Androids.
Issue still exists with latest AIR 50.2.4.1.
Issue still exists with latest AIR 51.1.3.10.
Moreover. After few times minimize/restore application (steps above) - video stop to playback. Just showed white screen (no video). No any errors or any NetStatusEvent.
Sometimes it could be workarounded by NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE, activate); and start video again in listener. Interesting that in such case there is no flickering...
But it's dirty hack anyway cause you cannot start video from the same (last) point because of cue points, time lags and so on.
It's most critical for Video usage.
I think it should be fixed or behavior should be properly documented if it "as designed". Or add some events...