Search code examples
androidvideoandroid-intentyoutubegoogle-cardboard

Play Youtube Video in Cardboard mode


I'm developing a cardboard app. In my app I want to play a 360 youtube video, I want it to go straight to VR mode so the user doesn't have to remove their headset.

I don't mind whether this video is embedded in my app or opens the youtube app, but I need it go directly into VR mode with no non-VR interaction.

I've looked into doing the following:

  • streaming the video onto a surfaceTexture and using this to render stereoscoptically: not Possible
  • Launching the youtube app in cardboard mode: Not Possible
  • Using the YoutubePlayerView/Fragment/standalonePlayer : None expose functions to enable cardboard mode.

Is this possible?


Solution

  • I ended up using DASH with exoplayer.

    I grabbed the direct url like so:

            String GET_VIDEO_INFO_URL = "http://www.youtube.com/get_video_info";
            Bundle params = new Bundle();
            params.putString("video_id", info.getId());
    
            UrlUtils.HttpURLRequest request = new UrlUtils.HttpURLRequest(GET_VIDEO_INFO_URL, "GET", params);
            String response = request.execute();
            if(response != null) {
                Bundle urlParams = UrlUtils.decodeUrl(response);
                String manifest_url = urlParams.getString("dashmpd", null);
                info.setPath(manifest_url);
            }
    

    Then I use exoplayer to render the dash stream to a texture as explained here.