How to play 360 video with RajawaliVR or Rajawali


Ma Wenguang

I'm having a hard time figuring out how to play 360 video with Rajawali. To achieve this, I tried every solution I could find on the internet, but failed.

First, I used RajawaliCardboard and then let MainActivity extend from CardboardActivity. Meanwhile, in MyRendererclass, I let this class expand from class RajawaliCardboardRenderer. In the MyRendererclass, I override 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 runs without any errors, but the screen is black with no image.
I would like to ask what should I do to improve the program and why use Rajawali for video playback. who can help me?

Biraj Zalavadia

I successfully 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();
    }
    public void nextVideo(String nextVideoPath){
        try{
            mMediaPlayer.stop();
            mMediaPlayer.reset();

            mMediaPlayer.setDataSource(nextVideoPath);
            mMediaPlayer.prepare();
            mMediaPlayer.start();

      }catch (Exception e){
        e.printStackTrace();
      }
    }
}

Related


How to play 360 video with RajawaliVR or Rajawali

Ma Wenguang I'm having a hard time figuring out how to play 360 video with Rajawali. To achieve this, I tried every solution I could find on the internet, but failed. First, I used RajawaliCardboard and then let MainActivity extend from CardboardActivity. Mean

How to play 360 video with RajawaliVR or Rajawali

Ma Wenguang I'm having a hard time figuring out how to play 360 video with Rajawali. To achieve this, I tried every solution I could find on the internet, but failed. First, I used RajawaliCardboard and then let MainActivity extend from CardboardActivity. Mean

Play 360 Stereoscopic Video with VideoPlayer

Discover I want to play a stereo 360 video in virtual reality in Unity for Android. I've been doing some research so far and I have two cameras for the left and right eyes, each around a sphere. I also need a custom shader to render the image inside the sphere

Play 360 Stereoscopic Video with VideoPlayer

Discover I want to play a stereo 360 video in virtual reality in Unity for Android. I've been doing some research so far and I have two cameras for the left and right eyes, each around a sphere. I also need a custom shader to render the image inside the sphere

Play 360 Stereoscopic Video with VideoPlayer

Discover I want to play a stereo 360 video in virtual reality in Unity for Android. I've been doing some research so far and I have two cameras for the left and right eyes, each around a sphere. I also need a custom shader to render the image inside the sphere

Play 360 Stereoscopic Video with VideoPlayer

Find I want to play a stereo 360 video in virtual reality in Unity for Android. I've been doing some research so far and I have two cameras for the left and right eyes, each around a sphere. I also need a custom shader to render the image inside the sphere. I'

Play 360 Stereoscopic Video with VideoPlayer

Find I want to play a stereo 360 video in virtual reality in Unity for Android. I've been doing some research so far and I have two cameras for the left and right eyes, each around a sphere. I also need a custom shader to render the image inside the sphere. I'

How to change 360 video projection with ffmpeg?

g I want to convert a 360 video from equirectangular projection to cubic projection. How can I do this with ffmpeg? What other effective open source methods are there? Paul B.Mahall Use native FFmpeg v360 filters, which support more features than other solutio

How to change 360 video projection with ffmpeg?

g I want to convert a 360 video from equirectangular projection to cubic projection. How can I do this with ffmpeg? What other effective open source methods are there? Paul B.Mahall Use native FFmpeg v360 filters, which support more features than other solutio

How to change 360 video projection with ffmpeg?

g I want to convert a 360 video from equirectangular projection to cubic projection. How can I do this with ffmpeg? What other effective open source methods are there? Paul B.Mahall Use native FFmpeg v360 filters, which support more features than other solutio

How to change 360 video projection with ffmpeg?

g I want to convert a 360 video from equirectangular projection to cubic projection. How can I do this with ffmpeg? What other effective open source methods are there? Paul B.Mahall Use native FFmpeg v360 filters, which support more features than other solutio

How to change 360 video projection with ffmpeg?

g I want to convert a 360 video from equirectangular projection to cubic projection. How can I do this with ffmpeg? What other effective open source methods are there? Paul B.Mahall Use native FFmpeg v360 filters, which support more features than other solutio

How to enable gyro sensor for Exoplayer 360 video

