使用Pixi.js 5.2.1循环和自动播放视频

时间:2020-03-26 22:26:00

标签: javascript arrays video html5-video pixi.js

我正在尝试使用Pixi.js@5.2.1在视频上实现自动播放和循环(请参见下面的代码)-我的问题是:bg.baseTexture.source.loop = true; -返回未捕获的TypeError-尽管自动播放方法有效,但由于某种原因baseTexture.source.loop方法不起作用。感谢您检查此问题。 Pixi.js的最新版本是否更改了-baseTexture.source.loop的调用方式?感谢您的评论和帮助!

这是我的代码:

    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) ```

1 个答案:

答案 0 :(得分:0)

extern crate xmlJSON; extern crate rustc_serialize; use crate::rustc_serialize::json::ToJson; use xmlJSON::XmlDocument; use rustc_serialize::json; use std::str::FromStr; use std::fs::File; use std::io::prelude::*; fn main() { let filename = "myfile.xml"; let mut f = File::open(filename).expect("file not found"); let mut contents = String::new(); f.read_to_string(&mut contents).expect("something went wrong reading the file"); let document: XmlDocument = XmlDocument::from_str(&mut contents).unwrap(); let jsn: json::Json = document.to_json(); println!("{}", jsn); } 是答案-https://github.com/pixijs/pixi.js/issues/6501-

已实现自动播放和视频循环:

baseTexture.resource.source.loop