From 9e680fe86cd5b64aa758ce32666a6efa19118d3d Mon Sep 17 00:00:00 2001 From: Sven Gothel <sgothel@jausoft.com> Date: Tue, 3 Apr 2012 22:39:27 +0200 Subject: GLMediaPlayer/MovieSimple: Refine API (split setStream(GL, URL) -> initStream(URL) + initGL(GL)) .. IllegalStateException if wrong. Using internet streams of BigBuckBunny, if avail. - Splitting the initialization in stream and GL allows using the stream information (eg: size, ..) for setting the GLDrawable properties .. - Make the impl. more bullet proof .. --- .../android/av/AndroidGLMediaPlayerAPI14.java | 83 +++++++++++----------- 1 file changed, 43 insertions(+), 40 deletions(-) (limited to 'src/jogl/classes/jogamp/opengl/android/av') diff --git a/src/jogl/classes/jogamp/opengl/android/av/AndroidGLMediaPlayerAPI14.java b/src/jogl/classes/jogamp/opengl/android/av/AndroidGLMediaPlayerAPI14.java index a2d9b9bf3..037ab779c 100644 --- a/src/jogl/classes/jogamp/opengl/android/av/AndroidGLMediaPlayerAPI14.java +++ b/src/jogl/classes/jogamp/opengl/android/av/AndroidGLMediaPlayerAPI14.java @@ -53,14 +53,21 @@ public class AndroidGLMediaPlayerAPI14 extends GLMediaPlayerImpl { // n/a } + @Override + public float getPlaySpeed() { + return 0; + } + @Override protected boolean startImpl() { - try { - mp.start(); - return true; - } catch (IllegalStateException ise) { - if(DEBUG) { - ise.printStackTrace(); + if(null != mp) { + try { + mp.start(); + return true; + } catch (IllegalStateException ise) { + if(DEBUG) { + ise.printStackTrace(); + } } } return false; @@ -68,12 +75,14 @@ public class AndroidGLMediaPlayerAPI14 extends GLMediaPlayerImpl { @Override protected boolean pauseImpl() { - try { - mp.pause(); - return true; - } catch (IllegalStateException ise) { - if(DEBUG) { - ise.printStackTrace(); + if(null != mp) { + try { + mp.pause(); + return true; + } catch (IllegalStateException ise) { + if(DEBUG) { + ise.printStackTrace(); + } } } return false; @@ -81,21 +90,26 @@ public class AndroidGLMediaPlayerAPI14 extends GLMediaPlayerImpl { @Override protected boolean stopImpl() { - try { - mp.stop(); - return true; - } catch (IllegalStateException ise) { - if(DEBUG) { - ise.printStackTrace(); + if(null != mp) { + try { + mp.stop(); + return true; + } catch (IllegalStateException ise) { + if(DEBUG) { + ise.printStackTrace(); + } } } return false; } @Override - public long seek(long msec) { - mp.seekTo((int)msec); - return mp.getCurrentPosition(); + protected long seekImpl(long msec) { + if(null != mp) { + mp.seekTo((int)msec); + return mp.getCurrentPosition(); + } + return 0; } @Override @@ -105,7 +119,7 @@ public class AndroidGLMediaPlayerAPI14 extends GLMediaPlayerImpl { @Override public TextureFrame getNextTexture() { - if(null != atex) { + if(null != atex && null != mp) { final boolean _updateSurface; synchronized(updateSurfaceLock) { _updateSurface = updateSurface; @@ -126,11 +140,6 @@ public class AndroidGLMediaPlayerAPI14 extends GLMediaPlayerImpl { return null != mp ? mp.getCurrentPosition() : 0; } - @Override - public boolean isValid() { - return null != mp; - } - @Override protected void destroyImpl(GL gl) { if(null != mp) { @@ -140,7 +149,7 @@ public class AndroidGLMediaPlayerAPI14 extends GLMediaPlayerImpl { } @Override - protected void setStreamImplPreGL() throws IOException { + protected void initStreamImplPreGL() throws IOException { if(null!=mp && null!=url) { try { final Uri uri = Uri.parse(url.toExternalForm()); @@ -152,7 +161,11 @@ public class AndroidGLMediaPlayerAPI14 extends GLMediaPlayerImpl { } catch (IllegalStateException e) { throw new RuntimeException(e); } - mp.prepare(); + try { + mp.prepare(); + } catch (IOException ioe) { + throw new IOException("MediaPlayer failed to process stream <"+url.toExternalForm()+">: "+ioe.getMessage(), ioe); + } width = mp.getVideoWidth(); height = mp.getVideoHeight(); @@ -165,11 +178,6 @@ public class AndroidGLMediaPlayerAPI14 extends GLMediaPlayerImpl { } } - @Override - protected void setStreamImplPostGL() throws IOException { - - } - @Override protected void destroyTexImage(GLContext ctx, TextureFrame imgTex) { final AndroidTextureFrame atf = (AndroidTextureFrame) imgTex; @@ -200,10 +208,5 @@ public class AndroidGLMediaPlayerAPI14 extends GLMediaPlayerImpl { } AndroidGLMediaPlayerAPI14.this.newFrameAvailable(atex); } - }; - - @Override - public float getPlaySpeed() { - return 0; - } + }; } -- cgit v1.2.3