Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.imackshun.games.rhythmrpg.screens;
- import java.io.FileNotFoundException;
- import com.badlogic.gdx.Gdx;
- import com.badlogic.gdx.Screen;
- import com.badlogic.gdx.files.FileHandle;
- import com.badlogic.gdx.graphics.Color;
- import com.badlogic.gdx.graphics.GL20;
- import com.badlogic.gdx.graphics.g2d.BitmapFont;
- import com.badlogic.gdx.scenes.scene2d.Stage;
- import com.badlogic.gdx.scenes.scene2d.ui.Label;
- import com.badlogic.gdx.scenes.scene2d.ui.Table;
- import com.badlogic.gdx.utils.viewport.ScreenViewport;
- import com.badlogic.gdx.video.VideoPlayer;
- import com.badlogic.gdx.video.VideoPlayerCreator;
- public class VideoTestScreen implements Screen {
- VideoPlayer videoPlayer;
- Stage stage;
- boolean videoLoaded = false;
- @Override
- public void show() {
- stage = new Stage(new ScreenViewport());
- stage.getViewport().update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
- Label.LabelStyle lstyle = new Label.LabelStyle(new BitmapFont(), Color.WHITE);
- Label l = new Label("Stage is here!", lstyle);
- Table t = new Table();
- t.add(l).expand().fill();
- t.setFillParent(true);
- stage.addActor(t);
- videoPlayer = VideoPlayerCreator.createVideoPlayer();
- videoPlayer.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
- videoPlayer.setOnVideoSizeListener(new VideoPlayer.VideoSizeListener() {
- @Override
- public void onVideoSize(float v, float v2) {
- videoLoaded = true;
- }
- });
- try {
- FileHandle fh = Gdx.files.internal("test.mp4");
- Gdx.app.log("TEST", "Loading file : " + fh.file().getAbsolutePath());
- videoPlayer.play(fh);
- } catch (FileNotFoundException e) {
- Gdx.app.log("TEST", "Err: " + e);
- }
- }
- @Override
- public void render(float delta) {
- Gdx.gl.glClearColor(0, 0, 0, 1);
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
- if(videoLoaded) {
- if (!videoPlayer.render()) { // As soon as the video is finished, we start the file again using the same player.
- try {
- videoLoaded = false;
- videoPlayer.play(Gdx.files.internal("test.mp4"));
- Gdx.app.log("TEST", "Started new video");
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- }
- }
- stage.act(Gdx.graphics.getDeltaTime());
- stage.draw();
- }
- @Override
- public void resize(int width, int height) {
- // TODO Auto-generated method stub
- }
- @Override
- public void pause() {
- // TODO Auto-generated method stub
- }
- @Override
- public void resume() {
- // TODO Auto-generated method stub
- }
- @Override
- public void hide() {
- // TODO Auto-generated method stub
- }
- @Override
- public void dispose() {
- // TODO Auto-generated method stub
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement