Log in or register to post comments

Unity video playback with cloud recognition

December 12, 2013 - 9:17pm #1

Hi,

Is there any reference code available for integrating cloud recognition service to the video playback.

Which will be the right step to start:

> Adding cloud service to the video playback sample?

> Adding video playback to the cloud recognition sample?

Thanks,

BP

Unity video playback with cloud recognition

July 27, 2017 - 4:07am #28

Hi guys,

currently, im working with my last project in college

I create app base on Android, I really consuse how to combine Video Playback + Cloud AR ?

I've tried steps from this thread but not work for me, can you guys help me, is there a more spesific tutorial ?

please I have 4 days again until my final exam, any reference unity project sample ? or else ?

thanks.

Unity video playback with cloud recognition

May 14, 2017 - 8:45am #27

Guys i'm using unity 5.5, i can't find cloudrecohandler so I've created cloud handler and attached to cloudrecogn i'm getting errors while compiling not able to resolve please help me!

Unity video playback with cloud recognition

November 22, 2016 - 10:15pm #26

Hi. I just follow your steps, and packaged the apk, But it also can not play the video(local or remote url) ...  Please help~~~~

 

Unity video playback with cloud recognition

October 31, 2016 - 6:56am #25

Hi everyone, I got the solution for who might using vuforia 6.x with unity 5.3x.

it took me about a week to study n finally it works for me by follow Mr fathahnoor's provided script.

in which u have to amend some of the codes by the following:

1.in order to use Json to call the metadata from the cloud markers, you need to download (for me) Newtonsoft.json.dll into your Plugins folder by the link:

http://www.newtonsoft.com/json. (cause i really can't find any Json.dll on web) - "NET 20"

n (for Android) change the Api Compatibility Level to .NET2.0 (under Player Setting), else will be error to build / play.

* import package of vuforia sample6-0-12 (content Cloud Reco) n videoPlayback sample in which i amend the scene "Vuforia-3-CloudReco".

2.edit CloudRecoEventHandle.cs by amended the codes as fathahnoor was stated.

Due to the different .dll is applying, i change the script to:

//not using Json;

using Newtonsoft.Json;

using Newtonsoft.Json.Linq;

 

......

public void OnNewSearchResult(TargetFinder.TargetSearchResult targetSearchResult)

    {

       

  if(targetSearchResult.MetaData == null)

  {

   return;

  }

  else

  {

//no neccesory to apply SerializeObject here...

   string output = JsonConvert.SerializeObject (targetSearchResult.MetaData);

  



   JObject dict = JsonConvert.DeserializeObject<JObject> (targetSearchResult.MetaData);

   Debug.Log("We got a target metadata: " + dict["title"]);

   VideoPlaybackBehaviour video = ImageTargetTemplate.gameObject.GetComponentInChildren<VideoPlaybackBehaviour>();

   if(video != null)

   {

    video.VideoPlayer.Unload();

    if(video.VideoPlayer.Load((string) dict["title"], VideoPlayerHelper.MediaType.ON_TEXTURE, false, 0) == false)

    {

    

    }

   }

  }

        // First clear all trackables

        mObjectTracker.TargetFinder.ClearTrackables(false);

        // enable the new result with the same ImageTargetBehaviour:

        ImageTargetBehaviour imageTargetBehaviour = mObjectTracker.TargetFinder.EnableTracking(targetSearchResult, mParentOfImageTargetTemplate) as ImageTargetBehaviour;

       

        //if extended tracking was enabled from the menu, we need to start the extendedtracking on the newly found trackble.

        if (mTrackableSettings && mTrackableSettings.IsExtendedTrackingEnabled())

        {

            imageTargetBehaviour.ImageTarget.StartExtendedTracking();

        }

    }

......

3.add "video" prefab under child of CloudRecoTarget/ attach playVideo.cs to AR camera/ attach TrackableEventHandler.cs to  CloudRecoTarget (remove CloudRecoTrackableEventHandler)... /attach videoTapHandle.cs to sample UI, etc, as a setup progress for implement video playback.

