www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: arash on January 20, 2014, 07:49:33 am

Title: background video
Post by: arash on January 20, 2014, 07:49:33 am
Hi,

I am trying to add a video to my game background. I tried FrameBuffer.blit method and changed the background texture on every frame but this is very slow and maxes out my memory pretty soon.

Is there any other way to display a video on the background?

Cheers
Title: Re: background video
Post by: EgonOlsen on January 20, 2014, 08:23:05 am
Maybe this thread helps: http://www.jpct.net/forum2/index.php/topic,3762.0.html (http://www.jpct.net/forum2/index.php/topic,3762.0.html)?
Title: Re: background video
Post by: raft on January 24, 2014, 03:13:18 pm
you can use a SurfaceTexture (http://developer.android.com/reference/android/graphics/SurfaceTexture.html).

SurfaceTexture can redirect MediaPlayer's output to a GL texture and can display that in GLSurfaceView. jPCT happily draws on top if it without any complains.

this is far more faster than modifying texture manually and uploading to GPU.
Title: Re: background video
Post by: arash on February 20, 2014, 01:03:04 pm
Thanks guys for your replies.

I tried overrideTexelData with ByteBuffer first but could not get very far.

Then I tried SurfaceTexture and managed to get some progress. Now I have Audio playing but the video does not play.

so to test this, as a proof of concept, basically in the onSurfaceCreated of my GLSurfaceView.Renderer I create the media player and surface texture like this:

Code: [Select]
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
int[] texture = new int[1];

        GLES20.glGenTextures(1,texture, 0);
        GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, texture[0]);
        GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
             GL10.GL_TEXTURE_MIN_FILTER,GL10.GL_LINEAR);       
        GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
             GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
    GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
             GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
             GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);

int mTextureID = texture[0];

mSurface = new SurfaceTexture(mTextureID);
mSurface.setOnFrameAvailableListener(new videoTexture());

try {
AssetFileDescriptor afd = getAssets().openFd("test7.mp4");
MediaPlayer player = new MediaPlayer();
    player.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength());
    player.setSurface(new Surface(mSurface));
    player.prepare();
    player.start();
    player.setLooping(true);

} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}

and then I have this class:
Code: [Select]
class videoTexture implements SurfaceTexture.OnFrameAvailableListener {
@Override
public void onFrameAvailable(SurfaceTexture surfaceTexture) {
updateSurface = true;
mGLView.requestRender();
}
}

and finally in my onDrawFrame method I have:
Code: [Select]
if (updateSurface) {
                mSurface.updateTexImage();
                updateSurface = false;
            }

I really appreciate your input  :)
Title: Re: background video
Post by: raft on February 20, 2014, 01:24:40 pm
in your code, i dont see anything to render the contents of SurfaceTexture to screen. you are just updating its content but it's not rendered.

This class (https://android.googlesource.com/platform/cts/+/master/tests/tests/media/src/android/media/cts/TextureRender.java) works fine for me. do the same thing but also call TextureRender.drawFrame in your onDrawFrame method