JOGL v2.6.0-rc-20250712
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.android;
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.av.MovieSimple;
38
39import jogamp.newt.driver.android.NewtBaseActivity;
40
41import com.jogamp.common.net.Uri;
42import com.jogamp.common.util.IOUtil;
43import com.jogamp.newt.NewtFactory;
44import com.jogamp.newt.Window;
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.StreamException;
51import com.jogamp.opengl.util.texture.TextureSequence.TextureFrame;
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 @Override
69 public void onCreate(final Bundle savedInstanceState) {
70 super.onCreate(savedInstanceState);
71
72 final String[] streamLocs = new String[] {
73 System.getProperty("jnlp.media0_url0"),
74 System.getProperty("jnlp.media0_url1"),
75 System.getProperty("jnlp.media0_url2") };
76 final Uri streamLoc = getUri(streamLocs, 0, false);
77 if(null == streamLoc) { throw new RuntimeException("no media reachable: "+Arrays.asList(streamLocs)); }
78
79 // also initializes JOGL
80 final GLCapabilities capsMain = new GLCapabilities(GLProfile.getGL2ES2());
81 capsMain.setNumSamples(4);
82 capsMain.setSampleBuffers(true);
83 capsMain.setBackgroundOpaque(false);
84
85 // screen for layout params ..
88 scrn.addReference();
89
90 final Animator anim = new Animator(0 /* w/o AWT */);
91
92 // Main
93 final GLWindow glWindowMain = GLWindow.create(scrn, capsMain);
94 glWindowMain.setFullscreen(true);
95 setContentView(getWindow(), glWindowMain);
96 anim.add(glWindowMain);
97 glWindowMain.setVisible(true);
98
99 final MovieSimple demoMain = new MovieSimple(null);
100 demoMain.setUseOriginalScale(true);
101 final GLMediaPlayer mPlayer = demoMain.getGLMediaPlayer();
103 @Override
104 public void attributesChanged(final GLMediaPlayer mp, final GLMediaPlayer.EventMask eventMask, final long when) {
105 System.err.println("MovieSimpleActivity0 AttributesChanges: "+eventMask+", when "+when);
106 System.err.println("MovieSimpleActivity0 State: "+mp);
107 if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Init) ) {
108 glWindowMain.addGLEventListener(demoMain);
109 anim.setUpdateFPSFrames(60*5, System.err);
110 anim.resetFPSCounter();
111 }
112 if( eventMask.isSet(GLMediaPlayer.EventMask.Bit.Error) || eventMask.isSet(GLMediaPlayer.EventMask.Bit.EOS) ) {
113 final StreamException se = mPlayer.getStreamException();
114 if( null != se ) {
115 se.printStackTrace();
116 }
117 getActivity().finish();
118 }
119 }
120 });
121 demoMain.playStream(streamLoc, GLMediaPlayer.STREAM_ID_AUTO, GLMediaPlayer.STREAM_ID_AUTO, 0);
122
123 scrn.removeReference();
124
125 Log.d(TAG, "onCreate - X");
126 }
127
128 static Uri getUri(final String path[], final int off, final boolean checkAvail) {
129 Uri uri = null;
130 for(int i=off; null==uri && i<path.length; i++) {
131 if(null != path[i] && path[i].length()>0) {
132 if( checkAvail ) {
133 final URLConnection uc = IOUtil.getResource(path[i], null);
134 if( null != uc ) {
135 try {
136 uri = Uri.valueOf(uc.getURL());
137 } catch (final URISyntaxException e) {
138 uri = null;
139 }
140 if( uc instanceof HttpURLConnection ) {
141 ((HttpURLConnection)uc).disconnect();
142 }
143 }
144 } else {
145 try {
146 uri = Uri.cast(path[i]);
147 } catch (final URISyntaxException e) {
148 uri = null;
149 }
150 }
151 Log.d(TAG, "Stream: <"+path[i]+">: "+(null!=uri));
152 }
153 }
154 return uri;
155 }
156}
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
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.