1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.util.BufferedImageUtil;
import com.xuggle.mediatool.IMediaReader;
import com.xuggle.mediatool.IMediaTool;
import com.xuggle.mediatool.MediaToolAdapter;
import com.xuggle.mediatool.ToolFactory;
import com.xuggle.mediatool.event.IVideoPictureEvent;
public class VideoPlay extends BasicGame
{
private Image image;
private float angle;
static private IMediaReader reader;
public VideoPlay ()
{
super("Slick-VideoPlayer");
}
/**
* @param args
*/
public static void main(String[] args)
{
File inputFile = new File("C:/Users/Administrateur/Downloads/Video/Doc's/C'est pas sorcier/C'est Pas Sorcier - Comètes Et Astéroïdes.avi");
if (!inputFile.exists())
{
System.out.println("Input file does not exist: " + inputFile);
System.exit(-1);
}
reader = ToolFactory.makeReader(inputFile.toString());
reader.setBufferedImageTypeToGenerate(BufferedImage.TYPE_3BYTE_BGR);
AppGameContainer app;
try
{
app = new AppGameContainer(new VideoPlay());
app.setDisplayMode(800, 600, false);
app.start();
}
catch (SlickException e)
{
e.printStackTrace();
}
}
@Override
public void init(GameContainer arg0) throws SlickException
{
IMediaTool addTimeStamp = new TimeStampTool();
reader.addListener(addTimeStamp);
image = new Image (600,500);
}
@Override
public void update(GameContainer arg0, int arg1) throws SlickException
{
reader.readPacket();
}
@Override
public void render(GameContainer arg0, Graphics arg1) throws SlickException
{
if (image != null)
{
image.draw (0,0);
image.setRotation(angle);
}
}
public class TimeStampTool extends MediaToolAdapter
{
@Override
public void onVideoPicture(IVideoPictureEvent event)
{
Graphics2D g = event.getImage().createGraphics();
try
{
if (image != null)
image.setTexture (BufferedImageUtil.getTexture("bla", event.getImage()));
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
} |
Partager