Play video from youtube in my website made on Openfl


#1

Hi all, i´m making a webside to my game, wanna play the video trailer(from youtube link) in my webside on html5 target, how can i do that?


#2

If it runs in the DOM target, you could use an <iframe /> element inside of an openfl.display.DOMSprite

Or, you could use openfl.external.ExternalInterface (or just untyped JS calls) to execute code and create a DOM element to float above your game content

Here’s a simple embed:

https://www.w3schools.com/html/html_youtube.asp


#3

Thanks ! i will try, never hear of DOM taget before


#4

ok, i´m really lost;

Do i have to use this:

<iframe width="420" height="315" src="https://www.youtube.com/embed/A5n1nx8Yr7U"></iframe>

inside the DOMSprite params? like this:

var video:DOMSprite = new DOMSprite("Here?");

#5

or it goes inside the project.xml? them i have to cast it?


#6

I think it would be something like this:

import js.html.IFrameElement;
import js.Browser;

...

var iframe:IFrameElement = cast Browser.document.createElement ("iframe");
iframe.width = 420;
iframe.height = 315;
iframe.src = "https://www.youtube.com/embed/A5n1nx8Yr7U";

var domSprite = new DOMSprite (iframe);
addChild (domSprite);

#7

Thanks Singmajesty! it works perfect!


#8

Hello @singmajesty I am trying this code I’m on openfl version 3.6.1 and lime version 2.9.1 and I can’t seem to get the iframe to work properly any help would be much apperciated thanks :grinning:


#9

Are you using Flixel, or is there any other reason why you use those versions? Thank you :slight_smile:


#10

Yes I’m using haxe flixel but I even tried writing the code in complete openfl as well as adding it to the stage via haxeflixel addChild below mouse


#11

Well, I was curious, because we have over a year of fixes since that version