Adobe-Runtime-Support icon indicating copy to clipboard operation
Adobe-Runtime-Support copied to clipboard

[Windows][macOS] StageVideo doesn't call onPlayStatus on playback complete

Open itlancer opened this issue 3 years ago • 4 comments
trafficstars

Problem Description

StageVideo doesn't call onPlayStatus on playback complete with Windows/macOS devices. So you cannot handle onPlayStatus to play video in a loop or detect video playback end.

Tested with multiple AIR versions, even with latest AIR 33.1.1.856 with multiple different Windows/macOS devices with different OS versions with different MP4 H.264 videos. Same problem in all cases. The same issue with Windows for Video and with macOS for Video and VideoTexture. ~~It works with VideoTexture and Video.~~ For Windows It works with VideoTexture.

Also it works with iOS and Android.

Steps to Reproduce

Launch code below with any Windows/macOS device. After video playback it will be started again in a loop by handling onPlayStatus and NetStream::seek(0).

Application example with sources and example of video attached. stagevideo_onplaystatus_bug.zip

package {
	import flash.display.Sprite;
	import flash.events.NetStatusEvent;
	import flash.net.NetStream;
	import flash.net.NetConnection;
	import flash.media.StageVideo;
	import flash.geom.Rectangle;
	
	public class StageVideoOnPlayStatusBug extends Sprite {
		private var nc:NetConnection;
		private var ns:NetStream;
		
		public function StageVideoOnPlayStatusBug() {
			nc = new NetConnection();
			nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
			nc.connect(null);
		}
		
		private function netStatusHandler(event:NetStatusEvent):void {
			trace(event.info.code);
			switch (event.info.code){
				case "NetConnection.Connect.Success":
					ns = new NetStream(nc);
					ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
					ns.client = {onMetaData:getMeta, onPlayStatus:onPlayStatus};
					var sv:StageVideo = stage.stageVideos[0];
					sv.viewPort = new Rectangle(0, 0, 720, 480);
					sv.attachNetStream(ns);
					ns.play("neon.mp4");
					break;
				case "NetStream.Play.StreamNotFound":
					trace("Stream not found");
					break;
			}
		}

		private function getMeta(mdata:Object):void {
			trace("metadata");
		}

		//This function doesn't call with Windows/macOS
		private function onPlayStatus(infoObject:Object):void {
			trace("onPlayStatus", infoObject.code);
			ns.seek(0);
		}
	}
}

Actual Result: Video will be stopped after one playback. onPlayStatus method didn't called.

Expected Result: Video playback in a loop. onPlayStatus method will be called.

Known Workarounds

Use NetStream.Play.Stop event to detect video playback end.

itlancer avatar May 30 '22 11:05 itlancer

I've just changed:

var sv:StageVideo = stage.stageVideos[0];
sv.viewPort = new Rectangle(0, 0, 720, 480);
sv.attachNetStream(ns);

to

var vid:Video = new Video(720, 480);
addChild(vid);
vid.attachNetStream(ns);

but I still don't get the onPlayStatus callback... you mentioned that it works for you for Video?

ajwfrost avatar May 31 '22 06:05 ajwfrost

@ajwfrost Hm, seems my fault. Made retest and edit original post. So, how video ending for me: Windows: Video - NetStream.Play.Stop VideoTexture - onPlayStatus StageVideo - NetStream.Play.Stop

macOS: Video - NetStream.Play.Stop VideoTexture - NetStream.Play.Stop StageVideo - NetStream.Play.Stop

So seems with different platforms it has different behavior.

itlancer avatar May 31 '22 12:05 itlancer

Thanks .. so from what I can see, we should be both dispatching the NetStream.Play.Stop event via NetStatusEvent.NET_STATUS, and also calling the onPlayStatus method: https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStream.html#event:onPlayStatus

onPlayStatus is also used for notifying of DRM-related activity and it may be that we've ended up with some 'normal' uses of it being removed when we disabled the DRM code.. we'll look to see where this should be dispatched (and how it's working with Windows + VideoTexture) and try to re-enable it across the board...

thanks

ajwfrost avatar Jun 01 '22 05:06 ajwfrost

@ajwfrost Great! May be some of that already outdated (legacy DRM-related methods). If it is so I think they should be removed and provide the same behavior/events/methods for different platforms in case of video playback. I think even better if video complete event will be only handled via NetStream.Play.Stop for all platforms.

itlancer avatar Jun 01 '22 07:06 itlancer