Play video on Canvas When Image target found. Vuforia - Unity3d
Asked Answered
M

0

1

I'm trying to Play a video on canvas using the script play video on canvas in an AR app using Vuforia.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;
public class StreamVideo : MonoBehaviour
{
    public RawImage rawImage;
    public VideoPlayer videoPlayer;
    public AudioSource audioSource;
    // Use this for initialization
    void Start()
    {
        StartCoroutine(PlayVideo());
    }
    IEnumerator PlayVideo()
    {
        videoPlayer.Prepare();
        WaitForSeconds waitForSeconds = new WaitForSeconds(1);
        while (!videoPlayer.isPrepared)
        {
            yield return waitForSeconds;
            break;
        }
        rawImage.texture = videoPlayer.texture;
        videoPlayer.Play();
        audioSource.Play();
    }
}

and this plays video when the play button is pressed. Now I hooked this game object to Default trackable event handler so when tracking is found rawimage.gameobject.setactive(true); and (false) when tracking is lost. The main problem here is when I show the camera in front of image target, only a Raw image is being shown and its child Videoplayer is not starting. Which results in Video Not being played. Any fix for this?

Maculate answered 27/8, 2018 at 2:22 Comment(23)
would it maybe be an alternative for you to have the videoplayer "play on load" and just disable/enable the entire gameObject holding the videoPlayer?Bestead
@Bestead but the thing is , if this is the case , the videoplayer component will need a object (target texture ) to play the video ..Maculate
So for that I would do this: Take an empty GameObject, add the components: MeshRenderer, MeshFilter and VideoClip. The VideoClip should now use Material Override using the MeshRenderer. Now for the MeshFilter choose Quad and set its size through the transform Scale (careful it is still in meters). Now create a Material and add it to the MeshRenderer (Materials -> element 0). Now you should have a Video plane that plays onAwake you can enable/disable as GameObjectBestead
No its not working . the empty game object is not visible now . When pressed play , the new game object is not even visible :( .The main reason im playing video on canvas is because , if we use Vuforia's videoplayback with a 3d object , say quad for example , the 3d objects starts shaking in a weird way when image target is found . So i thought if linking it to Canvas so that it stays fixed .Maculate
It always worked for me also as child of a canvas .. unfortunately I can not tell from here what you might have missedBestead
Here is the link of screenshots ibb.co/jgrLhp ibb.co/kuEZ8UMaculate
Did you try to double click it in the hierarchy and look in the Scene View where it is placed? To me it seems very huge and has a big offset ... Is it possible it is simply behind that red overlay?Bestead
no its not behind red overlay , the red screen in play windows is due to my finger . I closed the camera with my finger which made it red . But not its not working . I didnt even hook it up with Defaulttrackableeventhandler script. Its child of canvas and its not hooked up with anything :(Maculate
Can you see it in the Scene view after double click on it?Bestead
give me a mail id or something . Ill record a video of what happens and ill send you .Maculate
This goes against the no personal data policy but you could upload it somewhere and post a link hereBestead
drive.google.com/open?id=19VBebUEgkoRVUxzdaeHUSUsTYpGw9_wNMaculate
I see you didn't apply a material to MeshRenderer -> Materials -> element 0. Just generate a new Material and drag it in thereBestead
here Still no use :(Maculate
sorry this seems to be the same video as before with still no material attached (the video plane is still pink .. should be white)Bestead
My bad . Here is the correct oneMaculate
Oh I think I see it now. In the Canvas settings do you have Screen Space - Overlay or Screen Space - Camera selected? The way I did it appears to only work with Screen Space - Overlay but not with Screen Space CameraBestead
It's in screenspace - Overlay only :( ... btw if we follow this method and attach to default trackable event handler , will it work ?Maculate
sorry the other way round. Screen Space - Camera works for me. Otherwise it might get placed so far way from the camera that it is further than the Clipping Planes -> Far value of the camera ... maybe it also works for you just increasing this valueBestead
I just made an example you can get here (have to import it to any project and open the scene Assets/VideoExample/Examples). You can see there a bit clearer what the ScreenSpace - Overlay does ... it might be better to just switch to ScreenSpace - Camera in generalBestead
Thanks a lot man . It worked like charm even with tracking :)Maculate
Glad to help out. This method might not be the best one to show a video but it always did it for me in the past.Bestead
All that matters is "It works" :) .Maculate

© 2022 - 2024 — McMap. All rights reserved.