You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to convert html canvas which playing live stream video into Laya.Sprite.
Video can play well in canvas, but laya itself create it's canvas.
so the problem I'm encountering is my html canvas is overlapped by laya default canvas.
That's why I'm finding a way to convert HTMLCanvasElement into Laya.Sprite.
Here's my code
const{ regClass, property }=Laya;
@regClass()exportclassExamplePlayerScriptextendsLaya.Script{player: NodePlayersprite: Laya.SpriteonEnable(): void{NodePlayer.load(()=>{this.player=newNodePlayer();this.startVideo()// Create a Laya.Spritethis.sprite=newLaya.Sprite();this.sprite.width=800this.sprite.height=600this.owner.addChild(this.sprite);// Get a reference to HTML canvasconstcanvas=document.getElementById('video')asHTMLCanvasElement;canvas.width=800canvas.height=600constcanvasContext=canvas.getContext('2d')consttexture2D=newLaya.Texture2D(canvas.width,canvas.height,Laya.TextureFormat.R8G8B8A8,true,false)consttexture=newLaya.Texture(texture2D,[0,0,1,1],texture2D.width,texture2D.height);texture.bitmap=texture2D;// Set the bitmap data to Texture2D this.sprite.graphics.drawTexture(texture,0,0,canvas.width,canvas.height);// Draw the texture on the sprite})}startVideo(){this.player.setView("video",true);this.player.setBufferTime(1000);this.player.on("stats",(stats)=>{console.log("player on stats=",stats);})this.player.enableVideo(true)this.player.start("http://localhost:8000/live/strange.flv")}}
The text was updated successfully, but these errors were encountered:
I want to convert html canvas which playing live stream video into Laya.Sprite.
Video can play well in canvas, but laya itself create it's canvas.
so the problem I'm encountering is my html canvas is overlapped by laya default canvas.
That's why I'm finding a way to convert HTMLCanvasElement into Laya.Sprite.
Here's my code
The text was updated successfully, but these errors were encountered: