JOGL v2.6.0-rc-20250712
JOGL, High-Performance Graphics Binding for Java™ (public API).
MovieSimpleActivity1.java
Go to the documentation of this file.
1/**
2 * Copyright 2011 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28package com.jogamp.opengl.demos.android;
29
30import java.net.HttpURLConnection;
31import java.net.URISyntaxException;
32import java.net.URLConnection;
33import java.util.Arrays;
34
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;
41
42import jogamp.newt.driver.android.NewtBaseActivity;
43
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;
54
55import android.os.Bundle;
56import android.util.Log;
57import android.view.Gravity;
58
59public class MovieSimpleActivity1 extends NewtBaseActivity {
60 static String TAG = "MovieSimpleActivity1";
61
62 MouseAdapter toFrontMouseListener = new MouseAdapter() {
63 @Override
64 public void mouseClicked(final MouseEvent e) {
65 final Object src = e.getSource();
66 if(src instanceof Window) {
67 ((Window)src).requestFocus(false);
68 }
69 } };
70
71 @Override
72 public void onCreate(final Bundle savedInstanceState) {
73 super.onCreate(savedInstanceState);
74
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);
79
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)); }
86
87 final Uri streamLoc1;
88 {
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);
93 }
94 if(null == _streamLoc1) { _streamLoc1 = streamLoc0; }
95 streamLoc1 = _streamLoc1;
96 }
97
98 setTransparencyTheme();
99 setFullscreenFeature(getWindow(), true);
100
101 final android.view.ViewGroup viewGroup = new android.widget.FrameLayout(getActivity().getApplicationContext());
102 getWindow().setContentView(viewGroup);
103
104 // also initializes JOGL
105 final GLCapabilities capsMain = new GLCapabilities(GLProfile.getGL2ES2());
106 capsMain.setNumSamples(4);
107 capsMain.setSampleBuffers(true);
108 capsMain.setBackgroundOpaque(!mPlayerHUD);
109
110 // screen for layout params ..
113 scrn.addReference();
114
115 final Animator anim = new Animator(0 /* w/o AWT */);
116
117 // Main
118 final GLWindow glWindowMain = GLWindow.create(scrn, capsMain);
119 {
120 final int padding = mPlayerHUD ? 32 : 0;
121 final android.view.View androidView = ((jogamp.newt.driver.android.WindowDriver)glWindowMain.getDelegatedWindow()).getAndroidView();
122 glWindowMain.setSurfaceSize(scrn.getWidth()-padding, scrn.getHeight()-padding);
123 glWindowMain.setUndecorated(true);
124 // setContentView(getWindow(), glWindowMain);
125 viewGroup.addView(androidView, new android.widget.FrameLayout.LayoutParams(glWindowMain.getSurfaceWidth(), glWindowMain.getSurfaceHeight(), Gravity.BOTTOM|Gravity.RIGHT));
126 registerNEWTWindow(glWindowMain);
127 }
128 anim.add(glWindowMain);
129 glWindowMain.setVisible(true);
130
131 final MovieSimple demoMain = new MovieSimple(null);
132 final GLMediaPlayer mPlayerMain = demoMain.getGLMediaPlayer();
133 if(mPlayerHUD) {
135 demoMain.setTransparency(0.9f);
136 }
137 demoMain.setUseOriginalScale(mPlayerNoZoom);
139 @Override
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();
147 }
148 if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Error) || eventMask.isSet(GLMediaPlayer.EventMask.Bit.EOS) ) {
149 final StreamException se = mPlayerMain.getStreamException();
150 if( null != se ) {
151 se.printStackTrace();
152 }
153 getActivity().finish();
154 }
155 }
156 });
157 demoMain.playStream(streamLoc0, GLMediaPlayer.STREAM_ID_AUTO, GLMediaPlayer.STREAM_ID_AUTO, 0);
158
159 if(mPlayerHUD) {
160 final GLMediaPlayer mPlayerShared = mPlayerSharedHUD ? mPlayerMain : null;
161 final GLCapabilities capsHUD = new GLCapabilities(GLProfile.getGL2ES2());
162 capsHUD.setNumSamples(4);
163 capsHUD.setSampleBuffers(true);
164 capsHUD.setBackgroundOpaque(false);
165 final GLWindow glWindowHUD = GLWindow.create(scrn, capsHUD);
166 glWindowMain.invoke(false, new GLRunnable() {
167 @Override
168 public boolean run(final GLAutoDrawable drawable) {
169 final GLMediaPlayer mPlayerSub;
170 final MovieSimple demoHUD;
171 final Rectangle windowBounds = (Rectangle) scrn.getViewportInWindowUnits().cloneMutable();
172 if(null != mPlayerShared) {
173 if(0 < mPlayerShared.getWidth() && mPlayerShared.getWidth()<scrn.getWidth()/2 &&
174 0 < mPlayerShared.getHeight() && mPlayerShared.getHeight()<scrn.getHeight()/2) {
175 final int[] wh = glWindowHUD.convertToWindowUnits(new int[]{mPlayerShared.getWidth(), mPlayerShared.getHeight()});
176 windowBounds.setWidth( wh[0] );
177 windowBounds.setHeight( wh[1] );
178 }
179 glWindowHUD.setSharedAutoDrawable(glWindowMain);
180 demoHUD = new MovieSimple(mPlayerShared);
181 mPlayerSub = mPlayerShared;
182 } else {
183 demoHUD = new MovieSimple(null);
184 mPlayerSub = demoHUD.getGLMediaPlayer();
185 }
186 mPlayerSub.addEventListener( new GLMediaPlayer.GLMediaEventListener() {
187 @Override
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);
191 }
192 if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Error) || eventMask.isSet(GLMediaPlayer.EventMask.Bit.EOS) ) {
193 final StreamException se = mPlayerMain.getStreamException();
194 if( null != se ) {
195 se.printStackTrace();
196 }
197 getActivity().finish();
198 }
199 }
200 });
201 demoHUD.playStream(streamLoc1, GLMediaPlayer.STREAM_ID_AUTO, GLMediaPlayer.STREAM_ID_AUTO, 0);
202
203 glWindowHUD.setPosition(windowBounds.getX(), windowBounds.getY());
204 glWindowHUD.setSize(windowBounds.getWidth(), windowBounds.getHeight());
205 System.err.println("HUD: "+mPlayerHUD);
206 System.err.println("HUD: "+windowBounds);
207 glWindowHUD.addMouseListener(toFrontMouseListener);
208
209 viewGroup.post(new Runnable() {
210 @Override
211 public void run() {
212 final android.view.View androidView = ((jogamp.newt.driver.android.WindowDriver)glWindowHUD.getDelegatedWindow()).getAndroidView();
213 // addContentView(getWindow(), glWindowHUD, new android.view.ViewGroup.LayoutParams(glWindowHUD.getWidth(), glWindowHUD.getHeight()));
214 viewGroup.addView(androidView, new android.widget.FrameLayout.LayoutParams(glWindowHUD.getSurfaceWidth(), glWindowHUD.getSurfaceHeight(), Gravity.TOP|Gravity.LEFT));
215 registerNEWTWindow(glWindowHUD);
216 anim.add(glWindowHUD);
217 glWindowHUD.setVisible(true);
218 } } );
219 return true;
220 } } );
221 }
222
223 scrn.removeReference();
224
225 Log.d(TAG, "onCreate - X");
226 }
227
228 static Uri getUri(final String path[], final int off, final boolean checkAvail) {
229 Uri uri = null;
230 for(int i=off; null==uri && i<path.length; i++) {
231 if(null != path[i] && path[i].length()>0) {
232 if( checkAvail ) {
233 final URLConnection uc = IOUtil.getResource(path[i], null);
234 if( null != uc ) {
235 try {
236 uri = Uri.valueOf(uc.getURL());
237 } catch (final URISyntaxException e) {
238 uri = null;
239 }
240 if( uc instanceof HttpURLConnection ) {
241 ((HttpURLConnection)uc).disconnect();
242 }
243 }
244 } else {
245 try {
246 uri = Uri.cast(path[i]);
247 } catch (final URISyntaxException e) {
248 uri = null;
249 }
250 }
251 Log.d(TAG, "Stream: <"+path[i]+">: "+(null!=uri));
252 }
253 }
254 return uri;
255 }
256}
void setBackgroundOpaque(final boolean opaque)
Sets whether the surface shall be opaque or translucent.
final int getX()
x-position, left of rectangle.
Definition: Rectangle.java:68
final Rectangle setWidth(final int width)
Definition: Rectangle.java:92
final int getY()
y-position, top of rectangle.
Definition: Rectangle.java:70
final Rectangle setHeight(final int height)
Definition: Rectangle.java:93
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.
Definition: Screen.java:58
abstract int getHeight()
abstract int addReference()
See Display#addReference().
abstract int getWidth()
Pointer event of type PointerType.
Definition: MouseEvent.java:74
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
final int getSurfaceHeight()
Returns the height of this GLDrawable's surface client area in pixel units.
Definition: GLWindow.java:466
final void addMouseListener(final MouseListener l)
Appends the given MouseListener to the end of the list.
Definition: GLWindow.java:927
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.
Definition: GLWindow.java:525
final int getSurfaceWidth()
Returns the width of this GLDrawable's surface client area in pixel units.
Definition: GLWindow.java:461
final void setSize(final int width, final int height)
Sets the size of the window's client area in window units, excluding decorations.
Definition: GLWindow.java:625
final int[] convertToWindowUnits(final int[] pixelUnitsAndResult)
Converts the given pixel units into window units in place.
Definition: GLWindow.java:476
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
Definition: GLWindow.java:615
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 ...
Definition: GLWindow.java:629
final void setUndecorated(final boolean value)
Definition: GLWindow.java:337
final Window getDelegatedWindow()
If the implementation uses delegation, return the delegated Window instance, otherwise return this in...
Definition: GLWindow.java:277
static GLWindow create(final GLCapabilitiesImmutable caps)
Creates a new GLWindow attaching a new Window referencing a new default Screen and default Display wi...
Definition: GLWindow.java:169
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.
Definition: GLProfile.java:77
static GLProfile getGL2ES2(final AbstractGraphicsDevice device)
Returns the GL2ES2 profile implementation, hence compatible w/ GL2ES2.
Definition: GLProfile.java:913
Simple planar movie player w/ orthogonal 1:1 projection.
void playStream(final Uri streamLoc, final int vid, final int aid, final int textureCount)
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:
Definition: Window.java:115
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...
As the contract of GLMediaFrameListener and TexSeqEventListener requests, implementations of GLMediaE...
GLMediaPlayer interface specifies a TextureSequence state machine using a multiplexed audio/video str...
int getWidth()
Returns the width of the video.
int getHeight()
Returns the height of the video.
void addEventListener(GLMediaEventListener l)
Adds a GLMediaEventListener to this player.
static final int STREAM_ID_AUTO
Constant {@value} for auto or unspecified.