sow fiber I'm developing a custom Exoplayer based player to play VR videos. SimpleExoPlayerHowever, I was able to create a simplified version where even if I moved my device, the VR player wouldn't rotate as it should. Then I went and tried the Exoplayer demo

How to change 360 video projection with ffmpeg?

g I want to convert a 360 video from equirectangular projection to cubic projection. How can I do this with ffmpeg? What other effective open source methods are there? Paul B.Mahall Use native FFmpeg v360 filters, which support more features than other solutio

How to change 360 video projection with ffmpeg?

g I want to convert a 360 video from equirectangular projection to cubic projection. How can I do this with ffmpeg? What other effective open source methods are there? Paul B.Mahall Use native FFmpeg v360 filters, which support more features than other solutio

How to change 360 video projection with ffmpeg?

g I want to convert a 360 video from equirectangular projection to cubic projection. How can I do this with ffmpeg? What other effective open source methods are there? Paul B.Mahall Use native FFmpeg v360 filters, which support more features than other solutio

How to change 360 video projection with ffmpeg?

g I want to convert a 360 video from equirectangular projection to cubic projection. How can I do this with ffmpeg? What other effective open source methods are there? Paul B.Mahall Use native FFmpeg v360 filters, which support more features than other solutio

How to change 360 video projection with ffmpeg?

g I want to convert a 360 video from equirectangular projection to cubic projection. How can I do this with ffmpeg? What other effective open source methods are there? Paul B.Mahall Use native FFmpeg v360 filters, which support more features than other solutio

How to change 360 video projection with ffmpeg?

g I want to convert a 360 video from equirectangular projection to cubic projection. How can I do this with ffmpeg? What other effective open source methods are there? Paul B.Mahall Use native FFmpeg v360 filters, which support more features than other solutio

How to play 360 MP4 vids?

code Lately, I've been obsessed with 360 videos on YouTube. I want to develop a sample android app that can play 360 video and be able to pan/swipe and be able to use the accelerometer/gyroscope. Some Problems: What file format is a 360 video? Where can I down

How to Play 360 Videos on iOS Devices

Oleg Godiczyk By browsing different websites and analyzing different sources, I found that to play 360 video on iPhone you should use 3-d party lib( ). But I'm interested in how I implement it myself. Because standard iOS elements do not support such functiona

How to Play 360 Videos on iOS Devices

Oleg Godiczyk By browsing different websites and analyzing different sources, I found that to play 360 video on iPhone you should use 3-d party lib( ). But I'm interested in how I implement it myself. Because standard iOS elements do not support such functiona

How to play 360 MP4 vids?

code Lately, I've been obsessed with 360 videos on YouTube. I want to develop a sample android app that can play 360 video and can pan/swipe and can use accelerometer/gyroscope. Some Problems: What file format is a 360 video? Where can I download sample 360 vi

How to play 360 MP4 vids?

code Lately, I've been obsessed with 360 videos on YouTube. I want to develop a sample android app that can play 360 video and be able to pan/swipe and be able to use the accelerometer/gyroscope. Some Problems: What file format is a 360 video? Where can I down

How to play 360 MP4 vids?

code Lately, I've been obsessed with 360 videos on YouTube. I want to develop a sample android app that can play 360 video and be able to pan/swipe and be able to use the accelerometer/gyroscope. Some Problems: What file format is a 360 video? Where can I down

How to play 360 MP4 vids?

code Lately, I've been obsessed with 360 videos on YouTube. I want to develop a sample android app that can play 360 video and be able to pan/swipe and be able to use the accelerometer/gyroscope. Some Problems: What file format is a 360 video? Where can I down

How to Play 360 Videos on iOS Devices

Oleg Godiczyk By browsing different websites and analyzing different sources, I found that to play 360 video on iPhone you should use 3-d party lib( ). But I'm interested in how I implement it myself. Because standard iOS elements do not support such functiona

How to play 360 MP4 vids?

code Lately, I've been obsessed with 360 videos on YouTube. I want to develop a sample android app that can play 360 video and be able to pan/swipe and be able to use the accelerometer/gyroscope. some questions: What file format is a 360 video? Where can I dow

How to play 360 MP4 vids?

code Lately, I've been obsessed with 360 videos on YouTube. I want to develop a sample android app that can play 360 video and be able to pan/swipe and be able to use the accelerometer/gyroscope. some questions: What file format is a 360 video? Where can I dow