How to create VR Video player using Google Cardboard SDK for Unity
Asked Answered
J

5

9

I just downloaded Google Cardboard SDK for unity. I am fine and able to create VR project. Setup is fine and everything is working fine.

I am noob at VR Apps. Just stepped in VR Apps.

I am planing to create my own VR Enabled Video Player for android, Just like the default Google Cardboard Youtube player.

Can any one suggest me a link or can guide me in developing this app.

Jennyjeno answered 16/5, 2015 at 16:10 Comment(1)
@All, i am trying to buy EasyMoviePlayer plugin from Unity asset store @ assetstore.unity3d.com/en/#!/content/10032. Can any one suggests if this is fine.Jennyjeno
B
11

Scott Driscoll's answer totally works. I had some initial problems getting the Easy Movie Texture Unity plug-in to work for me, but finally figured it out, and it works flawlessly. I now have 360-video running as a texture on the inside of a sphere on my iPhone 6. And I have to say, I didn't think it would happen.

For working on a Mac, here's what I did:

  1. Download the Easy Movie Texture plug-in from the Unity Asset Store
  2. Open the Demo Sphere demo scene from Assets/EasyMovieTexture/Scene
  3. Create a new (empty) Prefab to your project, and drag the Sphere GameObject from the Demo Sphere scene onto the Prefab.
  4. Reopen your Cardboard scene and drag the new videosphere prefab into your hierarchy.
  5. Open your source 360-video in Quicktime
  6. File -> Export -> 720p
  7. Change file extension from '.mov' to '.mp4'
  8. Drag your new mp4 file into your projects Assets/Streaming Assets directory. Note: don't import through the menu system, as this will force Unity to convert to OGG.
  9. On the "Media Player Ctrl" script component of your videosphere GameObject, locate the "Str_File_Name" field and provide the FULL filename. Make sure to include the extension as part of the string, "mymovie.mp4".

Pretty sure that's everything. Hope it helps other folks stuck on this problem. Thanks Scott Driscoll!

One last note, you can only view the video on the phone, not in preview in the editor. It would be better if it didn't work this way, but really once the initial issues of resolution and placement are resolved, I don't really need to see the video every time I run the scene in the editor.

Barbee answered 8/9, 2015 at 23:47 Comment(1)
how to pass data dynamically using intent ?Dwarf
H
8

Here are the major steps for how we do this:

  1. Add a sphere with an equirectangular UV mapping and inward facing normals around the camera.
  2. Purchase a plugin to play a movie on that sphere’s texture. I recommend Easy Movie Texture.
  3. Use mp4s or ogg vorbis files that are compatible with the platform. This is phone and OS dependent.

Full details: http://immersivetechblog.foundry45.com/2015/07/31/implementing-360-video-in-unity-for-gear-vr-and-cardboard/

Hertfordshire answered 1/9, 2015 at 21:45 Comment(2)
This looks promising, but the documentation for Easy Movie Texture is pretty unclear and Android-specific. How do I actually attach the video to the sphere? For Oculus I just attached as a texture, but here it looks like I use the Video Manager prefab somehow?Barbee
I made a prefab from the video sphere in the video sphere demo scene. Video is referenced as a string on str_file_name field of the video sphere’s Media Player Ctrl script. The video needs to be an mp4 file (not OGG) in the Streaming Assets directory. But, I still just see a white sphere when I run the app using one my own videos. As soon as I switch back to the example video I’m fine. I’m thinking the issue is with the dimensions of my video, which is a 360 video, not a rectilinear video as is the example video. The 360 video I’m trying to run is 3906 x 1952. Any thoughts?Barbee
O
3

I saw the answers above but all of them either required Easy Movie Texture Unity plug-in or coding your way through.. There's another easy solution to this as well which won't require you to buy that asset or code your way through.. Oculus provides an already built free sample framework which you can use without much trouble.. The solution below shows both how to create both a photo viewer as well as video viewer for Unity..

