IrfanZ
IrfanZ

Reputation: 55

Problems with playing videos ARCore

I followed the example code listed on the AugmentedImageController for ARCore unity on github at: https://github.com/google-ar/arcore-unity-sdk/blob/master/Assets/GoogleARCore/Examples/AugmentedImage/Scripts/AugmentedImageExampleController.cs. Even after I've followed the code on this example, it doesn't play the video from the video player as shown on the AugmentedImageVisualizer code below:

The video plays if I drag and drop the AugmentedImageVirtulizer onto the scene and put playOnAwake. However it doesn't play when I take the playOnAwake off, send the app to my phone, and then point the camera to the augmented image (in my case a empty milk bottle label). I want an object such as a ghost to appear coming out of the milk bottle.

    using GoogleARCore;
    using UnityEngine;
    using UnityEngine.Video;

    public class AugmentedImageVisualizer : MonoBehaviour {

    private VideoPlayer vidPlayer;
    public VideoClip[] vidClips;
    public AugmentedImage Image;

// Use this for initialization
void Start () {
    vidPlayer = GetComponent<VideoPlayer>();
    vidPlayer.loopPointReached += OnStop;

}

   private void OnStop(VideoPlayer source)
   {
      gameObject.SetActive(false);
   }

   // Update is called once per frame
   void Update () {

    if (Image == null || Image.TrackingState != TrackingState.Tracking)
    {
        return;
    }

    if (!vidPlayer.isPlaying)
    {
        vidPlayer.clip = vidClips[Image.DatabaseIndex];
        vidPlayer.Play();
    }

    transform.localScale = new Vector3(Image.ExtentX, Image.ExtentZ, 
    1f);

  }
      }

no console errors showing, but no videos showing

Upvotes: 1

Views: 796

Answers (2)

Zeghra
Zeghra

Reputation: 477

EDIT: I had to edit answer to give more explanation: I used the examples of augmented image that comes with GoogleARCore to create the AR. Here the controller needs an augmented image visualizer prefab. This prefab is a Quad (right click on hierarchy area, then 3D Object > Quad) and moved it to prefab folder (this creates prefab from quad). This quad/prefab has a videoplayer (added in inspector). This quad(prefab) also has a script (augmentedimagevisualizer) which contains your code snippet. So in the inspector (with augmentedimagevisualizer script) the quad already has videoclips where you can set your videos. In hierarchy, there is an arcore device and inside is the camera. This camera has Tracked Pose Driver (set it in inspector) with Pose source: Color Camera and AR Core Background Renderer script. The 2. videolink makes the same and contains your code as well, so this video is very descriptive regarding your question. I found 2 similar video on youtube.

  1. that shows 1 video: https://www.youtube.com/watch?v=yjj5dV2v9Fs
  2. that shows multiple videos on multiple ref. images: https://www.youtube.com/watch?v=GkzMFNmvums

The 2. was tricky for me, the guy in video created quad that he renamed to AugmentedImageVisualizer and then he placed it in Prefabs. Since I've realized this my videos appear on ref. images. I used Unity 2019.3.15 and arcore-unity-sdk-1.17.0.unitypackage

Upvotes: 0

P&#233;ter Kov&#225;cs
P&#233;ter Kov&#225;cs

Reputation: 204

Be sure that your camera's position is in the origo. Is your videoplayer active? (videoplayer.setactive(true))

My working solution:

public class AugmentedImageVisualizer : MonoBehaviour
{
    private const string TAG = "AugmentedImageVisualizer";
    public AugmentedImage image;

    public GameObject video;
    public VideoClip[] videoClips;

    private VideoPlayer videoPlayer;

    private void Start() {
        videoPlayer = video.GetComponent<VideoPlayer>();
    }

    private void Update() {
        if (Session.Status != SessionStatus.Tracking) return;

        if (image == null || image.TrackingState != TrackingState.Tracking) {
            videoplayer.SetActive(false);
            return;
        }

        UpdateVideo();

    private void UpdateVideo() {
        if (!videoPlayer.isPlaying) {
            videoPlayer.clip = videoClips[image.DatabaseIndex];
            videoPlayer.Play();
            video.SetActive(true);
        }

        transform.localScale = new Vector3(image.ExtentX, 1, image.ExtentZ);
    }
}

Don't forget to add videoplayer component to your gameobject.

Upvotes: 0

Related Questions