JOGL v2.6.0-rc-20250722
JOGL, High-Performance Graphics Binding for Java™ (public API).
MovieCubeActivity0.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.androidfat;
29
30import java.io.IOException;
31import java.net.HttpURLConnection;
32import java.net.URISyntaxException;
33import java.net.URLConnection;
34import java.util.Arrays;
35
36import com.jogamp.opengl.GLCapabilities;
37import com.jogamp.opengl.GLProfile;
38import com.jogamp.opengl.demos.android.LauncherUtil.OrderedProperties;
39import com.jogamp.opengl.demos.av.MovieCube;
40
41import jogamp.newt.driver.android.NewtBaseActivity;
42
43import com.jogamp.common.net.Uri;
44import com.jogamp.common.util.IOUtil;
45import com.jogamp.newt.NewtFactory;
46import com.jogamp.newt.event.MouseAdapter;
47import com.jogamp.newt.event.MouseEvent;
48import com.jogamp.newt.opengl.GLWindow;
49import com.jogamp.opengl.util.Animator;
50import com.jogamp.opengl.util.av.GLMediaPlayer;
51import com.jogamp.opengl.util.av.GLMediaPlayer.GLMediaEventListener;
52import com.jogamp.opengl.util.av.GLMediaPlayer.StreamException;
53
54import android.os.Bundle;
55import android.util.Log;
56
57public class MovieCubeActivity0 extends NewtBaseActivity {
58 static String TAG = "MovieCubeActivity0";
59
60 MouseAdapter showKeyboardMouseListener = new MouseAdapter() {
61 @Override
62 public void mousePressed(final MouseEvent e) {
63 if( e.getPointerCount() == 4 && e.getPressure(0, true) > 0.7f ) {
64 ((com.jogamp.newt.Window) e.getSource()).setKeyboardVisible(true);
65 }
66 }
67 };
68
69 public void initProperties() {
70 final OrderedProperties props = new OrderedProperties();
71 props.setProperty("jnlp.media0_url0", "https://archive.org/download/BigBuckBunny_328/BigBuckBunny_512kb.mp4");
72 props.setProperty("jnlp.media1_url1", "https://archive.org/download/ElephantsDream/ed_1024_512kb.mp4");
73 props.setProperty("jnlp.media0_url2", "file:///mnt/sdcard/Movies/BigBuckBunny_320x180.mp4");
74 // props.setProperty("jogamp.debug.JNILibLoader", "true");
75 // props.setProperty("jogamp.debug.NativeLibrary", "true");
76 // props.setProperty("jogamp.debug.NativeLibrary.Lookup", "true");
77 // props.setProperty("jogamp.debug.IOUtil", "true");
78 // props.setProperty("jogamp.debug.Lock", "true");
79 // props.setProperty("jogamp.debug.Lock.TraceLock", "true");
80 // props.setProperty("nativewindow.debug", "all");
81 // props.setProperty("nativewindow.debug.GraphicsConfiguration", "true");
82 // props.setProperty("jogl.debug", "all");
83 // props.setProperty("jogl.debug.GLProfile", "true");
84 // props.setProperty("jogl.debug.GLDrawable", "true");
85 // props.setProperty("jogl.debug.GLContext", "true");
86 props.setProperty("jogl.debug.GLMediaPlayer", "true");
87 props.setProperty("jogl.debug.GLSLCode", "true");
88 // props.setProperty("jogl.debug.CapabilitiesChooser", "true");
89 // props.setProperty("jogl.debug.GLSLState", "true");
90 // props.setProperty("jogl.debug.DebugGL", "true");
91 // props.setProperty("jogl.debug.TraceGL", "true");
92 // props.setProperty("newt.debug", "all");
93 // props.setProperty("newt.debug.Window", "true");
94 // props.setProperty("newt.debug.Window.MouseEvent", "true");
95 // props.setProperty("newt.debug.Window.KeyEvent", "true");
96 // props.setProperty("jogamp.debug.IOUtil", "true");
97 props.setSystemProperties();
98 }
99
100 @Override
101 public void onCreate(final Bundle savedInstanceState) {
102 Log.d(TAG, "onCreate - 0");
103
105
106 super.onCreate(savedInstanceState);
107
108 final String[] streamLocs = new String[] {
109 System.getProperty("jnlp.media0_url0"),
110 System.getProperty("jnlp.media0_url1"),
111 System.getProperty("jnlp.media0_url2") };
112 final Uri streamLoc = getUri(streamLocs, 0, false);
113 if(null == streamLoc) { throw new RuntimeException("no media reachable: "+Arrays.asList(streamLocs)); }
114
115 // also initializes JOGL
116 final GLCapabilities capsMain = new GLCapabilities(GLProfile.getGL2ES2());
117 capsMain.setNumSamples(4);
118 capsMain.setSampleBuffers(true);
119 capsMain.setBackgroundOpaque(false);
120
121 Log.d(TAG, "req caps: "+capsMain);
122
123 // screen for layout params ..
126 scrn.addReference();
127
128 try {
129 final Animator anim = new Animator(0 /* w/o AWT */);
130
131 // Main
132 final GLWindow glWindowMain = GLWindow.create(scrn, capsMain);
133 glWindowMain.setFullscreen(true);
134 setContentView(getWindow(), glWindowMain);
135 anim.add(glWindowMain);
136 glWindowMain.setVisible(true);
137 glWindowMain.addMouseListener(showKeyboardMouseListener);
138
139 final MovieCube demoMain = new MovieCube(MovieCube.zoom_def, 0f, 0f, true);
140 final GLMediaPlayer mPlayer = demoMain.getGLMediaPlayer();
142 @Override
143 public void attributesChanged(final GLMediaPlayer mp, final GLMediaPlayer.EventMask eventMask, final long when) {
144 System.err.println("MovieCubeActivity0 AttributesChanges: "+eventMask+", when "+when);
145 System.err.println("MovieCubeActivity0 State: "+mp);
146 if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Init) ) {
147 glWindowMain.addGLEventListener(demoMain);
148 anim.setUpdateFPSFrames(60*5, null);
149 anim.resetFPSCounter();
150 } else if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Play) ) {
151 anim.resetFPSCounter();
152 }
153 if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Error) || eventMask.isSet(GLMediaPlayer.EventMask.Bit.EOS) ) {
154 final StreamException se = mPlayer.getStreamException();
155 if( null != se ) {
156 se.printStackTrace();
157 }
158 getActivity().finish();
159 }
160 }
161 });
163 } catch (final IOException e) {
164 e.printStackTrace();
165 }
166
167 scrn.removeReference();
168
169 Log.d(TAG, "onCreate - X");
170 }
171
172 static Uri getUri(final String path[], final int off, final boolean checkAvail) {
173 Uri uri = null;
174 for(int i=off; null==uri && i<path.length; i++) {
175 if(null != path[i] && path[i].length()>0) {
176 if( checkAvail ) {
177 final URLConnection uc = IOUtil.getResource(path[i], null);
178 if( null != uc ) {
179 try {
180 uri = Uri.valueOf(uc.getURL());
181 } catch (final URISyntaxException e) {
182 uri = null;
183 }
184 if( uc instanceof HttpURLConnection ) {
185 ((HttpURLConnection)uc).disconnect();
186 }
187 }
188 } else {
189 try {
190 uri = Uri.cast(path[i]);
191 } catch (final URISyntaxException e) {
192 uri = null;
193 }
194 }
195 Log.d(TAG, "Stream: <"+path[i]+">: "+(null!=uri));
196 }
197 }
198 return uri;
199 }
200}
void setBackgroundOpaque(final boolean opaque)
Sets whether the surface shall be opaque or translucent.
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 addReference()
See Display#addReference().
abstract int removeReference()
See Display#removeReference().
Pointer event of type PointerType.
Definition: MouseEvent.java:74
final int getPointerCount()
See details for multiple-pointer events.
final float getPressure(final boolean normalized)
An implementation of GLAutoDrawable and Window interface, using a delegated Window instance,...
Definition: GLWindow.java:121
final void addMouseListener(final MouseListener l)
Appends the given MouseListener to the end of the list.
Definition: GLWindow.java:927
final boolean setFullscreen(final boolean fullscreen)
Enable or disable fullscreen mode for this window.
Definition: GLWindow.java:534
final void setVisible(final boolean visible)
Calls setVisible(true, visible), i.e.
Definition: GLWindow.java:615
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
final void setProperty(final String key, final String value)
Simple cube movie player w/ aspect ration true projection on a cube.
Definition: MovieCube.java:73
void playStream(final Uri streamLoc, final int vid, final int aid, final int textureCount)
Definition: MovieCube.java:144
final void resetFPSCounter()
Reset all performance counter (startTime, currentTime, frame number)
final synchronized void add(final GLAutoDrawable drawable)
Adds a drawable to this animator's list of rendering drawables.
final void setUpdateFPSFrames(final int frames, final PrintStream out)
A StreamException encapsulates a caught exception in the decoder thread, a.k.a StreamWorker,...
void addGLEventListener(GLEventListener listener)
Adds the given listener to the end of this drawable queue.
As the contract of GLMediaFrameListener and TexSeqEventListener requests, implementations of GLMediaE...
GLMediaPlayer interface specifies a TextureSequence state machine using a multiplexed audio/video str...
void addEventListener(GLMediaEventListener l)
Adds a GLMediaEventListener to this player.
StreamException getStreamException()
Returns the StreamException caught in the decoder thread, or null if none occured.
static final int STREAM_ID_AUTO
Constant {@value} for auto or unspecified.