4. a very tricky thing here is that, i have to put a video url link to the "path" (var under video > videoPlaybackBehaviour.cs) ,else, the marker would not detacted (error) by my android device.

Then it may work!

* of course, dont forget to apply license.

hope my post will help.

thanks

Unity video playback with cloud recognition

April 13, 2016 - 9:48am #24

Hello! I know this is an old thread, but if you reply to me you could save my life. Can you please contact me to answer some questions? I followed the code in this thread but can't get my app to work, not even when I put directly the URL for my video.

Unity video playback with cloud recognition

February 5, 2016 - 12:16pm #23

HI please need your help get in touch with me please! please respond!

Unity video playback with cloud recognition

November 14, 2014 - 5:16am #22

video is playing but whenever video is play black screen came on the front of target.please reply

Unity video playback with cloud recognition

November 14, 2014 - 2:21am #21

You need to import Json class, I forgot whether I got it from Unity assets store or somewhere else out there.

 

sneha10 wrote:

i got error (Assets/Scripts/CloudRecoScripts/CloudRecoEventHandler.cs(161,36): error CS0103: The name `Json' does not exist in the current context)

Unity video playback with cloud recognition

November 14, 2014 - 1:27am #20

i got error (Assets/Scripts/CloudRecoScripts/CloudRecoEventHandler.cs(161,36): error CS0103: The name `Json' does not exist in the current context)

 

Unity video playback with cloud recognition

November 14, 2014 - 1:26am #19

fathahnoor wrote:

Hi binspaul and DavidBeard,

I've followed this thread and partially successful implementing cloudreco in videoplayback example by modifying OnNewSearchResult method in CloudRecoEventHandler.cs, thanks alot!

public void OnNewSearchResult(TargetFinder.TargetSearchResult targetSearchResult)
{
	if(targetSearchResult.MetaData == null)
	{
		return;
	}
	else
	{
		var dict = Json.Deserialize(targetSearchResult.MetaData) as Dictionary<string,object>;

		VideoPlaybackBehaviour video = ImageTargetTemplate.gameObject.GetComponentInChildren<VideoPlaybackBehaviour>();
		if(video != null)
		{
			video.VideoPlayer.Unload();

			if(video.VideoPlayer.Load((string) dict["video"], VideoPlayerHelper.MediaType.ON_TEXTURE, false, 0) == false)
			{
			
			}
		}
	}

	mImageTracker.TargetFinder.ClearTrackables(false);

	ImageTargetBehaviour imageTargetBehaviour = mImageTracker.TargetFinder.EnableTracking(targetSearchResult, mParentOfImageTargetTemplate) as ImageTargetBehaviour;
	
	if(CloudRecognitionUIEventHandler.ExtendedTrackingIsEnabled)
	{
		imageTargetBehaviour.ImageTarget.StartExtendedTracking();
	}
}
It can recognize the cloud image target, retreive its metadata info (path to an online video file), and also play the new video.
 

But the new video size is always resized relative to the default video previously set in VideoPlaybackBehaviour's Path (m_path) in Unity. For example, if the default video size is 854x480 and the new video size is 426x240, it would be scaled smaller than the Video prefab and placed in the left-top corner. And vice versa, if the default video size is 426x240 and the new video size is 854x480, it would be scaled bigger than the Video prefab and placed with cropped view.

How to automatically resize the new video view so that it can correctly fill the video prefab (with the right aspect ratio too)?

fathahnoor wrote:

Hi binspaul and DavidBeard,

I've followed this thread and partially successful implementing cloudreco in videoplayback example by modifying OnNewSearchResult method in CloudRecoEventHandler.cs, thanks alot!

public void OnNewSearchResult(TargetFinder.TargetSearchResult targetSearchResult)
{
	if(targetSearchResult.MetaData == null)
	{
		return;
	}
	else
	{
		var dict = Json.Deserialize(targetSearchResult.MetaData) as Dictionary<string,object>;

		VideoPlaybackBehaviour video = ImageTargetTemplate.gameObject.GetComponentInChildren<VideoPlaybackBehaviour>();
		if(video != null)
		{
			video.VideoPlayer.Unload();

			if(video.VideoPlayer.Load((string) dict["video"], VideoPlayerHelper.MediaType.ON_TEXTURE, false, 0) == false)
			{
			
			}
		}
	}

	mImageTracker.TargetFinder.ClearTrackables(false);

	ImageTargetBehaviour imageTargetBehaviour = mImageTracker.TargetFinder.EnableTracking(targetSearchResult, mParentOfImageTargetTemplate) as ImageTargetBehaviour;
	
	if(CloudRecognitionUIEventHandler.ExtendedTrackingIsEnabled)
	{
		imageTargetBehaviour.ImageTarget.StartExtendedTracking();
	}
}
It can recognize the cloud image target, retreive its metadata info (path to an online video file), and also play the new video.
 

But the new video size is always resized relative to the default video previously set in VideoPlaybackBehaviour's Path (m_path) in Unity. For example, if the default video size is 854x480 and the new video size is 426x240, it would be scaled smaller than the Video prefab and placed in the left-top corner. And vice versa, if the default video size is 426x240 and the new video size is 854x480, it would be scaled bigger than the Video prefab and placed with cropped view.

How to automatically resize the new video view so that it can correctly fill the video prefab (with the right aspect ratio too)?

Unity video playback with cloud recognition

July 25, 2014 - 9:43pm #18
Hello all,
 
I'm trying to follow a few threads to implement Cloud Reco and Video Playback in an AR Browser application. So far I've been able to integrate image overlay and 3d model overlay over a cloud reco target. I'm trying to implement the Video Overlay over target and seem to be lost somewhere in the process. 
 
As mentioned in an earlier post, I tried to implement the IT Event Handler class in the ShowObject() function as mentioned below, and have implemented the related scripts in the HideObject() and Update() functions as well. But neither the static video from the streaming assets folder nor the video from the URL play on the target. The application is stuck at the "loading" screen forever. Can anyone help me with this issue? 
 
Regards,
Parth Darji
private void ShowObject()
{
//If the asset is an image
....
....
....

//If the asset is a video
else if(mAssetData.AssetType == "video")
{
	//Find the gameobject to activate
	Transform videoTransform = AugmentationObject.transform.FindChild("Video");
	videoTransform.gameObject.SetActive(true);
	//Get the VideoPlaybackBehaviour component to modify its contents and play the video.

	VideoPlaybackBehaviour video = videoTransform.GetComponent<VideoPlaybackBehaviour>();
	//Set the URL to the video

	//video.m_path = mAssetData.AssetURL;

	//Activate renderers and colliders
	Renderer[] rendererComponents = video.GetComponentsInChildren<Renderer>();
	foreach(Renderer component in rendererComponents)
		component.enabled = true;

	Collider[] colliderComponents = video.GetComponentsInChildren<Collider>();
	foreach(Collider component in colliderComponents)
		component.enabled = true;

	//The following code deals with the playing of the video
	//along with the Update function above.
	// Optionally play the video automatically when the target is found

	if (video != null && video.AutoPlay)
	{
		if (video.VideoPlayer.IsPlayableOnTexture())
		{
			VideoPlayerHelper.MediaState state = video.VideoPlayer.GetStatus();
			if (state == VideoPlayerHelper.MediaState.PAUSED ||
			    state == VideoPlayerHelper.MediaState.READY ||
			    state == VideoPlayerHelper.MediaState.STOPPED)
			{
				// Pause other videos before playing this one
				PauseOtherVideos(video);
						
				// Play this video on texture where it left off
				video.VideoPlayer.Play(false, video.VideoPlayer.GetCurrentPosition());
			}
			else if (state == VideoPlayerHelper.MediaState.REACHED_END)
			{
				// Pause other videos before playing this one
				PauseOtherVideos(video);
			
				// Play this video from the beginning
				video.VideoPlayer.Play(false, 0);
			}
		}
      }
}

 

Unity video playback with cloud recognition

July 4, 2014 - 6:44pm #17

Hi binspaul and DavidBeard,

I've followed this thread and partially successful implementing cloudreco in videoplayback example by modifying OnNewSearchResult method in CloudRecoEventHandler.cs, thanks alot!

public void OnNewSearchResult(TargetFinder.TargetSearchResult targetSearchResult)
{
	if(targetSearchResult.MetaData == null)
	{
		return;
	}
	else
	{
		var dict = Json.Deserialize(targetSearchResult.MetaData) as Dictionary<string,object>;

		VideoPlaybackBehaviour video = ImageTargetTemplate.gameObject.GetComponentInChildren<VideoPlaybackBehaviour>();
		if(video != null)
		{
			video.VideoPlayer.Unload();

			if(video.VideoPlayer.Load((string) dict["video"], VideoPlayerHelper.MediaType.ON_TEXTURE, false, 0) == false)
			{
			
			}
		}
	}

	mImageTracker.TargetFinder.ClearTrackables(false);

	ImageTargetBehaviour imageTargetBehaviour = mImageTracker.TargetFinder.EnableTracking(targetSearchResult, mParentOfImageTargetTemplate) as ImageTargetBehaviour;
	
	if(CloudRecognitionUIEventHandler.ExtendedTrackingIsEnabled)
	{
		imageTargetBehaviour.ImageTarget.StartExtendedTracking();
	}
}
It can recognize the cloud image target, retreive its metadata info (path to an online video file), and also play the new video.
 

But the new video size is always resized relative to the default video previously set in VideoPlaybackBehaviour's Path (m_path) in Unity. For example, if the default video size is 854x480 and the new video size is 426x240, it would be scaled smaller than the Video prefab and placed in the left-top corner. And vice versa, if the default video size is 426x240 and the new video size is 854x480, it would be scaled bigger than the Video prefab and placed with cropped view.

How to automatically resize the new video view so that it can correctly fill the video prefab (with the right aspect ratio too)?

Unity video playback with cloud recognition

March 3, 2014 - 8:26am #16

Hello DavidBeard,

-> Is there a way to stop the automatic cloud scanning from happening when the target image is changed?

-> I was able to implement the background downloading and playing of the video file from web url using the WWW class. I am now working on a way to improve the basic loading bar.

 

Thanks,

BP

Unity video playback with cloud recognition

January 1, 2014 - 6:58pm #15

That's a good question for Unity Answers or their forum, because I wonder whether WWW is recommended for larger files - otherwise you can use System.IO and .NET.

WWW provides a .progress property that you can use for a progress bar and an alternate approach is shown below..

http://answers.unity3d.com/questions/300841/ios-download-files-and-store-to-local-drive.html

Unity video playback with cloud recognition

December 31, 2013 - 11:04pm #14

Hello DavidBeard,

I followed your suggestion and was able to get a reference to the video object. I was also able to play the video successfully.

Great start for the new year! Thanks a lot for your time and assistance.

---

I am planning to download the video from url to the device folder and play it from there. This is to avoid the buffering delay in the case of a long file/weak network. I am aiming to work with the 'WWW' class of Unity. Is there any better method to suggest?

Also, is it possible to show a loading progress bar for buffering?

---
 
Thanks,
BP
 

Unity video playback with cloud recognition

December 31, 2013 - 7:09pm #13

Take a look at the TrackableEventHandler in the VideoPlayback sample for an example of how to reference the Video instance and access the VideoPlayerHelper API on that instance. 

 

e.g.


                VideoPlaybackBehaviour video = GetComponentInChildren<VideoPlaybackBehaviour>();
                if (video != null &&
                    video.CurrentState == VideoPlayerHelper.MediaState.PLAYING)
                {
                    video.VideoPlayer.Pause();
                }

  
    

Use GetComponent to reference the VideoPlaybackBehaviour in the child video prefab instance, and then the VPH API will be accessible using the VideoPlayer property. You can use the Load method w/ the URL as the first argument, and the SetFileName method will recognize that as a remote file and it will be handled accordingly.

There are also some useful examples in the VideoPlaybackAppManager  class for selecting videos, handing touches etc..

Unity video playback with cloud recognition

December 31, 2013 - 6:52pm #12

Hello DavidBeard,

I have parsed the JSON response successfully using the MiniJSON plugin.

I was not able to set the new video url to the video player correctly. I am current in the 'OnNewSearchResult' method of 'CloudRecoEventHandler.cs' file. From here, how could I get a reference to the 'VideoPlayerHelper' or the correct object that is required for setting the video file url?

NOTE: The video is playing successfully whent the url is specified directly in the path field of the video prefab.

 

Thanks,

BP

 

Unity video playback with cloud recognition

December 29, 2013 - 9:57pm #11

http://json.org/ provides a good selection of JSON libraries in various languages.

Unity video playback with cloud recognition

December 29, 2013 - 8:55pm #10

Hello DavidBeard,

I was able to identify the cloud server response. I am using DDMS for finding the Unity Logs.

---

12-30 08:34:08.145: W/Unity(7865): Cloud response is: {index: "1", type:"video", url: "http://www.mydomain.com/demo/movie.m4v", size: "1391402"}

---

Now comes the JSON parsing....

 

Thanks,

BP

Unity video playback with cloud recognition

December 29, 2013 - 8:34am #9

I recommend using the Eclipse DDMS and adding a 'Unity' filter. Otherwise you can write logcat to a file - https://sites.google.com/site/androidhowto/how-to-1/save-logcat-to-a-text-file. You'll need ADB installed for both. See: https://developer.vuforia.com/resources/dev-guide/getting-started-android-native-sdk

There is a script in this thread that shows how to read the metadata from the search result - https://developer.vuforia.com/forum/cloud-recognition/cloud-recognition-tutorial-scripts

You can then assign the associated video using the VideoPlayerHelper API

Unity video playback with cloud recognition

December 28, 2013 - 7:34pm #8

Hello DavidBeard,

The first method worked. I am able to get the cloud response and then the default video is played. Now, I need to implement the logic to play the video depending on the cloud meta data response. I am planning to work on the 'ShowObject' method you mentioned.

Where can I get the unity logs that are getting printed? Do I need to check with the ADB?

Looks so good for the new year!

 

Thanks,

BP

Unity video playback with cloud recognition

December 28, 2013 - 10:08am #7

Verify your video path is correct, and that you are using the TrackableEventHandler.cs script from the VideoPlayback sample - you can also use VideoPlaybackAppManager.cs to handle touches.

Also are you seeing this on a device, or in Play Mode - video playback isn't supported in Play Mode, you'll see the keyframe and button but no video rendering.

Unity video playback with cloud recognition

December 28, 2013 - 9:23am #6

Hello DavidBeard,

Thanks for the update. I will check that and will let you know.

Since my first implementation was error, I tried a second method to integrate the cloud service with the video player. I started with the cloud recognition example and imported the video prefab and the associated files from the video playback example to it.

I set the video prefab as the child of the cloud target and disabled the teapot object to prevent it from getting augmented.

When the cloud response is obtained, the video prefab is getting displayed successfully. The video is not played though. I am getting the loading/busy indicator. Is it because of the video path error or do I need to write some code to get the video played? I tried with the auto play feature also.

---

The screen shots are available for your reference at: https://dl.dropboxusercontent.com/u/2543137/01.zip

---

Thanks,

BP

AttachmentSize
Package icon 01.zip825.48 KB
Binary Data bytes

Unity video playback with cloud recognition

December 28, 2013 - 8:46am #5

The event handling for the IT template is now in ContentManager.cs.

That script is obsolete for the 2.8.9 samples. 

You'll want to implement any video specific code from the ShowObject method ..

public class ContentManager : MonoBehaviour, ITrackableEventHandler
{
    #region PUBLIC_VARIABLES
    /// <summary>
    /// The root gameobject that serves as an augmentation for the image targets created by search results
    /// </summary>
    public GameObject AugmentationObject;
    #endregion PUBLIC_VARIABLES

    #region UNTIY_MONOBEHAVIOUR_METHODS

    void Start ()
    {
        TrackableBehaviour trackableBehaviour = AugmentationObject.transform.parent.GetComponent<TrackableBehaviour>();
        if (trackableBehaviour)
        {
            trackableBehaviour.RegisterTrackableEventHandler(this);
        }
        
        ShowObject(false);
    }
    
    #endregion UNTIY_MONOBEHAVIOUR_METHODS

    #region PUBLIC_METHODS
    
    /// <summary>
    /// Implementation of the ITrackableEventHandler function called when the
    /// tracking state changes.
    /// </summary>
    public void OnTrackableStateChanged(
                                    TrackableBehaviour.Status previousStatus,
                                    TrackableBehaviour.Status newStatus)
    {
        if (newStatus == TrackableBehaviour.Status.DETECTED ||
            newStatus == TrackableBehaviour.Status.TRACKED || 
            newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)
        {
            ShowObject(true);
        }
        else
        {
            ShowObject(false);
        }
    }

    public void ShowObject(bool tf)
    {
        Renderer[] rendererComponents = AugmentationObject.GetComponentsInChildren<Renderer>();
        Collider[] colliderComponents = AugmentationObject.GetComponentsInChildren<Collider>();

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

        // Enable colliders:
        foreach (Collider component in colliderComponents)
        {
            component.enabled = tf;
        }
    }

 

Unity video playback with cloud recognition

December 28, 2013 - 7:52am #4

Hi,

I am working on the cloud recognition + video player integration using the latest vuforia unity template. I am using the code posted by AL in the thread: https://developer.vuforia.com/forum/unity-3-extension-technical-discussion/please-explain-step-step-how-use-vuforia-cloud

The cloud recognition is working and the detection count is incremented in the 'Target Manager'. But, I am not getting the response as intended.

Also, I am stuck with the following error:

---

Assets/Scripts/CloudRecoScripts/CloudRecoEventHandler.cs(65,46): error CS0266: Cannot implicitly convert type `ImageTargetAbstractBehaviour' to `ImageTargetBehaviour'. An explicit conversion exists (are you missing a cast?)

---

How to fix this error ?

Thanks,

BP

Unity video playback with cloud recognition

December 13, 2013 - 6:06am #3

Hello DavidBeard,

I have started with the video playback demo. The steps I followed was:

1. Cloud recognition prefab was added from the 'Prefabs' folder.

2. Client access keys were set.

3. ImagetargetsChips type was changed to 'Cloud Reco'

4. The stones image target was removed.

5. Imported the 'CloudRecognitionEventHandler.cs' and 'ErrorMsg.cs' from the cloud recognition sample.

6. Commented out the codes that reference 'mContentManager'

---

When the application is run, nothing happens. What should be the next step that is required to link the cloud recognition service to the video player?

Thanks in advance,

BP

Unity video playback with cloud recognition

December 12, 2013 - 10:03pm #2

I'd recommend starting w/ the Video Playback sample. You can convert the predefined ImageTarget to a template by redefinding it as a Cloud Reco type in the imageTargetBehaviour. Then follow this tutorial to see how to set-up the scene to use the Cloud Recognition service using the Cloud Recognition prefab - https://developer.vuforia.com/resources/tutorials/creating-cloud-recognition-apps-unity

Log in or register to post comments