Showing videos in OpenFl

I looked into this link :
https://muut.com/i/openfl/general:openfl-and-video

But still not sure, how successfully, videos can be embedded using OpenFl ? However I searched the API reference, but it seems, OpenFl yet does not provide any direct support for video. Is their any alternative I can go for, to implement videos in OpenFl ?

I believe video is supported in HTML5 right now, for other targets, we would have to find something that is licensed properly to include it in the project. I’ve successfully used BinkVideo, though that costs thousands of dollars per target to license

Hello,

If you target Flash only, you can embed a video in your final swf using the flash.net.NetStream and flash.media.Video classes.
I successfully managed to do that. I can show you some working code if you’re interested.

1 Like

@ julacariote, sure, I would definitely like to look into it for future references. Thanks!

No problem. So basically, you have to create a NetConnection instance somewhere and add an event listener.

private var nc:NetConnection = new NetConnection();

// [....]

nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStreamConnect);
nc.connect(null);

and then in the event listener, you create a NetStream instance, append bytes from your video asset and attach the stream to an instance of the video class:

 public function onNetStreamConnect(evt:NetStatusEvent):Void

        if (evt.info.code == 'NetConnection.Connect.Success') {

            var ns:NetStream = new NetStream(nc);

            try {
                
                var bytes = Assets.getBytes("path/to/your/video/in/your/assets");
                ns.play(null);
                
                // using appendByte, you can play a video embeded as an asset
                ns.appendBytes(bytes);
                 
                var vid:Video = new Video();
                vid.attachNetStream(ns);
                
                // Now, you just have to add the video to the display list to make appear on the screen
                addChild(vid);

            } catch(error:Dynamic) {

                trace(error.message);

            }
        }
    }

You can find many other example in action script 3 to work with these classes.

NB: you can also play a video without embedding it your swf. To do that, forget about the “appendByte” part et directly play the URL:

ns.play("http://www.to-your-video.com/video.mp4");
var vid:Video = new Video();
vid.attachNetStream(ns);
                    
// Now, you just have to add the video to the display list to make appear on the screen
addChild(vid);
1 Like

dont mean to uproot old forum posts, but rather than start a new one, i may as well.

but has video been looked at quite a lot. i know it has to do with codecs, licencing and so forth. but one codec i could recommend to maybe hack into OPENFL would be HAP, from the cats at VDMX


thin the one thing tha HAXE/OPENFL is missing is proper video playback. would be nice. plus opens up so many doors in terms of software development and game development.
id like to use HAXE for things other than games, just games are on my mind :wink:

2 Likes

Hi Lewis. I’m keen to try and make HAP work. In our company, we create interactive digital content for very large, very high resolution screens. Almost exclusively, we’ve developed this in AS3 > AIR but I’m hoping to migrate all viable work we produce to Haxe.

One of the biggest issues we deal with is the handling of and seamless playback of very high resolution video files. Layering those creates even more complexity. Something like HAP appears at least, to be designed specifically for that purpose.

Unfortunately, my experience with Haxe/C/C++ is still early days, so whilst I hope to have a good ol’ crack at getting it to work, I must admit I’m not entirely sure I’m even capable at this point.

That throws an error for me, am trying to embed a video to see if it loops seamlessly and getting this on the line with : ns.appendBytes()

src/i/m/a/Main.hx:56: characters 16-32 : Not enough arguments, expected bytes:openfl.utils.ByteArray
Build halted with errors.
Done(1)
C:\HaxeToolkit\haxe\lib\openfl/3,6,1/extern/openfl/display/Stage.hx:135: lines 135-630 : Field addRenderer needed by lime.app.IModule is missing
C:\HaxeToolkit\haxe\lib\openfl/3,6,1/extern/openfl/display/Stage.hx:135: lines 135-630 : Field addWindow needed by lime.app.IModule is missing
C:\HaxeToolkit\haxe\lib\openfl/3,6,1/extern/openfl/display/Stage.hx:135: lines 135-630 : Field registerModule needed by lime.app.IModule is missing
C:\HaxeToolkit\haxe\lib\openfl/3,6,1/extern/openfl/display/Stage.hx:135: lines 135-630 : Field removeRenderer needed by lime.app.IModule is missing
C:\HaxeToolkit\haxe\lib\openfl/3,6,1/extern/openfl/display/Stage.hx:135: lines 135-630 : Field removeWindow needed by lime.app.IModule is missing
C:\HaxeToolkit\haxe\lib\openfl/3,6,1/extern/openfl/display/Stage.hx:135: lines 135-630 : Field setPreloader needed by lime.app.IModule is missing
C:\HaxeToolkit\haxe\lib\openfl/3,6,1/extern/openfl/display/Stage.hx:135: lines 135-630 : Field unregisterModule needed by lime.app.IModule is missing
C:\HaxeToolkit\haxe\lib\openfl/3,6,1/extern/openfl/display/Stage.hx:135: lines 135-630 : Field addRenderer needed by lime.app.IModule is missing
C:\HaxeToolkit\haxe\lib\openfl/3,6,1/extern/openfl/display/Stage.hx:135: lines 135-630 : Field addWindow needed by lime.app.IModule is missing
C:\HaxeToolkit\haxe\lib\openfl/3,6,1/extern/openfl/display/Stage.hx:135: lines 135-630 : Field registerModule needed by lime.app.IModule is missing
C:\HaxeToolkit\haxe\lib\openfl/3,6,1/extern/openfl/display/Stage.hx:135: lines 135-630 : Field removeRenderer needed by lime.app.IModule is missing
C:\HaxeToolkit\haxe\lib\openfl/3,6,1/extern/openfl/display/Stage.hx:135: lines 135-630 : Field removeWindow needed by lime.app.IModule is missing
C:\HaxeToolkit\haxe\lib\openfl/3,6,1/extern/openfl/display/Stage.hx:135: lines 135-630 : Field setPreloader needed by lime.app.IModule is missing
C:\HaxeToolkit\haxe\lib\openfl/3,6,1/extern/openfl/display/Stage.hx:135: lines 135-630 : Field unregisterModule needed by lime.app.IModule is missing

Has something changed since this was posted ?

HTML5 video support requires matching (and current) OpenFL and Lime releases, perhaps try the latest Lime and OpenFL, and see if it works for you?

1 Like

Thanks singmajesty, just having a bigger problem now, can’t seem to be able to release memory of the previous video played and it flashplayer blows up near 1GB ram consumed… very bad because I have around 30 videos to launch and it ain’t happening.

This is on Flash Player? How would you normally release that memory?

1 Like

I was doing something very wrong opening new videos on top of new videos, now getting “Error: The input swf bin/flash/debug/obj/assets.swf is corrupted” wich is a major problem. Due in 15 hours. Cold sweat.

Does a -clean build help?

If you have to, you can also embed="false" on your assets, and use Assets.loadBitmapData instead of Assets.getBitmapData, or use URLLoader/Loader like traditional Flash projects

1 Like

Thanks, wasn’t aware of that. That will come in handy for sure. Got to test them out see what works best where.