YouTube Video Player | Target Found and Lost | Urgent
Hi guys. I'm starting a new thread as oriented because we have urgency on this.
The idea is very simple, but I couldn't achieve yet because I'm not a software engineer (and new on unity stuffs) and I need your help if you could, since we're going to use yours plugin (Pro version). And I've tested a lot of AR packages trying to solve that, yours was the only who could do it in the way we want.
We want to play a YouTube video. Unity don't support that for now. They just support a URL file which is http://.../video.mp4. But that's not what we want, we want to play a Youtube video because its easier to manage the videos and it's free!
So here we go. To get videos playing from Youtube into Android and iOS I've tested a lot of videoplayback plugins and I found a solution. A plugin for unity called "Youtube Video Player" does the trick very well and in a impressive quality. This plugin has a checkbox to play the video on start, but that's not what we want. We want to play the video when target is found and pause it when target is lost.
Therefore, I imagine that in the plugin exists the possibility to identify the "play" function in the codes and link together with MAXST function GetCount that you previously informed me. Guys, I'm new on unity stuff, so if you could help me with a step by step, this will turn in a positive thing for you soon.
What can I do to solve that?
Best!
Ok, I tryed to put yours code from last post in the Youtube Video Player plugin code and just changed the name of the "videoPlayer" to "unityVideoPlayer".
I paste yours code before the line that video was ready to play and disable the ".Play" from original plugin code:
YOURS CODE UP HERE;
//Play Video
//unityVideoPlayer.Play();
//Play Sound
//unityVideoPlayer.Play();
But, I'm getting the following error:
"SimplePlayback.cs(110,28): error CS0120: an object reference is required to access non-static member `maxstAR.TrackingResult.GetCount()"
What can I do here guys?
Best.
Hi,
We are sorry to have you waiting :-)
Please refer full implementation code below.
TrackingState state = TrackerManager.GetInstance().UpdateTrackingState();
TrackingResult trackingResult = state.GetTrackingResult();
if (trackingResult.GetCount() == 0)
{
// Pause or stop playing
}
else
{
// Start or resume playing
}
If you can share your project to our team we can check your code.
- Maxst support team
Thaaankkkssss guys.
After a day inside this codes I finally figure out how to do it with your help, of course.
Your code now works pretty cool and smooth.
I do not know how to thank you more. Expect some license purchases in the coming months.
You guys, rocks! Thank You again.
Best.
It's very nice to hear that you have found the way!
Good job :-)
- Maxst support team
Hi guys, I'm back again :D
Let's say for example that I generated more target images (5 for ex.) and I want to add each one of those target images specifically to reproduce a unique YouTube video. For example, if I point my cell phone to image "A" then the video play a specifically Youtube video to "A". If I point my cell phone to image "B" then stop the video "A" and starts playing a video specifically to "B", if I point to "C" then stop "B" and plays a youtube video to "C" and so on. Therefore, the logic is to duplicate the "ImageTrackable" object with children (Youtube Video Playback plugin), change the image target mark and change the youtube video link in the plugin, right?
But, that is not what's happening. It seems that somehow the Youtube plugin is getting the same unityVideoPlayer ID or something like that because, on my case, if the tracker finds an image target "A" both videos starts to play at the same time. To be more specifically, if the tracker finds an image target "A" the video starts but also the audio from other youtube video (from other image target). That is not what we want. We want to reproduce a single video at a time, one youtube video for one image target.
So guys, how can we do that?
I'm sharing my project package so you could have a better idea of what's going on.
Looking forward to hearing back from you!
Best.
Hi,
Where is the sample scene for video augmented located?
- Maxst support team
Sorry for not explaining how scenes were organized.
Scene "NAMES" is where you can find the subject of this topic. "NAME1_TRACK" and "NAME2_TRACK" is yours "ImageTrackable" prefab renamed. In the canvas I created a button to go back to start menu.
You want to control each video individually and you've implemented your control code in SimplePlayback.cs right?
But you don't change the visibility of SimplePlayback component so FixedUpdate function is always alive in both videos.
My suggestions are
1. Remove tracking result checking in SimplePlayback.cs
2. Control the state of SimplePlayback component in ImageTrackableBehaviour.cs
Please refer code below. (I'm not sure it's the corret implementation but it's better to follow the style below)
public class ImageTrackableBehaviour : AbstractImageTrackableBehaviour
{
public override void OnTrackSuccess(string id, string name, Matrix4x4 poseMatrix)
{
Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);
SimplePlayback[] videoplayers = GetComponentsInChildren<SimplePlayback>(true);
// Enable renderers
foreach (Renderer component in rendererComponents)
{
component.enabled = true;
}
// Enable colliders
foreach (Collider component in colliderComponents)
{
component.enabled = true;
}
// Enable video player attached
foreach (SimplePlayback videoplayer in videoplayers)
{
videoplayer.enabled = true;
}
transform.position = MatrixUtils.PositionFromMatrix(poseMatrix);
transform.rotation = MatrixUtils.QuaternionFromMatrix(poseMatrix);
}
public override void OnTrackFail()
{
Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(true);
Collider[] colliderComponents = GetComponentsInChildren<Collider>(true);
SimplePlayback[] videoplayers = GetComponentsInChildren<SimplePlayback>(true);
// Disable renderer
foreach (Renderer component in rendererComponents)
{
component.enabled = false;
}
// Disable collider
foreach (Collider component in colliderComponents)
{
component.enabled = false;
}
// Disable video player attached
foreach (SimplePlayback videoplayer in videoplayers)
{
videoplayer.enabled = false;
}
}
- Maxst support team
Ok guys! I'm going to try it.
Best.
Hi,
So, now they're recognizing the targets individually, but they're not obeying to "pause and play" with found or lost after I removed the tracking result checking in SimplePlayback.cs (FixedUpdate).
It seems to work well after I've made that change on ImageTrackableBehaviour.cs in onTrackSuccess and onTrackFail as you suggested, but preserving the tracking result ckecking in SimplePlayback.cs so that maintain the play/found and pause/lost function.
The only issue now is that sometimes even after target is lost the video keeps playing.
What that could be?
//UPDATE ON THAT
If target is lost the video definitely pause, the problem is that sometimes if the target goes to "lost" and "found" quickly the video disappears but audio keeps playing. I'm not sure if there's any way to solve that.
Thanks so far guys. Appreciate ALL the efforts you've doing on helping me.
Best.
Hi,
I think you've arrived just in front of the goal.
If you use onTrackSuccess, onTrackFail and FixedUpdate simultaneously to control video playing it may occur confusing because after onTrackFail called FixedUpdate may not be called. (That is the reason why you heared the audio of the lost target's video)
So, you must change your code as to unityVideoPlayer.Pause() must be called in OnTrackFail and unityVideoPlayer.Play() must be called in OnTrackSuccess()
- Maxst support team
Yes, we are very close to reach the objective!!! ;)
Thanks for the amazing support from you man.
I'm not able to understand how could I do that. I've tryed to insert the function of OnTrackFail/Success in SimplePlayback.cs but I couldn't get it to work. And on the ImageTrackableBehaviour.cs it don't recognize the Play and Pause function, it seems that just works with boolean.
I'm lost here. How that could be done guys?
Sorry for not fully understand how to do it, I definitely need to do some 101 in C# language.
Best.
Hi,
Please follow steps below.
1. Add StopPlaying() and StartPlaying() in SimplePlayback.cs.
2. Implement StopPlaying() body to call unityVideoPlayer.Pause()
3. Implement StartPlaying() body to call unityVideoPlayer.Play()
4. Call StartPlaying when tracking success and call StopPlaying when tracking fails.
- Maxst support team
IT WORKED GUYS!!! CONGRATULATIONS AND THANKS! :D :D :D
I can't believe that I should be able to write some code in my life time even something simple like that. haha
Now, thank you a lottttt for been patience with some noob like me. We can't be more grateful to you. As I sayd before, you guys rock and expect some license purchase in next months. We'll really going to use yours technology.
Take care and have a nice day there in another side of the world. ;)
Best.
Hi,
It's nothing to us to guide developers like you.
Have a good day!
- Maxst support team