Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class VideoLoopExample implements ApplicationListener
- {
- private SpriteBatch spriteBatch;
- private BitmapFont font;
- private OrthographicCamera camera;
- GStreamerPlayer videoplayer = null;
- GlyphLayout glyphL = new GlyphLayout();
- @Override
- public void create()
- {
- try {
- GStreamerLibrary.init();
- } catch (Exception e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- Gdx.input.setInputProcessor(new OurInputListener());
- spriteBatch = new SpriteBatch();
- font = new BitmapFont(Gdx.files.internal("font/dejavu.fnt"), true);
- font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
- camera = new OrthographicCamera();
- camera.setToOrtho(true);
- videoplayer = new GStreamerPlayer(Gdx.files.internal("video/loop.ogv").file());
- videoplayer.play();
- }
- public static void main(String[] args)
- {
- System.setProperty("gstreamer.dir", "vlib_gst");
- LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
- cfg.title = "Test";
- cfg.useGL30 = true;
- cfg.width = 1280;
- cfg.height = 720;
- new LwjglApplication(new VideoLoopExample(), cfg);
- }
- @Override
- public void resume()
- {
- }
- private class OurInputListener extends InputAdapter
- {
- @Override public boolean keyDown(int keycode)
- {
- if (keycode == Keys.ENTER)
- {
- }
- else if (keycode == Keys.ESCAPE)
- {
- if (videoplayer != null)
- {
- videoplayer.destroy();
- videoplayer = null;
- }
- Gdx.app.exit();
- }
- else if (keycode == Keys.SPACE)
- {
- if (videoplayer != null)
- {
- videoplayer.pause();
- }
- }
- return true;
- }
- }
- @Override
- public void render()
- {
- Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
- camera.update();
- spriteBatch.setProjectionMatrix(camera.combined);
- // //RENDERING
- videoplayer.updateAndRender();
- if (videoplayer != null)
- {
- if(videoplayer.isDone())
- {
- videoplayer.stop();
- videoplayer.getPlayBin().play();
- videoplayer.done = false;
- }
- }
- spriteBatch.begin();
- font.setColor(Color.WHITE);
- if (videoplayer == null)
- {
- glyphL.setText(font, "Press Enter to start playing video.");
- font.draw(spriteBatch, "Press Enter to start playing video.", (Gdx.graphics.getWidth()/2)-(glyphL.width/2), (Gdx.graphics.getHeight()/2)-(font.getLineHeight()/2));
- }
- else
- {
- glyphL.setText(font, "This is text");
- font.draw(spriteBatch, "This is text", (Gdx.graphics.getWidth()/2)-(glyphL.width/2), (Gdx.graphics.getHeight()/2)-(font.getLineHeight()/2));
- }
- font.draw(spriteBatch, "FPS: "+Gdx.graphics.getFramesPerSecond(), 12, 10);
- spriteBatch.end();
- }
- @Override
- public void resize(int width, int height)
- {
- }
- @Override
- public void pause()
- {
- }
- @Override
- public void dispose()
- {
- if (videoplayer != null)
- {
- videoplayer.stop();
- videoplayer.destroy();
- videoplayer = null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement