Video playing in game

I would like to use gdx-video extension in my libGDX project to embed a YouTube video. I have found this extension on GitHub, but there are several error messages during Gradle Sync process. I have pasted dependencies in build.gradle file.

[quote]Error:Failed to resolve: com.badlogicgames.gdxvideo:gdx-video:0.0.1 Error:Failed to resolve: com.badlogicgames.gdxvideo:gdx-video-platform:0.0.1 Error:Failed to resolve: com.badlogicgames.gdxvideo:gdx-video-android:0.0.1
[/quote]
Is this project dead? Should I use another one? I haven’t found proper solution for this after 2 hours googling.

Riven wrote a thing for this called YUNPM (Y U NO play movie). It may be what you’re looking for.

Here you go.

It seems great! Maybe some tutorial would be great, this is fully new for me.

That thread has good examples. I got most of them to work not so long ago. Also that thread has good explanations of what it does and how. When the thread was made, i was testing it on full HD on very crap hardware.

I have tried to use GDX-video extension in a libGDX project. I have converted an MP4 file into OGG (Theora+Vorbis) with use of VLC and placed under res/data/ folder in android project. When I run project, see black screen.

package com.mygdx.game;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Mesh;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
import com.badlogic.gdx.graphics.g3d.Environment;
import com.badlogic.gdx.graphics.g3d.ModelInstance;
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
import com.badlogic.gdx.graphics.g3d.utils.CameraInputController;
import com.badlogic.gdx.graphics.g3d.utils.MeshBuilder;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.video.VideoPlayer;
import com.badlogic.gdx.video.VideoPlayerCreator;

import java.io.FileNotFoundException;

public class MyGdxGame extends ApplicationAdapter implements InputProcessor {
    public PerspectiveCamera cam;
    public CameraInputController inputController;
    public ModelInstance instance;
    public Environment environment;

    public VideoPlayer videoPlayer;
    public Mesh mesh;

    private final Vector3 tmpV1 = new Vector3();
    private final Vector3 target = new Vector3();

    @Override
    public void create() {
        environment = new Environment();
        environment.set(new ColorAttribute(ColorAttribute.AmbientLight, .4f, .4f, .4f, 1f));
        environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));

        cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        cam.position.set(10f, 10f, 10f);
        cam.lookAt(0, 0, 0);
        cam.near = 0.1f;
        cam.far = 300f;
        cam.update();

        MeshBuilder meshBuilder = new MeshBuilder();
        meshBuilder.begin(Usage.Position | Usage.TextureCoordinates, GL20.GL_TRIANGLES);
        // @formatter:off
        meshBuilder.box(5, 5, 5);
        // @formatter:on
        mesh = meshBuilder.end();
        videoPlayer = VideoPlayerCreator.createVideoPlayer(cam, mesh, GL20.GL_TRIANGLES);
        try {
            videoPlayer.play(Gdx.files.internal("data/converted.ogg"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        Gdx.input.setInputProcessor(new InputMultiplexer(this, inputController = new CameraInputController(cam)));
        Gdx.gl.glEnable(GL20.GL_CULL_FACE);
        Gdx.gl.glCullFace(GL20.GL_BACK);
    }

    @Override
    public void render() {
        inputController.update();

        Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);

        final float delta = Gdx.graphics.getDeltaTime();
        tmpV1.set(cam.direction).crs(cam.up).y = 0f;
        cam.rotateAround(target, tmpV1.nor(), delta * 20);
        cam.rotateAround(target, Vector3.Y, delta * -30);
        cam.update();

        if (!videoPlayer.render()) { // As soon as the video is finished, we start the file again using the same player.
            try {
                videoPlayer.play(Gdx.files.internal("data/converted.ogg"));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }
    }

    @Override
    public void dispose () {
    }

    public boolean needsGL20 () {
        return true;
    }

    public void resume () {
    }

    public void resize (int width, int height) {
    }

    public void pause () {
    }

    @Override
    public boolean keyDown(int keycode) {
        return false;
    }

    @Override
    public boolean keyUp(int keycode) {
        return false;
    }

    @Override
    public boolean keyTyped(char character) {
        return false;
    }

    @Override
    public boolean touchDown(int screenX, int screenY, int pointer, int button) {
        return false;
    }

    @Override
    public boolean touchUp(int screenX, int screenY, int pointer, int button) {
        return false;
    }

    @Override
    public boolean touchDragged(int screenX, int screenY, int pointer) {
        return false;
    }

    @Override
    public boolean mouseMoved(int screenX, int screenY) {
        return false;
    }

    @Override
    public boolean scrolled(int amount) {
        return false;
    }
}

It is a freshly created project, only necessary Gradle dependencies have added to it.

Can you HEAR the video? Because my guess would be you are not correctly looking at it in 3D space
I suppose the file can be read, other there would be an error
Bascially if you make the mesh a color or a texture and you can clearly see it, but then with the video on it, you cannot, then something is up, for sure
Try other files to be sure

I havent used gdx-video even tho I use libgdx and need video, because I used my own gstreamer solution. But I should try this out, as it makes it easier… I just dont have the time right now.
I also wish they would allow you to have a 2D plane for projection, either full screen or 3D is a tick limiting, even tho usually fullscreen is fine…

On a scale of 1 to 10 where 1 is “I’d code my own MJPEG video format just to get something on the screen” and 10 is “only a pure Java implementation of 10-bit H264 is good enough for me”, how desperate are you to get this working?

I’m confused. That’s like asking: “on a scale from yellow to red, how green do you want your sweater” :persecutioncomplex:

(he can be desperate to get a video player to work, without caring about technicalities)

[quote=“Riven,post:8,topic:56582”]
Oh, come on, that’s a bit of hyberbole, isn’t it? I’m just wondering if he’d be okay with anything even if can only play low quality and inefficiently encoded video files, or if he needs to be able to play advanced well-compressed codecs. There’s a difference in how important something is and how efficient it has to be. If you want a tiny little GIF-level tutorial video next to one of your abilities to show how it works in the skill tree, that’s not the same requirement as wanting to play a full HD 5 minute intro video for the game.

If you’re really (and I mean really) desperate to get a video to play in Java, you could split the video up into individual frames, and then just play each frame one at a time. I wrote something like this a while back, it’s in Java2D but it could be easily ported to LibGDX.


package animation;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;

public class RenderAnimation extends JPanel implements ActionListener {
	private static final long serialVersionUID = 1L;

	Image[] images = new Image[35];
	
	int frame = 0;
	private Timer t;

	public RenderAnimation() {
		for(int i = 0; i < 35; i++) {
		    images[i] = new ImageIcon("res/" + (i + 1) + ".png").getImage();
		}
		
		t = new Timer(25, this);
		t.start();
	}

	public void actionPerformed(ActionEvent e) {
		repaint();

		frame += 1;
		if (frame >= images.length) {
			frame = 0;
		}
		try {
			Thread.sleep(50);
		} catch (InterruptedException e1) {
			e1.printStackTrace();
		}
	}

	public void paint(Graphics g) {
		super.paint(g);
		g.setColor(Color.black);
		g.fillRect(0, 0, 800, 600);
		g.drawImage(images[frame], 200, 100, null);
	}
}

Video playing in Java is a new field for me, but existing “solutions” seems a bit problematic and first of all poorly documented.

he IS using libgdx, so getting gdx-video to work should be the most sensible solution

[quote] poorly documented.
[/quote]
very much so.

@DarkCart
I think a game that uses video rather need 1080p video with audio, synced up, 30fps for cutscenes and stuff, dont you think? :stuck_out_tongue:
some 100 line gif thingy wont cut it

I do have a gstreamer solution working under libgdx but it would be a lot of work getting it in there, especially with the native binaries. getting gdx video to work makes more sense

There is no sound, but file is exists on the right place, I have checked. I have also corrected file format to valid .ogv file.

[s]http://forum.lwjgl.org/index.php?topic=2516.0
I found this gem on lwjgl. I, too, want to know how to render video on a quad surface.

It looks promising. It’s from 08 (8 years ago…)[/s]

It’s dead, Jim!

@kovacsdev
You can also download ogg and ogv files if you are unsure
I use the Theora net converter

I cant even find a release at: https://oss.sonatype.org/content/repositories/releases/com/badlogicgames/gdx/

Not sure why you posted that to begin with… you can find video solutions on this very forum that arent as old…

It is here: https://oss.sonatype.org/#nexus-search;quick~gdx-video

This may be easier these days given that there are official cross-platform binary downloads available for GStreamer 1.x, and much more of a focus on it being cross-platform.

The most interesting bit is not yet available in the Java bindings, though. Andres from the Processing project is currently working to bind GStreamer’s support for OpenGL textures, which will open up GPU video decoding direct to textures. I’m awaiting a pull request with much anticipation!


https://gstreamer.freedesktop.org/download/

But gdx-video seems to be a much more easier, maybe already working solution for this purpose.

well I am not sure about easy, UNLESS you NEED the mesh functionality libgdx has there, I only need it to be 2D

Here an example that I made: http://pastebin.com/J16nDkmb

Only thing thats annoying is, when looping, for backgrounds and similar, I get like a 300ms or so stutter, which you would in most video players
I dont know how to make it super smooth endless looping

Ah I forget another bug.
Sometimes when I run this, it freezes the whole program, no error, just freezes.
Then you try again, and it works fine.

Pretty sure its GStreamerLibrary.init() which freezes without error. Which is pretty annoying.
That being said, I havent updates these gstreamer bindings since I made it, years ago…