Advertisement
Guest User

Untitled

a guest
Mar 13th, 2016
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.11 KB | None | 0 0
  1. public class VideoLoopExample implements ApplicationListener
  2. {
  3.     private SpriteBatch spriteBatch;
  4.     private BitmapFont font;
  5.     private OrthographicCamera camera;
  6.    
  7.     GStreamerPlayer videoplayer = null;
  8.     GlyphLayout glyphL = new GlyphLayout();
  9.  
  10.     @Override
  11.     public void create()
  12.     {
  13.         try {
  14.           GStreamerLibrary.init();
  15.           } catch (Exception e) {
  16.               e.printStackTrace();
  17.               throw new RuntimeException(e);
  18.           }
  19.        
  20.         Gdx.input.setInputProcessor(new OurInputListener());
  21.        
  22.         spriteBatch     = new SpriteBatch();
  23.         font            = new BitmapFont(Gdx.files.internal("font/dejavu.fnt"), true);
  24.         font.getRegion().getTexture().setFilter(TextureFilter.Linear, TextureFilter.Linear);
  25.        
  26.         camera = new OrthographicCamera();
  27.         camera.setToOrtho(true);
  28.        
  29.        
  30.         videoplayer = new GStreamerPlayer(Gdx.files.internal("video/loop.ogv").file());
  31.         videoplayer.play();
  32.     }
  33.    
  34.     public static void main(String[] args)
  35.     {
  36.         System.setProperty("gstreamer.dir", "vlib_gst");
  37.        
  38.         LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
  39.         cfg.title = "Test";
  40.         cfg.useGL30 = true;
  41.         cfg.width = 1280;
  42.         cfg.height = 720;
  43.        
  44.         new LwjglApplication(new VideoLoopExample(), cfg);
  45.     }
  46.  
  47.     @Override
  48.     public void resume()
  49.     {
  50.     }
  51.    
  52.     private class OurInputListener extends InputAdapter
  53.     {
  54.         @Override public boolean keyDown(int keycode)
  55.         {
  56.             if (keycode == Keys.ENTER)
  57.             {
  58.  
  59.             }
  60.             else if (keycode == Keys.ESCAPE)
  61.             {
  62.                 if (videoplayer != null)
  63.                 {
  64.                     videoplayer.destroy();
  65.                     videoplayer = null;
  66.                 }
  67.                 Gdx.app.exit();
  68.             }
  69.             else if (keycode == Keys.SPACE)
  70.             {
  71.                 if (videoplayer != null)
  72.                 {
  73.                     videoplayer.pause();
  74.                 }
  75.             }
  76.            
  77.             return true;
  78.         }
  79.     }
  80.  
  81.  
  82.     @Override
  83.     public void render()
  84.     {
  85.         Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  86.         Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  87.        
  88.         camera.update();
  89.         spriteBatch.setProjectionMatrix(camera.combined);
  90.        
  91. //      //RENDERING
  92.        
  93.         videoplayer.updateAndRender();
  94.        
  95.         if (videoplayer != null)
  96.         {
  97.             if(videoplayer.isDone())
  98.             {
  99.                 videoplayer.stop();
  100.                 videoplayer.getPlayBin().play();
  101.                 videoplayer.done = false;
  102.             }
  103.         }
  104.        
  105.         spriteBatch.begin();
  106.             font.setColor(Color.WHITE);
  107.             if (videoplayer == null)
  108.             {
  109.                 glyphL.setText(font, "Press Enter to start playing video.");
  110.                 font.draw(spriteBatch, "Press Enter to start playing video.", (Gdx.graphics.getWidth()/2)-(glyphL.width/2),  (Gdx.graphics.getHeight()/2)-(font.getLineHeight()/2));
  111.             }
  112.             else
  113.             {
  114.                 glyphL.setText(font, "This is text");
  115.                 font.draw(spriteBatch, "This is text", (Gdx.graphics.getWidth()/2)-(glyphL.width/2),  (Gdx.graphics.getHeight()/2)-(font.getLineHeight()/2));
  116.             }
  117.             font.draw(spriteBatch, "FPS: "+Gdx.graphics.getFramesPerSecond(), 12,  10);
  118.         spriteBatch.end();
  119.     }
  120.  
  121.     @Override
  122.     public void resize(int width, int height)
  123.     {
  124.     }
  125.  
  126.     @Override
  127.     public void pause()
  128.     {
  129.          
  130.     }
  131.  
  132.     @Override
  133.     public void dispose()
  134.     {
  135.         if (videoplayer != null)
  136.         {
  137.             videoplayer.stop();
  138.             videoplayer.destroy();
  139.             videoplayer = null;
  140.         }
  141.     }
  142.  
  143.    
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement