JOGL v2.6.0-rc-20250822
JOGL, High-Performance Graphics Binding for Java™ (public API).
MovieSimpleActivity0.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.net.HttpURLConnection;
31import java.net.URISyntaxException;
32import java.net.URLConnection;
33import java.util.Arrays;
34
35import com.jogamp.opengl.GLCapabilities;
36import com.jogamp.opengl.GLProfile;
37import com.jogamp.opengl.demos.android.LauncherUtil.OrderedProperties;
38import com.jogamp.opengl.demos.av.MovieSimple;
39
40import jogamp.newt.driver.android.NewtBaseActivity;
41
42import com.jogamp.common.net.Uri;
43import com.jogamp.common.util.IOUtil;
44import com.jogamp.newt.NewtFactory;
45import com.jogamp.newt.Window;
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.StreamException;
52
53import android.os.Bundle;
54import android.util.Log;
55
56public class MovieSimpleActivity0 extends NewtBaseActivity {
57 static String TAG = "MovieSimpleActivity0";
58
59 MouseAdapter toFrontMouseListener = new MouseAdapter() {
60 @Override
61 public void mouseClicked(final MouseEvent e) {
62 final Object src = e.getSource();
63 if(src instanceof Window) {
64 ((Window)src).requestFocus(false);
65 }
66 } };
67
68 public void initProperties() {
69 final OrderedProperties props = new OrderedProperties();
70 props.setProperty("jnlp.media0_url0", "https://archive.org/download/BigBuckBunny_328/BigBuckBunny_512kb.mp4");
71 props.setProperty("jnlp.media1_url1", "https://archive.org/download/ElephantsDream/ed_1024_512kb.mp4");
72 props.setProperty("jnlp.media0_url2", "file:///mnt/sdcard/Movies/BigBuckBunny_320x180.mp4");
73 // props.setProperty("jogamp.debug.JNILibLoader", "true");
74 // props.setProperty("jogamp.debug.NativeLibrary", "true");
75 // props.setProperty("jogamp.debug.NativeLibrary.Lookup", "true");
76 // props.setProperty("jogamp.debug.IOUtil", "true");
77 // props.setProperty("nativewindow.debug", "all");
78 // props.setProperty("nativewindow.debug.GraphicsConfiguration", "true");
79 // props.setProperty("jogl.debug", "all");
80 // props.setProperty("jogl.debug.GLProfile", "true");
81 // props.setProperty("jogl.debug.GLDrawable", "true");
82 // props.setProperty("jogl.debug.GLContext", "true");
83 props.setProperty("jogl.debug.GLMediaPlayer", "true");
84 props.setProperty("jogl.debug.GLSLCode", "true");
85 // props.setProperty("jogl.debug.CapabilitiesChooser", "true");
86 // props.setProperty("jogl.debug.GLSLState", "true");
87 // props.setProperty("jogl.debug.DebugGL", "true");
88 // props.setProperty("jogl.debug.TraceGL", "true");
89 // props.setProperty("newt.debug", "all");
90 // props.setProperty("newt.debug.Window", "true");
91 // props.setProperty("newt.debug.Window.MouseEvent", "true");
92 // props.setProperty("newt.debug.Window.KeyEvent", "true");
93 props.setProperty("jogamp.debug.IOUtil", "true");
94 props.setSystemProperties();
95 }
96
97 @Override
98 public void onCreate(final Bundle savedInstanceState) {
99 Log.d(TAG, "onCreate - 0");
100
102
103 super.onCreate(savedInstanceState);
104
105 final String[] streamLocs = new String[] {
106 System.getProperty("jnlp.media0_url0"),
107 System.getProperty("jnlp.media0_url1"),
108 System.getProperty("jnlp.media0_url2") };
109 final Uri streamLoc = getUri(streamLocs, 0, false);
110 if(null == streamLoc) { throw new RuntimeException("no media reachable: "+Arrays.asList(streamLocs)); }
111
112 // also initializes JOGL
113 final GLCapabilities capsMain = new GLCapabilities(GLProfile.getGL2ES2());
114 capsMain.setNumSamples(4);
115 capsMain.setSampleBuffers(true);
116 capsMain.setBackgroundOpaque(false);
117
118 Log.d(TAG, "req caps: "+capsMain);
119
120 // screen for layout params ..
123 scrn.addReference();
124
125 final Animator anim = new Animator(0 /* w/o AWT */);
126
127 // Main
128 final GLWindow glWindowMain = GLWindow.create(scrn, capsMain);
129 glWindowMain.setFullscreen(true);
130 setContentView(getWindow(), glWindowMain);
131 anim.add(glWindowMain);
132 glWindowMain.setVisible(true);
133
134 final MovieSimple demoMain = new MovieSimple(null);
135 demoMain.setUseOriginalScale(true);
136 final GLMediaPlayer mPlayer = demoMain.getGLMediaPlayer();
138 @Override
139 public void attributesChanged(final GLMediaPlayer mp, final GLMediaPlayer.EventMask eventMask, final long when) {
140 System.err.println("MovieSimpleActivity0 AttributesChanges: "+eventMask+", when "+when);
141 System.err.println("MovieSimpleActivity0 State: "+mp);
142 if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Init) ) {
143 glWindowMain.addGLEventListener(demoMain);
144 anim.setUpdateFPSFrames(60*5, System.err);
145 anim.resetFPSCounter();
146 }
147 if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Error) || eventMask.isSet(GLMediaPlayer.EventMask.Bit.EOS) ) {
148 final StreamException se = mPlayer.getStreamException();
149 if( null != se ) {
150 se.printStackTrace();
151 }
152 getActivity().finish();
153 }
154 }
155 });
156 demoMain.playStream(streamLoc, GLMediaPlayer.STREAM_ID_AUTO, GLMediaPlayer.STREAM_ID_AUTO, 0);
157
158 scrn.removeReference();
159
160 Log.d(TAG, "onCreate - X");
161 }
162
163 static Uri getUri(final String path[], final int off, final boolean checkAvail) {
164 Uri uri = null;
165 for(int i=off; null==uri && i<path.length; i++) {
166 if(null != path[i] && path[i].length()>0) {
167 if( checkAvail ) {
168 final URLConnection uc = IOUtil.getResource(path[i], null);
169 if( null != uc ) {
170 try {
171 uri = Uri.valueOf(uc.getURL());
172 } catch (final URISyntaxException e) {
173 uri = null;
174 }
175 if( uc instanceof HttpURLConnection ) {
176 ((HttpURLConnection)uc).disconnect();
177 }
178 }
179 } else {
180 try {
181 uri = Uri.cast(path[i]);
182 } catch (final URISyntaxException e) {
183 uri = null;
184 }
185 }
186 Log.d(TAG, "Stream: <"+path[i]+">: "+(null!=uri));
187 }
188 }
189 return uri;
190 }
191}
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().
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 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 planar movie player w/ orthogonal 1:1 projection.
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
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.
static final int STREAM_ID_AUTO
Constant {@value} for auto or unspecified.