LibGDX In 10 Minute Slices: Playing Videos in LibGDX

LibGDX Tutorial: Playing Videos in Game

Details from Video

Add your Gradle dependencies:

Core: 
implementation "com.badlogicgames.gdx-video:gdx-video:1.3.2-SNAPSHOT"
Desktop:
implementation "com.badlogicgames.gdx-video:gdx-video-lwjgl:1.3.2-SNAPSHOT"

Our main Class:

package com.video.demo;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.utils.ScreenUtils;
import com.badlogic.gdx.video.VideoPlayer;
import com.badlogic.gdx.video.VideoPlayerCreator;

import java.io.FileNotFoundException;

public class VideoDemo extends ApplicationAdapter {
	SpriteBatch batch;
	private VideoPlayer videoPlayer;
	
	@Override
	public void create () {
		batch = new SpriteBatch();

		videoPlayer = VideoPlayerCreator.createVideoPlayer();

		videoPlayer.setOnCompletionListener(new VideoPlayer.CompletionListener() {
			@Override
			public void onCompletionListener(FileHandle file) {
				// Do something
			}
		});

		try {
			videoPlayer.play(Gdx.files.local("intro/yobowargames.webm"));
		} catch (FileNotFoundException e) {
			Gdx.app.error("gdx-video", "Oh no!");
		}
	}

	@Override
	public void render () {
		ScreenUtils.clear(0, 0, 0, 1);

		videoPlayer.update();

		batch.begin();

		Texture frame = videoPlayer.getTexture();
		if (frame != null)
			batch.draw(frame, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

		batch.end();
	}
	
	@Override
	public void dispose () {
		batch.dispose();
	}
}
0
YOUR CART
  • No products in the cart.