使用Google Cardboard制作VR视频播放器

时间:2016-01-06 09:37:00

标签: google-cardboard rajawalivr

如何使用Google CardBoard Android SDK制作简单的VR视频播放器?我是这个领域的新人。我正在尝试更改github中的程序,以便现在播放纸板视频!

1 个答案:

答案 0 :(得分:1)

我以这种方式使用Rajawali Library以及Google Cardboard Sdk和Modified initscene()来完成这项工作。

public class VideoRenderer extends RajawaliCardboardRenderer {

Context mContext;

private MediaPlayer mMediaPlayer;
private StreamingTexture mVideoTexture;

public VideoRenderer(Context context) {
    super(context);
    mContext = context;
}

@Override
protected void initScene() {

    mMediaPlayer = MediaPlayer.create(getContext(),
            R.raw.video);
    mMediaPlayer.setLooping(true);

    mVideoTexture = new StreamingTexture("sintelTrailer", mMediaPlayer);
    Material material = new Material();
    material.setColorInfluence(0);
    try {
        material.addTexture(mVideoTexture);
    } catch (ATexture.TextureException e) {
        e.printStackTrace();
    }

    Sphere sphere = new Sphere(50, 64, 32);
    sphere.setScaleX(-1);
    sphere.setMaterial(material);

    getCurrentScene().addChild(sphere);

    getCurrentCamera().setPosition(Vector3.ZERO);

    getCurrentCamera().setFieldOfView(75);

    mMediaPlayer.start();

}

@Override
protected void onRender(long ellapsedRealtime, double deltaTime) {
    super.onRender(ellapsedRealtime, deltaTime);
    mVideoTexture.update();
}

@Override
public void onPause() {
    super.onPause();
    if (mMediaPlayer != null)
        mMediaPlayer.pause();
}

@Override
public void onResume() {
    super.onResume();
    if (mMediaPlayer != null)
        mMediaPlayer.start();
}

@Override
public void onRenderSurfaceDestroyed(SurfaceTexture surfaceTexture) {
    super.onRenderSurfaceDestroyed(surfaceTexture);
    mMediaPlayer.stop();
    mMediaPlayer.release();
}
 }