Building your 360 degree PhotoViewer:

  1. Go to Blender and delete all the prexisitng objects (if any) and make an icosphere and increase the subdivisions to a point where it looks more like a sphere like 6 and hit Generate UVs (both these options are found in settings underneath the create tab in add to sphere) and go to edit and choose Flip Normals so that you can see inside out rather than outside inwards and save it.
  2. Bring that icosphere saved file into your assets folder in Unity.
  3. Download GoogleVR SDK and bring GoogleVR plugin into your assets folder as well.. (You can download it here: https://developers.google.com/vr/unity/)
  4. Delete the main camera and directional light present in default.
  5. Bring your icosphere asset into your project.
  6. Bring GVR Main from your assets folder into your project: GoogleVR plugin -> Legacy -> Prefab -> GVR Main
  7. Take any panaroma or 360 photo and bring it in your assets folder.
  8. Take this photo in your asset folder and put it above the icosphere in your scene and hit play. You should be able to see your 360 degree photos.

Building your 360 degree MoviePlayer:

  1. Step 1 same.
  2. Now go to the Oculus developer console and download this file and bring this to your assets folder. https://developer3.oculus.com/downloads/game-engines/1.5.0/Oculus_Sample_Framework_for_Unity_5_Project/
  3. Bring this file you downloaded above to your assets folder.
  4. Find MoviePlayer in your assetsFolder in bring it in your project.
  5. Bring the icosphere you downloaded into your assets folder as well and scale it a little bit so you can see correctly.
  6. Copy the MoviePlayer sample script and Audio Source in the components of the MovieSurface from the project and add it in the components of the sphere in the scene, also get rid of the animator in the components of the sphere.
  7. Bring the Movie Player material found in the Materials under Mesh Renderer in MovieSurface and add it on top of your sphere.
  8. Now this sphere formed is your 360 degree movie player so store it as an asset in the asset folder.
  9. Create a new scene, delete the directional light and bring your saved icosphere asset into this scene and move the main camera at the centre.
  10. Delete the non required assets to clean up some space in your project other than MoviePlayer, Plugins and Streaming Assets.
  11. You'll have to convert the desired mp4 into an ogv file as well for the plugin to play in VR and bring both the mp4 and ogv files into your streaming assets folder and change the MovieName and click Play. You should be able to see your 360 degree video playing.

*To play it in your devices, just go to build settings and choose the desired platform and delete all the scene and just Add Open Scene and click on the Virtual Reality Supported in Other Settings under Player Settings. To play it in your android phone you need to download the GoogleVR SDK just like above and bring it in your assets folder and find the GVRViewerMain in the assets folder and bring it in the scene and uncheck the Virtual Reality Supported you did above and just build and run the whole thing in your device (You should be able to see the view in you game mode when you hit play in Unity). You should be able to see the video in your respective gear.

  • There's also a video tutorial available but I'm only able to share only 2 links with my new StackOverFlow profile.
Offence answered 16/1, 2017 at 13:58 Comment(1)
can you please share video link in comment ... I am having difficulty following you steps as I am new to unity ... ThanksTawnyatawsha
O
1

I can't help you with Unity, but in java, you can create a texture with OpenGL-ES:

private static int GL_TEXTURE_EXTERNAL_OES = 0x8D65;
....
GLES20.glGenTextures(1, textureHandle, 0);
GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, textureHandle[0]);

Use it to create a surface texture and a surface:

SurfaceTexture surfaceTexture = new SurfaceTexture(textureHandle[0]);
Surface surface = new Surface(surfaceTexture);

And then pass that surface to android.media.MediaPlayer:

MediaPlayer mediaPlayer = new MediaPlayer(getContext(), uriToMyMediaFile, surface);

Bind that texture to a square in your scene and call this every frame:

surfaceTexture.updateTexImage()

and the video will play when you call mediaPlayer.start();

If Unity allows you to write your own java code to run behind the scenes, this should work if you bind that texture to a surface from Unity.

If you have a video stream that you can't play with mediaPlayer (like a live video chat, etc), you can use the surface with android.media.MediaCodec as well, but there's a lot more setup work involved.

Openair answered 22/5, 2015 at 20:42 Comment(6)
Thax Mog, In Unity we can write code in C#, Java and boo. i will chk and let you know my result if you suggestion work for me.Jennyjeno
@Mog, I have a try according to your steps, but my app always shows a black screen, I don't know where I was made the wrong :(, do you have a sample for this? Thanks a lot~Grindle
some my codes is at here: evernote.com/shard/s211/sh/ecb4fb7a-7ca7-49ea-aa5f-52bc75ffd4d8/…Grindle
If you download the Oculus Mobile SDK for GearVR, the CinemaSDK example in there plays movies from the phone on a virtual screen. You'd need a Note 4 or S6 to run it, but you can look at the code and see what they're doing: developer.oculus.com/downloads/#version=mobile-0.6.0Openair
Hi Mog, do you have any sample code snippet based on the code below? I downloaded the sample project from CardBoard google website, but have no idea how should I change the code to add a surface view.thanksJourdain
Anyone have any luck with this? I followed these steps but I get "ERROR: java.lang.IllegalStateException: Unable to update texture contents (see logcat for details)" I'm passing the texture ID from Unity's Texture.GetNativeTexturePtr() into the SurfaceTexture constructor. Should I not be using the same texture ID in each?Bizerte
O
1

This has become very simple for Unity 5.6 and above.

  1. You just need a sphere with its normals inverted which you can either find online or just go to blender and make an IcoSphere and flip its normals or you can use a shader to do the same on a normal sphere. In either case use an Unlit texture for the shader.
  2. Add a Video Player in the component which comes default with Unity to this sphere.
  3. Add any 360 degree video to this Video Player. You can also add an online link as well. And it plays consistently well throughout the range of platforms from GoogleVR to SteamVR.

The only downside is, it only plays monoscopic images/videos by default and there requires some tweaking to run stereoscopic images/videos.

Offence answered 4/7, 2017 at 17:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.