background video

Started by arash, January 20, 2014, 07:49:33 AM

Previous topic - Next topic

arash

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


raft

you can use a SurfaceTexture.

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.

arash

#3
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:


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:

class videoTexture implements SurfaceTexture.OnFrameAvailableListener {
@Override
public void onFrameAvailable(SurfaceTexture surfaceTexture) {
updateSurface = true;
mGLView.requestRender();
}
}


and finally in my onDrawFrame method I have:

if (updateSurface) {
                mSurface.updateTexImage();
                updateSurface = false;
            }


I really appreciate your input  :)

raft

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 works fine for me. do the same thing but also call TextureRender.drawFrame in your onDrawFrame method