I would like to get this working with the OpenGL example code from the
NeHe Android Ports, but when I try to access the timecode from the
MediaPlayer within onDrawFrame, it gives the error:

  "mp cannot be resolved"

I tried putting the MediaPlayer.create line in Lesson06.java but it
gives the error:

  "The method create(Context, int) in the type MediaPlayer is not
applicable for the arguments (Lesson06, int)"

The music plays fine when the MediaPlayer.create is in Run.java, but
the question is what's the easiest way to getCurrentPosition from
within onDrawFrame in the following code?


package com.nea.nehe.lesson06;

import android.app.Activity;
import android.media.MediaPlayer;
import android.opengl.GLSurfaceView;
import android.os.Bundle;

/**
 * The initial Android Activity, setting and initiating
 * the OpenGL ES Renderer Class @see Lesson06.java
 *
 * @author Savas Ziplies (nea/INsanityDesign)
 */
public class Run extends Activity {

        MediaPlayer mp;

    /** The OpenGL View */
        private GLSurfaceView glSurface;

        /**
         * Initiate the OpenGL View and set our own
         * Renderer (@see Lesson06.java)
         */
        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);

                mp = MediaPlayer.create(this, R.raw.yang13bs);

                //Create an Instance with this Activity
                glSurface = new GLSurfaceView(this);
                //Set our own Renderer and hand the renderer this Activity 
Context
                glSurface.setRenderer(new Lesson06(this, mp));
                //Set the GLSurface as View to this Activity
                setContentView(glSurface);
        }

        /**
         * Remember to resume the glSurface
         */
        @Override
        protected void onResume() {
                super.onResume();
                glSurface.onResume();
        }

        /**
         * Also pause the glSurface
         */
        @Override
        protected void onPause() {
                super.onPause();

                mp.stop();

                glSurface.onPause();
        }

}

--------------------------------------------------------------------------------

package com.nea.nehe.lesson06;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.content.Context;
import android.media.MediaPlayer;
import android.opengl.GLU;
import android.opengl.GLSurfaceView.Renderer;

/**
 * This is a port of the {@link http://nehe.gamedev.net} OpenGL
 * tutorials to the Android 1.5 OpenGL ES platform. Thanks to
 * NeHe and all contributors for their great tutorials and great
 * documentation. This source should be used together with the
 * textual explanations made at {@link http://nehe.gamedev.net}.
 * The code is based on the original Visual C++ code with all
 * comments made. It has been altered and extended to meet the
 * Android requirements. The Java code has according comments.
 *
 * If you use this code or find it helpful, please visit and send
 * a shout to the author under {@link http://www.insanitydesign.com/}
 *
 * @DISCLAIMER
 * This source and the whole package comes without warranty. It may or
may
 * not harm your computer or cell phone. Please use with care. Any
damage
 * cannot be related back to the author. The source has been tested on
a
 * virtual environment and scanned for viruses and has passed all
tests.
 *
 *
 * This is an interpretation of "Lesson 06: Texture Mapping"
 * for the Google Android platform.
 *
 * @author Savas Ziplies (nea/INsanityDesign)
 */
public class Lesson06 implements Renderer {

        /** Cube instance */
        private Cube cube;

        /* Rotation values for all axis */
        private float xrot;                             //X Rotation ( NEW )
        private float yrot;                             //Y Rotation ( NEW )
        private float zrot;                             //Z Rotation ( NEW )

        private long mPos;

        /** The Activity Context ( NEW ) */
        private Context context;

        /**
         * Instance the Cube object and set
         * the Activity Context handed over
         */
        public Lesson06(Context context, MediaPlayer mp) {
                this.context = context;

                cube = new Cube();

                mp.start();
        }

        /**
         * The Surface is created/init()
         */
        public void onSurfaceCreated(GL10 gl, EGLConfig config) {
                //Load the texture for the cube once during Surface creation
                cube.loadGLTexture(gl, this.context);

                gl.glEnable(GL10.GL_TEXTURE_2D);                        
//Enable Texture Mapping ( NEW )
                gl.glShadeModel(GL10.GL_SMOOTH);                        
//Enable Smooth Shading
                gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);        //Black 
Background
                gl.glClearDepthf(1.0f);                                         
//Depth Buffer Setup
                gl.glEnable(GL10.GL_DEPTH_TEST);                        
//Enables Depth Testing
                gl.glDepthFunc(GL10.GL_LEQUAL);                         //The 
Type Of Depth Testing To Do

                //Really Nice Perspective Calculations
                gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
        }

        /**
         * Here we do our drawing
         */
        public void onDrawFrame(GL10 gl) {
                //Clear Screen And Depth Buffer
                gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
                gl.glLoadIdentity();                                    //Reset 
The Current Modelview Matrix

                //Drawing
                gl.glTranslatef(0.0f, 0.0f, -5.0f);             //Move 5 units 
into the screen
                gl.glScalef(0.8f, 0.8f, 0.8f);                  //Scale the 
Cube to 80 percent,
otherwise it would be too large for the screen

                //Rotate around the axis based on the rotation matrix 
(rotation, x,
y, z)
                gl.glRotatef(xrot, 1.0f, 0.0f, 0.0f);   //X
                gl.glRotatef(yrot, 0.0f, 1.0f, 0.0f);   //Y
                gl.glRotatef(zrot, 0.0f, 0.0f, 1.0f);   //Z

                cube.draw(gl);                                                  
//Draw the Cube

                //Change rotation factors (nice rotation)
                xrot += 0.3f;
                yrot += 0.2f;
                zrot += 0.4f;

                mPos = mp.getCurrentPosition();
        }

        /**
         * If the surface changes, reset the view
         */
        public void onSurfaceChanged(GL10 gl, int width, int height) {
                if(height == 0) {                                               
//Prevent A Divide By Zero By
                        height = 1;                                             
//Making Height Equal One
                }

                gl.glViewport(0, 0, width, height);     //Reset The Current 
Viewport
                gl.glMatrixMode(GL10.GL_PROJECTION);    //Select The Projection 
Matrix
                gl.glLoadIdentity();                                    //Reset 
The Projection Matrix

                //Calculate The Aspect Ratio Of The Window
                GLU.gluPerspective(gl, 45.0f, (float)width / (float)height, 
0.1f,
100.0f);

                gl.glMatrixMode(GL10.GL_MODELVIEW);     //Select The Modelview 
Matrix
                gl.glLoadIdentity();                                    //Reset 
The Modelview Matrix
        }
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to