JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
MovieCubeActivity0b.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.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.av.MovieCube;
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.event.MouseAdapter;
46import com.jogamp.newt.event.MouseEvent;
47import com.jogamp.newt.opengl.GLWindow;
48import com.jogamp.opengl.util.Animator;
49import com.jogamp.opengl.util.av.GLMediaPlayer;
50import com.jogamp.opengl.util.av.GLMediaPlayer.GLMediaEventListener;
51import com.jogamp.opengl.util.av.GLMediaPlayer.StreamException;
52import com.jogamp.opengl.util.texture.TextureSequence.TextureFrame;
53
54import android.os.Bundle;
55import android.util.Log;
56
57public class MovieCubeActivity0b extends NewtBaseActivity {
58 static String TAG = "MovieCubeActivity0a";
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 @Override
70 public void onCreate(final Bundle savedInstanceState) {
71 super.onCreate(savedInstanceState);
72
73 final String[] streamLocs = new String[] {
74 System.getProperty("jnlp.media0_url0"),
75 System.getProperty("jnlp.media0_url1"),
76 System.getProperty("jnlp.media0_url2") };
77 final Uri streamLoc = getUri(streamLocs, 0, false);
78 if(null == streamLoc) { throw new RuntimeException("no media reachable: "+Arrays.asList(streamLocs)); }
79
80 // also initializes JOGL
81 final GLCapabilities capsMain = new GLCapabilities(GLProfile.getGL2ES2());
82 capsMain.setNumSamples(4);
83 capsMain.setSampleBuffers(true);
84 capsMain.setBackgroundOpaque(false);
85
86 // screen for layout params ..
89 scrn.addReference();
90
91 try {
92 final Animator anim = new Animator(0 /* w/o AWT */);
93
94 // Main
95 final GLWindow glWindowMain = GLWindow.create(scrn, capsMain);
96 glWindowMain.setFullscreen(true);
97 setContentView(getWindow(), glWindowMain);
98 anim.add(glWindowMain);
99 glWindowMain.setVisible(true);
100 glWindowMain.addMouseListener(showKeyboardMouseListener);
101
102 final MovieCube demoMain = new MovieCube(MovieCube.zoom_def, 0f, 0f, true);
103 final GLMediaPlayer mPlayer = demoMain.getGLMediaPlayer();
105 @Override
106 public void attributesChanged(final GLMediaPlayer mp, final GLMediaPlayer.EventMask eventMask, final long when) {
107 System.err.println("MovieCubeActivity0 AttributesChanges: "+eventMask+", when "+when);
108 System.err.println("MovieCubeActivity0 State: "+mp);
109 if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Init) ) {
110 glWindowMain.addGLEventListener(demoMain);
111 anim.setUpdateFPSFrames(60*5, null);
112 anim.resetFPSCounter();
113 } else if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Play) ) {
114 anim.resetFPSCounter();
115 }
116 if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Error) || eventMask.isSet(GLMediaPlayer.EventMask.Bit.EOS) ) {
117 final StreamException se = mPlayer.getStreamException();
118 if( null != se ) {
119 se.printStackTrace();
120 }
121 getActivity().finish();
122 }
123 }
124 });
126 } catch (final IOException e) {
127 e.printStackTrace();
128 }
129
130 scrn.removeReference();
131
132 Log.d(TAG, "onCreate - X");
133 }
134
135 static Uri getUri(final String path[], final int off, final boolean checkAvail) {
136 Uri uri = null;
137 for(int i=off; null==uri && i<path.length; i++) {
138 if(null != path[i] && path[i].length()>0) {
139 if( checkAvail ) {
140 final URLConnection uc = IOUtil.getResource(path[i], null);
141 if( null != uc ) {
142 try {
143 uri = Uri.valueOf(uc.getURL());
144 } catch (final URISyntaxException e) {
145 uri = null;
146 }
147 if( uc instanceof HttpURLConnection ) {
148 ((HttpURLConnection)uc).disconnect();
149 }
150 }
151 } else {
152 try {
153 uri = Uri.cast(path[i]);
154 } catch (final URISyntaxException e) {
155 uri = null;
156 }
157 }
158 Log.d(TAG, "Stream: <"+path[i]+">: "+(null!=uri));
159 }
160 }
161 return uri;
162 }
163}
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
void onCreate(final Bundle savedInstanceState)
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.