How to create VR Video player using Google Cardboard SDK for Unity

后端 未结 5 1497
走了就别回头了
走了就别回头了 2020-12-23 08:34

I just downloaded Google Cardboard SDK for unity. I am fine and able to create VR project. Setup is fine and everything is working fine.

I am noob at VR Apps. Just s

5条回答
  •  心在旅途
    2020-12-23 09:18

    I can't help you with Unity, but in java, you can create a texture with OpenGL-ES:

    private static int GL_TEXTURE_EXTERNAL_OES = 0x8D65;
    ....
    GLES20.glGenTextures(1, textureHandle, 0);
    GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, textureHandle[0]);
    

    Use it to create a surface texture and a surface:

    SurfaceTexture surfaceTexture = new SurfaceTexture(textureHandle[0]);
    Surface surface = new Surface(surfaceTexture);
    

    And then pass that surface to android.media.MediaPlayer:

    MediaPlayer mediaPlayer = new MediaPlayer(getContext(), uriToMyMediaFile, surface);
    

    Bind that texture to a square in your scene and call this every frame:

    surfaceTexture.updateTexImage()
    

    and the video will play when you call mediaPlayer.start();

    If Unity allows you to write your own java code to run behind the scenes, this should work if you bind that texture to a surface from Unity.

    If you have a video stream that you can't play with mediaPlayer (like a live video chat, etc), you can use the surface with android.media.MediaCodec as well, but there's a lot more setup work involved.

提交回复
热议问题