This site requires JavaScript, please enable it in your browser!
Greenfoot back
Lightning
Lightning wrote ...

2015/1/28

Trying to create a video player with arrays

Lightning Lightning

2015/1/28

#
Hi everyone, I'm trying to make a video player, which uses .jpg images. I made it work, but it lagged hardly, cause it had to load and scale ~20images a second. Now i want to use an array to load and scale them before playing the video itself. Here is my code for the video object: (this editor doesnt show up stuff in square clips, so i wrote the array clips round here.) public class video extends Actor { int frame = 0; GreenfootImage() frameShowed; String name ="video ("; String brak = ")"; boolean stop = false; public video() { frameShowed = new GreenfootImage(640); for(int i = 0; i < 640; i++) //640 = total number of frames { frameShowed(i).setImage(name+frame+brak+".jpg"); getImage().scale(600,400); } } public void act() { if(!stop) try { frame ++; setImage(frameShowed); } catch (java.lang.IllegalArgumentException iae) { stop = true; myWorld.finished(); } if("space".equals(Greenfoot.getKey())) { if(!stop){ stop = true; myWorld.finished(); } else { stop=false; myWorld.unfinished(); } } } } the error shows up in the underlined border line. Has anyone an idea how to solve this?
davmac davmac

2015/1/28

#
(this editor doesnt show up stuff in square clips, so i wrote the array clips round here.)
Yes it does.
Lightning Lightning

2015/1/28

#
Thank you! :) Sorry i'm new here and it seems i was a bit too fast ;) So here is the code again:

public class video extends Actor
{
    int frame = 0;
    GreenfootImage[] frameShowed;


    String name ="video (";
    String brak = ")";
    boolean stop = false;

    public video()
    {
        frameShowed = new GreenfootImage[640];

        for(int i = 0; i < 640; i++)
        {
            frameShowed[i].setImage(name+frame+brak+".jpg");
        }
    }

    public void act() 
    {        

        if(!stop)
            try
            {
                frame ++;
                setImage(frameShowed[frame]);

            }
            catch (java.lang.IllegalArgumentException iae)
            {
                stop = true;
                myWorld.finished();
        }

        if("space".equals(Greenfoot.getKey()))    
        {
            if(!stop){
                stop = true;
                myWorld.finished();
            }
            else
            {
                stop=false;
                myWorld.unfinished();
            }
        }
    }    

}
Super_Hippo Super_Hippo

2015/1/28

#
'setImage' is used to set the image of an actor, so not here.
frameShowed[i] = new GreenfootImage("video (" + frame + ").jpg");
You need to login to post a reply.