2015-09-04 18 views
6

Tôi là người mới trong lĩnh vực này. Tôi đang cố gắng thay đổi program trong github để phát video cho các tông ngay bây giờ.Cách tạo trình phát video VR đơn giản bằng Google SDK Android SDK và Rajawali

Tôi đã sửa đổi MyRenderer bằng cách sử dụng StreamingTexture.

public class MyRenderer extends RajawaliCardboardRenderer { 

public MyRenderer(Context context) { 
    super(context); 
} 

private MediaPlayer mMediaPlayer; 
private StreamingTexture streamingTexture; 

@Override 
protected void initScene() { 
    mMediaPlayer = MediaPlayer.create(this.getContext(), R.raw.test); 

    streamingTexture = new StreamingTexture("video", mMediaPlayer); 
    Sphere sphere = createPhotoSphereWithTexture(streamingTexture); 

    getCurrentScene().addChild(sphere); 

    getCurrentCamera().setPosition(Vector3.ZERO); 
    getCurrentCamera().setFieldOfView(75); 
} 

private static 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; 
} 
} 

Tôi đã lưu video ngắn dưới dạng test.mp4 trong thư mục thô, tuy nhiên, sau khi tôi bắt đầu ứng dụng, hai bên trống và âm thanh của video thực sự đang phát.

Tôi cần trợ giúp. Cảm ơn nhiều!

+0

bạn có thể thử trả lời của tôi http: // stackoverflow.com/questions/32391282/how-to-use-rajawalivr-or-rajawali-to-play-a-360-video –

Trả lời

5

Tôi nhận được video 360 có tính năng theo dõi đầu trong bảng điều khiển hoạt động như thế này.

Mở rộng lớp học của bạn bằng RajawaliVRRenderer

sử dụng tiếp theo initScene sau():

@Override 
public void initScene() { 

    // setup sphere 
    Sphere sphere = new Sphere(1, 100, 100); 
    sphere.setPosition(0, 0, 0); 
    // invert the sphere normals 
    // factor "1" is two small and result in rendering glitches 
    sphere.setScaleX(100); 
    sphere.setScaleY(100); 
    sphere.setScaleZ(-100); 

    //initiate MediaPlayer 
    mediaPlayer = new MediaPlayer(); 
    mediaPlayer.setLooping(true); 
    try { 
     Uri videoUrl = Uri.parse("android.resource://" + getContext().getPackageName() + "/" 
       + R.raw.test); 
     mediaPlayer.setDataSource(getContext(),Uri.parse(videoUrl)); 
     mediaPlayer.prepareAsync(); //prepare the player (asynchronous) 
     mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { 
      @Override 
      public void onPrepared(MediaPlayer mp) { 
       mp.start(); //start the player only when it is prepared 
      } 
     }); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

    // create texture from media player video 
    videoTexture = new StreamingTexture("video", mediaPlayer); 

    // set material with video texture 
    Material material = new Material(); 
    material.setColorInfluence(0f); 
    try { 
     material.addTexture(videoTexture); 
    } catch (ATexture.TextureException e){ 
     throw new RuntimeException(e); 
    } 
    sphere.setMaterial(material); 

    // add sphere to scene 
    getCurrentScene().addChild(sphere); 

    super.initScene(); 
} 

Sau khi bắt đầu cảnh mà bạn muốn cập nhật videoTexture trên mỗi render, nên thêm:

@Override 
public void onRender(long elapsedRealTime, double deltaTime) { 
    super.onRender(elapsedRealTime, deltaTime); 

    if (videoTexture != null) { 
     // update texture from video content 
     videoTexture.update(); 
    } 
} 

Và cuối cùng nhưng không kém phần quan trọng bạn muốn cập nhật ra để theo dõi phong trào cho các tông như thế này:

@Override 
public void onDrawEye(Eye eye) { 
    // Rajawali camera 
    org.rajawali3d.cameras.Camera currentCamera = getCurrentCamera(); 

    // cardboard field of view 
    FieldOfView fov = eye.getFov(); 

    // update Rajawali camera from cardboard sdk 
    currentCamera.updatePerspective(fov.getLeft(), fov.getRight(), fov.getBottom(), fov.getTop()); 
    eyeMatrix.setAll(eye.getEyeView()); 
    // orientation 
    eyeOrientation.fromMatrix(eyeMatrix); 
    currentCamera.setOrientation(eyeOrientation); 
    // position 
    eyePosition = eyeMatrix.getTranslation().inverse(); 
    currentCamera.setPosition(eyePosition); 

    // render with Rajawali 
    super.onRenderFrame(null); 
} 

Ngoài ra, để vượt qua một số thính giả khác mong muốn các carboard SDK, bạn sẽ cần những chức năng:

@Override 
public void onSurfaceChanged(int width, int height) { 
    // tell Rajawali that cardboard sdk detected a size change 
    super.onRenderSurfaceSizeChanged(null, width, height); 
} 

@Override 
public void onSurfaceCreated(EGLConfig eglConfig) { 
    // pass opengl config to Rajawali 
    super.onRenderSurfaceCreated(eglConfig, null, -1, -1); 
} 

@Override 
public void onRenderSurfaceDestroyed(SurfaceTexture surface) { 
    super.onRenderSurfaceDestroyed(surface); 
} 
+0

Cảm ơn bạn rất nhiều! Bạn đã thể hiện một giải pháp chi tiết như vậy. Tôi đã thực hiện nó với [link] (http://stackoverflow.com/questions/32391282/how-to-use-rajawalivr-or-rajawali-to-play-a-360-video) trước đây. Câu trả lời của bạn cũng rất hữu ích cho tôi. – Dobbie

Các vấn đề liên quan