Advertisement
Guest User

VideoTestScreen.java

a guest
Jan 18th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.99 KB | None | 0 0
  1. package com.imackshun.games.rhythmrpg.screens;
  2.  
  3. import java.io.FileNotFoundException;
  4.  
  5. import com.badlogic.gdx.Gdx;
  6. import com.badlogic.gdx.Screen;
  7. import com.badlogic.gdx.files.FileHandle;
  8. import com.badlogic.gdx.graphics.Color;
  9. import com.badlogic.gdx.graphics.GL20;
  10. import com.badlogic.gdx.graphics.g2d.BitmapFont;
  11. import com.badlogic.gdx.scenes.scene2d.Stage;
  12. import com.badlogic.gdx.scenes.scene2d.ui.Label;
  13. import com.badlogic.gdx.scenes.scene2d.ui.Table;
  14. import com.badlogic.gdx.utils.viewport.ScreenViewport;
  15. import com.badlogic.gdx.video.VideoPlayer;
  16. import com.badlogic.gdx.video.VideoPlayerCreator;
  17.  
  18. public class VideoTestScreen implements Screen {
  19.    
  20.     VideoPlayer videoPlayer;
  21.     Stage stage;
  22.     boolean videoLoaded = false;
  23.    
  24.     @Override
  25.     public void show() {
  26.         stage = new Stage(new ScreenViewport());
  27.         stage.getViewport().update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true);
  28.  
  29.         Label.LabelStyle lstyle =  new Label.LabelStyle(new BitmapFont(), Color.WHITE);
  30.  
  31.         Label l = new Label("Stage is here!", lstyle);
  32.         Table t = new Table();
  33.         t.add(l).expand().fill();
  34.         t.setFillParent(true);
  35.  
  36.         stage.addActor(t);
  37.  
  38.         videoPlayer = VideoPlayerCreator.createVideoPlayer();
  39.         videoPlayer.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
  40.         videoPlayer.setOnVideoSizeListener(new VideoPlayer.VideoSizeListener() {
  41.             @Override
  42.             public void onVideoSize(float v, float v2) {
  43.                 videoLoaded = true;
  44.             }
  45.         });
  46.  
  47.         try {
  48.             FileHandle fh = Gdx.files.internal("test.mp4");
  49.             Gdx.app.log("TEST", "Loading file : " + fh.file().getAbsolutePath());
  50.             videoPlayer.play(fh);
  51.         } catch (FileNotFoundException e) {
  52.             Gdx.app.log("TEST", "Err: " + e);
  53.         }
  54.  
  55.     }
  56.  
  57.     @Override
  58.     public void render(float delta) {
  59.          Gdx.gl.glClearColor(0, 0, 0, 1);
  60.             Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  61.  
  62.             if(videoLoaded) {
  63.                 if (!videoPlayer.render()) { // As soon as the video is finished, we start the file again using the same player.
  64.                     try {
  65.                         videoLoaded = false;
  66.                         videoPlayer.play(Gdx.files.internal("test.mp4"));
  67.                         Gdx.app.log("TEST", "Started new video");
  68.                     } catch (FileNotFoundException e) {
  69.                         e.printStackTrace();
  70.                     }
  71.                 }
  72.             }
  73.  
  74.             stage.act(Gdx.graphics.getDeltaTime());
  75.             stage.draw();
  76.  
  77.     }
  78.  
  79.     @Override
  80.     public void resize(int width, int height) {
  81.         // TODO Auto-generated method stub
  82.  
  83.     }
  84.  
  85.     @Override
  86.     public void pause() {
  87.         // TODO Auto-generated method stub
  88.  
  89.     }
  90.  
  91.     @Override
  92.     public void resume() {
  93.         // TODO Auto-generated method stub
  94.  
  95.     }
  96.  
  97.     @Override
  98.     public void hide() {
  99.         // TODO Auto-generated method stub
  100.  
  101.     }
  102.  
  103.     @Override
  104.     public void dispose() {
  105.         // TODO Auto-generated method stub
  106.  
  107.     }
  108.  
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement