28package com.jogamp.opengl.demos.android;
30import java.net.HttpURLConnection;
31import java.net.URISyntaxException;
32import java.net.URLConnection;
33import java.util.Arrays;
35import com.jogamp.nativewindow.util.Rectangle;
36import com.jogamp.opengl.GLAutoDrawable;
37import com.jogamp.opengl.GLCapabilities;
38import com.jogamp.opengl.GLProfile;
39import com.jogamp.opengl.GLRunnable;
40import com.jogamp.opengl.demos.av.MovieSimple;
42import jogamp.newt.driver.android.NewtBaseActivity;
44import com.jogamp.common.net.Uri;
45import com.jogamp.common.util.IOUtil;
46import com.jogamp.newt.NewtFactory;
47import com.jogamp.newt.Window;
48import com.jogamp.newt.event.MouseAdapter;
49import com.jogamp.newt.event.MouseEvent;
50import com.jogamp.newt.opengl.GLWindow;
51import com.jogamp.opengl.util.Animator;
52import com.jogamp.opengl.util.av.GLMediaPlayer;
53import com.jogamp.opengl.util.av.GLMediaPlayer.StreamException;
55import android.os.Bundle;
56import android.util.Log;
57import android.view.Gravity;
60 static String TAG =
"MovieSimpleActivity1";
65 final Object src = e.getSource();
66 if(src instanceof
Window) {
67 ((
Window)src).requestFocus(
false);
72 public void onCreate(
final Bundle savedInstanceState) {
73 super.onCreate(savedInstanceState);
75 final boolean mPlayerNoZoom = Boolean.valueOf(System.getProperty(
"jnlp.mplayer.nozoom"));
76 final boolean mPlayerHUD = Boolean.valueOf(System.getProperty(
"jnlp.mplayer.hud"));
77 final boolean mPlayerSharedHUD = mPlayerHUD && Boolean.valueOf(System.getProperty(
"jnlp.mplayer.hud.shared"));
78 Log.d(TAG,
"onCreate - 0 - mPlayerNoScale "+mPlayerNoZoom+
", mPlayerHUD "+mPlayerHUD+
", mPlayerSharedHUD "+mPlayerSharedHUD);
80 final String[] streamLocs =
new String[] {
81 System.getProperty(
"jnlp.media0_url0"),
82 System.getProperty(
"jnlp.media0_url1"),
83 System.getProperty(
"jnlp.media0_url2") };
84 final Uri streamLoc0 = getUri(streamLocs, 2,
false);
85 if(
null == streamLoc0) {
throw new RuntimeException(
"no media reachable: "+Arrays.asList(streamLocs)); }
89 Uri _streamLoc1 =
null;
90 if(mPlayerHUD && !mPlayerSharedHUD) {
91 final String[] urls1 =
new String[] { System.getProperty(
"jnlp.media1_url0") };
92 _streamLoc1 = getUri(urls1, 1,
false);
94 if(
null == _streamLoc1) { _streamLoc1 = streamLoc0; }
95 streamLoc1 = _streamLoc1;
98 setTransparencyTheme();
99 setFullscreenFeature(getWindow(),
true);
101 final android.view.ViewGroup viewGroup =
new android.widget.FrameLayout(getActivity().getApplicationContext());
102 getWindow().setContentView(viewGroup);
120 final int padding = mPlayerHUD ? 32 : 0;
121 final android.view.View androidView = ((jogamp.newt.driver.android.WindowDriver)glWindowMain.
getDelegatedWindow()).getAndroidView();
125 viewGroup.addView(androidView,
new android.widget.FrameLayout.LayoutParams(glWindowMain.
getSurfaceWidth(), glWindowMain.
getSurfaceHeight(), Gravity.BOTTOM|Gravity.RIGHT));
126 registerNEWTWindow(glWindowMain);
128 anim.
add(glWindowMain);
140 public void attributesChanged(final GLMediaPlayer mp, final GLMediaPlayer.EventMask eventMask, final long when) {
141 System.err.println(
"MovieSimpleActivity1 AttributesChanges: "+eventMask+
", when "+when);
142 System.err.println(
"MovieSimpleActivity1 State: "+mp);
143 if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Init) ) {
144 glWindowMain.addGLEventListener(demoMain);
145 anim.setUpdateFPSFrames(60*5, System.err);
146 anim.resetFPSCounter();
148 if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Error) || eventMask.isSet(GLMediaPlayer.EventMask.Bit.EOS) ) {
149 final StreamException se = mPlayerMain.getStreamException();
151 se.printStackTrace();
153 getActivity().finish();
160 final GLMediaPlayer mPlayerShared = mPlayerSharedHUD ? mPlayerMain :
null;
172 if(
null != mPlayerShared) {
173 if(0 < mPlayerShared.
getWidth() && mPlayerShared.
getWidth()<scrn.getWidth()/2 &&
179 glWindowHUD.setSharedAutoDrawable(glWindowMain);
180 demoHUD =
new MovieSimple(mPlayerShared);
181 mPlayerSub = mPlayerShared;
183 demoHUD =
new MovieSimple(
null);
188 public void attributesChanged(final GLMediaPlayer mp, final GLMediaPlayer.EventMask eventMask, final long when) {
189 if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Init) ) {
190 glWindowHUD.addGLEventListener(demoHUD);
192 if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Error) || eventMask.isSet(GLMediaPlayer.EventMask.Bit.EOS) ) {
193 final StreamException se = mPlayerMain.getStreamException();
195 se.printStackTrace();
197 getActivity().finish();
201 demoHUD.
playStream(streamLoc1, GLMediaPlayer.STREAM_ID_AUTO, GLMediaPlayer.STREAM_ID_AUTO, 0);
205 System.err.println(
"HUD: "+mPlayerHUD);
206 System.err.println(
"HUD: "+windowBounds);
209 viewGroup.post(
new Runnable() {
212 final android.view.View androidView = ((jogamp.newt.driver.android.WindowDriver)glWindowHUD.
getDelegatedWindow()).getAndroidView();
214 viewGroup.addView(androidView,
new android.widget.FrameLayout.LayoutParams(glWindowHUD.
getSurfaceWidth(), glWindowHUD.
getSurfaceHeight(), Gravity.TOP|Gravity.LEFT));
215 registerNEWTWindow(glWindowHUD);
216 anim.add(glWindowHUD);
223 scrn.removeReference();
225 Log.d(TAG,
"onCreate - X");
228 static Uri getUri(
final String path[],
final int off,
final boolean checkAvail) {
230 for(
int i=off;
null==uri && i<path.length; i++) {
231 if(
null != path[i] && path[i].length()>0) {
233 final URLConnection uc = IOUtil.getResource(path[i],
null);
236 uri = Uri.valueOf(uc.getURL());
237 }
catch (
final URISyntaxException e) {
240 if( uc instanceof HttpURLConnection ) {
241 ((HttpURLConnection)uc).disconnect();
246 uri = Uri.cast(path[i]);
247 }
catch (
final URISyntaxException e) {
251 Log.d(TAG,
"Stream: <"+path[i]+
">: "+(
null!=uri));
void setBackgroundOpaque(final boolean opaque)
Sets whether the surface shall be opaque or translucent.
final int getX()
x-position, left of rectangle.
final Rectangle setWidth(final int width)
final int getY()
y-position, top of rectangle.
final Rectangle setHeight(final int height)
static Display createDisplay(final String name)
Create a Display entity.
static Screen createScreen(final Display display, final int index)
Create a Screen entity.
A screen may span multiple MonitorDevices representing their combined virtual size.
abstract int addReference()
See Display#addReference().
Pointer event of type PointerType.
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
final int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
final void addMouseListener(final MouseListener l)
Appends the given MouseListener to the end of the list.
final void setPosition(final int x, final int y)
Sets the location of the window's client area excluding insets (window decorations) in window units.
final int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
final int[] convertToWindowUnits(final int[] pixelUnitsAndResult)
Converts the given pixel units into window units in place.
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
final void setSurfaceSize(final int pixelWidth, final int pixelHeight)
Sets the size of the window's surface in pixel units which claims the window's client area excluding ...
final void setUndecorated(final boolean value)
final Window getDelegatedWindow()
If the implementation uses delegation, return the delegated Window instance, otherwise return this in...
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Specifies a set of OpenGL capabilities.
void setNumSamples(final int numSamples)
If sample buffers are enabled, indicates the number of buffers to be allocated.
void setSampleBuffers(final boolean enable)
Defaults to false.
Specifies the the OpenGL profile.
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
void onCreate(final Bundle savedInstanceState)
Simple planar movie player w/ orthogonal 1:1 projection.
GLMediaPlayer getGLMediaPlayer()
void setEffects(final int e)
void playStream(final Uri streamLoc, final int vid, final int aid, final int textureCount)
static final int EFFECT_GRADIENT_BOTTOM2TOP
void setTransparency(final float alpha)
void setUseOriginalScale(final boolean v)
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
Specifying NEWT's Window functionality:
A higher-level abstraction than GLDrawable which supplies an event based mechanism (GLEventListener) ...
boolean invoke(boolean wait, GLRunnable glRunnable)
Enqueues a one-shot GLRunnable, which will be executed within the next display() call after all regis...