Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loop and Autoplay Video with Pixi.js 5.2.1 #6501

Closed
Plunky33 opened this issue Mar 27, 2020 · 6 comments
Closed

Loop and Autoplay Video with Pixi.js 5.2.1 #6501

Plunky33 opened this issue Mar 27, 2020 · 6 comments

Comments

@Plunky33
Copy link

Hello! I am trying to implement autoplay and loop on a video (see code below) with Pixi.js@5.2.1 - My question is: bg.baseTexture.source.loop = true; - returns an uncaught TypeError - while the autoplay method works but for some reason the baseTexture.source.loop method does not. Thank you for checking this issue out. Has the most recent version of Pixi.js changed how - baseTexture.source.loop is called? Your comments and help are appreciated!

Here's my code:

createBackgrounds() {

    this.bgArray.map((video) => {

        // create a video texture from a path
        const bg = PIXI.Texture.from(`../assets/video/${video}.mp4`);

        //assigning the texture to baseTexture.source.loop to loop video - and returns uncaught TypeError??
        bg.baseTexture.source.loop = true;

        const videoSprite = new PIXI.Sprite(bg);

        videoSprite.anchor.x = 0.5;
        videoSprite.anchor.y = 0.5;  

        // preload and autoplay video
        videoSprite.preload = 'auto';
        this.autoPlay = videoSprite.autoplay;

        this.imgContainer.addChild(videoSprite);
        this.bgSpriteArray.push(videoSprite);


        // IMAGE
        videoSprite.alpha = this.bgSpriteArray.length === 1 ? 1 : 0;
    });
}```
Uncaught TypeError: Cannot set property 'loop' of undefined
    at jello.js:199
    at Array.map (<anonymous>)
    at Jello.createBackgrounds (jello.js:194) 

Reference: does the fact that source was deprecated have anything to do with the TypeError?
<img width="1407" alt="Screen Shot 2020-03-26 at 7 47 42 PM" src="https://user-images.githubusercontent.com/57849114/77716141-b2955800-6f9a-11ea-9d4a-f920511bd86e.png">

@eXponenta
Copy link
Contributor

eXponenta commented Mar 27, 2020

from is async, there are not guarantee that source was assigned after call.
Then there are not source field in Pixi v5, in v5 this is resource of class:
https://pixijs.download/dev/docs/PIXI.resources.VideoResource.html

@ivanpopelyshev
Copy link
Collaborator

ivanpopelyshev commented Mar 27, 2020

baseTexture.resource.source.loop.

from detects resource that can process videos - VideoResource, https://github.com/pixijs/pixi.js/blob/dev/packages/core/src/textures/resources/VideoResource.ts

and creates BaseTexture based on it.

VideoResource creates html5 video element , it starts playing video asynchonously.

Tip: next time you see a null pointer (Type Error) - just look in object in debug, it might have something like that field but under different name ;)

@ivanpopelyshev
Copy link
Collaborator

@bigtimebuddy
Copy link
Member

@Plunky33 does that fix your issue?

@Plunky33
Copy link
Author

Good stuff!! Great information! Thank you for your answers. Issue has been fixed and I have implemented autoplay and video loop. Thanks guys!

@bigtimebuddy
Copy link
Member

Awesome, closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants