Log in or register to post comments

Problem to play video instead of display 3d models....

May 9, 2012 - 9:00pm #1

I would like to play a video clip(.mp4) when my Android camera see my image target. I just added a function in TrackableEventHandler.cs to play my video. The question is when AR Camera see image target, the video did play but playing twice, after that, then go back to AR Camera view. Mt expectation is playing video once then go back to AR Camera. Could anyone help me out?

Code:

using UnityEngine;
using System.Collections;

// A custom handler that implements the ITrackableEventHandler interface.
public class TrackableEventHandler : MonoBehaviour,
ITrackableEventHandler
{
#region PRIVATE_MEMBER_VARIABLES

private TrackableBehaviour mTrackableBehaviour;

#endregion // PRIVATE_MEMBER_VARIABLES

#region UNTIY_MONOBEHAVIOUR_METHODS

void Start()
{
mTrackableBehaviour = GetComponent();
if (mTrackableBehaviour)
{
mTrackableBehaviour.RegisterTrackableEventHandler(this);
}

OnTrackingLost();
}

#endregion // UNTIY_MONOBEHAVIOUR_METHODS

#region PUBLIC_METHODS

// Implementation of the ITrackableEventHandler function called when the
// tracking state changes.
public void OnTrackableStateChanged(
TrackableBehaviour.Status previousStatus,
TrackableBehaviour.Status newStatus)
{
if (newStatus == TrackableBehaviour.Status.DETECTED ||
newStatus == TrackableBehaviour.Status.TRACKED)
{
OnTrackingFound();
}
else
{
OnTrackingLost();
}
}

#endregion // PUBLIC_METHODS

#region PRIVATE_METHODS

private void OnTrackingFound()
{
Renderer[] rendererComponents = GetComponentsInChildren();

// Enable rendering:
foreach (Renderer component in rendererComponents) {
component.enabled = true;

}
// Playing my video:
PlayV1();
Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");
}

private void OnTrackingLost()
{
Renderer[] rendererComponents = GetComponentsInChildren();

// Disable rendering:
foreach (Renderer component in rendererComponents) {
component.enabled = false;
}

Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");
}

#endregion // PRIVATE_METHODS

private void PlayV1()
{
iPhoneUtils.PlayMovie("v1.mp4", Color.black, iPhoneMovieControlMode.Full);
Application.LoadLevel(Application.loadedLevel);

}

}

Re: Problem to play video instead of display 3d models....

June 18, 2012 - 5:52am #5

allanjjj, are you playing video full screen or onto a target?

Re: Problem to play video instead of display 3d models....

May 10, 2012 - 6:54pm #4

When the video plays twice, does is play in series? - i.e. the first clip plays entirely and then repeats.

Or is the first video interrupted by the second instance?

Also have you confirmed that OnTrackingFound() is only being called once? - you're not inadvertently losing and then reacquiring a target?

Re: Problem to play video instead of display 3d models....

May 10, 2012 - 6:16pm #3

I have removed "Application.LoadLevel(Application.loadedLevel);", but the video still played twice, that's weird. Can anyone help?

Re: Problem to play video instead of display 3d models....

May 10, 2012 - 10:48am #2

Perhaps it's because you are reloading the level after the video plays?

How many times does the Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found"); message appear?

Log in or register to post comments