Jump to content

Add videojs in phaser problem


sabdfresh
 Share

Recommended Posts

I want to play HLS live stream in the game,

the phaser built-in  video seems can't play.

I find video.js can play this HLS stream,

but i don't have idea how embed the player into game.

 

I read phaser video source code, phaser video create a video element,

and take it as texture. So game can add this texture into game.

it occurred to me that if I can do the same thing as phaser.video,

maybe i can add player into game.

 

My idea is very simple , 

I extend phaser.video and override  createfromurl to use videojs  create new player.

and output the texture to sprite.

But the sprite is always black.

MyVideo.prototype.createVideoFromURL = function (url, autoplay)
{

    if (autoplay === undefined) { autoplay = false; }

    //  Invalidate the texture while we wait for the new one to load (crashes IE11 otherwise)
    if (this.texture)
    {
        this.texture.valid = false;
    }


    this.video =  videojs(document.createElement("video"));

    this.video.src({

        src:url,
        type:"application/x-mpegURL", 
    });


    // if (autoplay)
    // {
    //     this.video.setAttribute('autoplay', 'autoplay');
    // }

    //  this.video.src = url;

    this.video.canplay = true;

    //      this.video.load();

    this.retry = this.retryLimit;

    // this._retryID = window.setTimeout(this.checkVideoProgress.bind(this), this.retryInterval);

    this.key = url;

    return this;
};

 

i don't know my idea is correct or not. maybe i miss something.

IS there anyone do similar thing successfully before ?

Or maybe better idea can play live stream  instead of hls .

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...