如何使用RajawaliVR或拉贾瓦利发挥360视频 [英] How to use RajawaliVR or Rajawali to play a 360 Video
问题描述
我有一个很难弄清楚如何使用拉贾瓦利播放360视频。为了做到这一点,我想每一个解决方案,我可以找到在互联网上,但我失败了。
I am having a hard time to figure out how to use the Rajawali to play a 360 video. In order to achieve this, I tried every solution I could find in the Internet, but I failed.
首先,我用了RajawaliCardboard,并让MainActivity从 CardboardActivity
延伸。与此同时,在 MyRenderer
类,我让这个类从 RajawaliCardboardRenderer
类扩展。在 MyRenderer
类,我overrided的 initScene()
功能:
Firstly, I used the RajawaliCardboard, and let the MainActivity extend from CardboardActivity
. At the same time, in MyRenderer
class, I let this class extend from the RajawaliCardboardRenderer
class. In MyRenderer
class, I overrided the initScene()
function:
protected void initScene() {
StreamingTexture mTexture = null;
if (externalMemoryAvailable())
{
mVideoPath = Environment.getExternalStorageDirectory().getAbsolutePath()+"/testVideo.mp4";
try{
mPlayer = new MediaPlayer();
mPlayer.setDataSource(mVideoPath);
}catch(IllegalArgumentException e){
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
mPlayer.prepare();
} catch (IOException t) {
t.printStackTrace();
}
mTexture = new StreamingTexture("video", mPlayer);
}
Sphere sphere = createPhotoSphereWithTexture(mTexture);
getCurrentScene().addChild(sphere);
getCurrentCamera().setPosition(Vector3.ZERO);
getCurrentCamera().setFieldOfView(75);
}
private Sphere createPhotoSphereWithTexture(ATexture texture) {
Material material = new Material();
material.setColor(0);
try {
material.addTexture(texture);
} catch (ATexture.TextureException e) {
throw new RuntimeException(e);
}
Sphere sphere = new Sphere(50, 64, 32);
sphere.setScaleX(-1);
sphere.setMaterial(material);
return sphere;
}
该程序可以运行,没有任何错误,但屏幕是黑的,没有任何图像。
我想请问我应该怎么做才能提高我的程序,为什么我应该做的使用拉贾瓦利播放视频。谁可以帮我?
The program can run without any error, but the screen is black and with no image.
I want to ask what should I do to improve my program, and why I should do to play video by using Rajawali. Who can help me?
推荐答案
我的成功与拉贾瓦利播放视频。
I got success to play video with Rajawali.
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();
}
}
这篇关于如何使用RajawaliVR或拉贾瓦利发挥360视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!