Log in or register to post comments

Set Video thumbnail at runtime iOS

January 13, 2014 - 5:55pm #1

Hi,

I am creating an app that is based on the cloud reco sample and the video playback sample.

After recognition I download data from my server and display the content on the target. I want to display videos as well, so I created a prefab for the video directly from the video playback sample and at runtime I set the parameters (url to video).

I have thumbnails for the videos on my server (jpgs) that I want to display, on Android and within the Unity player everything works fine, the video thumbnails is displayed and when pressed the video plays in full screen. However, in iOS the video thumbnail is just black (everything else works).

I know that the code I am using to download the images works, because to test it, I created another prefab which is just a plane, and I applied the downloaded image as a texture and it appears.

I cannot find the reason that in iOS the thumbnail appears black, is there something in the video playback scripts that would affect this?

Here is my code (in the contentmanager):

This is called from within the LoadJSONBookData function, after the JSON data has finished downloading:

newVideo = (GameObject)Instantiate(arvideo, new Vector3(15*i, 0, 0), Quaternion.identity);
newVideo.GetComponent<VideoPlaybackBehaviour>().m_path = ((BookAssets)bookData.Assets[i]).AssetContent; // SET THE URL FOR THE VIDEO

string url = ((BookAssets)bookData.Assets[i]).AssetThumbnail;
StartCoroutine(DownloadImage(url, newVideo, ((BookAssets)bookData.Assets[i]).AssetFilename, "VIDEO"));

newVideo.transform.parent = AugmentationObject.transform;
newVideo.transform.rotation = Quaternion.Euler(0, -180, 0);

and this is the DownloadImage function:

public IEnumerator DownloadImage(string url, GameObject tex, string filename, string type) 
{
        
    WWW www = new WWW(url);
    yield return www;
        if (www.isDone)
        {
            tex.GetComponent<VideoPlaybackBehaviour>().KeyframeTexture = www.texture;
            tex.renderer.material.mainTexture = www.texture;
            Color color = tex.renderer.material.color;
            color.a = 1f;
            tex.renderer.material.color = color;
        }
}

Any suggestions would be greatly appreciated! TIA!

Set Video thumbnail at runtime iOS

January 27, 2014 - 3:40pm #17

Thanks NalinS!

This is the code I ended up using for anyone else looking for a solution:

#if UNITY_EDITOR
    renderer.material.mainTextureScale = new Vector2(1, -1);
#elif UNITY_IPHONE
    renderer.material.mainTextureScale = new Vector2(1, 1);
#elif UNITY_ANDROID
    renderer.material.mainTextureScale = new Vector2(1, -1);
#endif

 

Set Video thumbnail at runtime iOS

January 27, 2014 - 9:56am #16

Right.

After looking at the project you sent me, I had problems where the texture would not be updated in iOS or in Play Mode.

However, in VideoPlaybackBehaviour.cs  when I changed this line:

                renderer.material.mainTextureScale = new Vector2(1, -1);

to this:

                renderer.material.mainTextureScale = new Vector2(11);

..suddenly the black keyframe texture disappeared to be replaced with the correct texture.

 

The reason this was put in was to orientate the keyframe texture the correct way for the VideoPlayback sample.

However it seems to have an adverse effect on other textures, exactly why I am not sure.

  • It could be platform specific (iOS v Android)
  • It could be Unity version specific
  • For Play Mode it could be different on Mac v PC
  • It could be dependent on the graphics card
  • It may be related to whether the texture is a Power of 2 

Either way you will probably need to experiment to get this working as you want it, as it is not really specific to Vuforia.

 

HTH

N

 

 

Set Video thumbnail at runtime iOS

January 17, 2014 - 8:31am #15

I am not sure why it is not working for you in Play Mode, when I play it in Unity it does work.

Have you tried it on Android?

Set Video thumbnail at runtime iOS

January 17, 2014 - 7:41am #14

So basically you are saying now that it is a problem in Play Mode, iOS and Android?

Previously, my understanding was that it was specific to iOS...

 

N

 

Set Video thumbnail at runtime iOS

January 17, 2014 - 7:29am #13

Great, you have managed to replicate the problem.

In this build I am applying the same texture to the video and to a normal Unity plane.

In the screenshot Screen Shot 2014-01-17 at 12.08.50.png you can see the texture has been successfully downloaded, as it appears on the plane (bottom right, the texture of the legs). But the video thumbnail is black, it should have the same texture.

Set Video thumbnail at runtime iOS

January 17, 2014 - 7:20am #12

With your latest build I got a black screen in Play Mode and just the spinner on the device.  Eventually the spinner disappears, but there is no augmentation.

Screenshots attached.

AttachmentSize
Image icon Screen Shot 2014-01-17 at 12.08.50.png591.76 KB
Image icon IMG_0078.PNG714.79 KB

Set Video thumbnail at runtime iOS

January 16, 2014 - 7:48am #11

Hi

When I run this in Play Mode the video playback keyframe shows black in Unity with an X on top of it - it's not showing a texture. ( see attached picture)

When I run it on the device, nothing shows up at all, and the log indicates there is a JSON error:

LoadJSONBookData, url= http://xtendi.azurewebsites.net/Projects/getData/122.json

 

(Filename: /Applications/buildAgent/work/d3d49558e4d408f4/artifacts/iPhonePlayer-armv7Generated/UnityEngineDebug.cpp Line: 53)

 

Error downloading json

 

 

N

AttachmentSize
Image icon Screen Shot 2014-01-16 at 15.30.12.png661.56 KB

Set Video thumbnail at runtime iOS

January 15, 2014 - 5:10am #10

Ok, could you PM me with a link to the project (e.g. dropbox) so I can download and investigate further?

 

thanks,

N

Set Video thumbnail at runtime iOS

January 14, 2014 - 11:08am #9

I have tested this and I can apply the textures to a normal plane in unity

Set Video thumbnail at runtime iOS

January 14, 2014 - 10:02am #8

Can you try one more test which is to apply these textures to a normal Unity plane i.e. not a VP Prefab

I want to understand whether it is definitely a Vuforia issue.

 

N

Set Video thumbnail at runtime iOS

January 14, 2014 - 9:55am #7

Hey,

You understand correctly.

Like I said I am able to apply the texture to a plane that is not a VP Prefab. That is why I believe that there is something in the VP scripts that doesn't allow me to apply a downloaded texture as the thumbnail.

Set Video thumbnail at runtime iOS

January 14, 2014 - 8:27am #6

Ok, just so I understand correctly:

  • static texture - updates ok on Android/iOS/Play mode
  • downloaded texture - updates ok on Android/Play mode  but not iOS

Can you try one more test which is to apply these textures to a normal Unity plane i.e. not a VP Prefab

I want to understand whether it is definitely a Vuforia issue.

 

cheers,

N

 

Set Video thumbnail at runtime iOS

January 14, 2014 - 8:02am #5

Hi NalinS,

In my previous reply I meant that I tried applying the script to the video playback sample with no success, not on my app. Sorry if I was unclear.

I tried your second suggestion, downloaded the thumbnail image from my server, put it in one of the folders in my Unity project, defined a public texutre in the contentmanager script, assigned the image to the texture, and using the following code I managed to get the thumbnail to appear correctly:

newVideo.GetComponent<VideoPlaybackBehaviour>().KeyframeTexture = testTex;

I noticed that applying the image as the mainTexture does not work, for example:

newVideo.renderer.material.mainTexture = testTex;

The image must be applied to the KeyframeTexure property of the prefab for it to work correctly.

Like I mentioned, I am using the same script to download images from the server and display them as images on my target by applying the downloaded image as a texture to a prefab plane, so therefor I am confident that the download routine is working.

I am guessing that the problem has to do with applying a downloaded image to the KeyframeTexture property but I cannot figure out as to why and how to resolve this.

Any ideas would be really really appreciated!

Set Video thumbnail at runtime iOS

January 14, 2014 - 6:28am #4

er... ok 

So let me ask the question again (plus one more)

  1. does the same thing happen with the video playback sample? i.e. not your app
  2. what happens if you try and assign a static texture (your own) at run-time rather than trying to download it first

N

Set Video thumbnail at runtime iOS

January 14, 2014 - 6:16am #3

Hi NalinS,

I did try to do this to debug the problem but without success.

Set Video thumbnail at runtime iOS

January 14, 2014 - 4:29am #2

Have you been able to reproduce this on the native video playback sample i.e. by downloading a remote image and then updating the Play Texture on the Video Playback behaviour script?

thanks

N

 

Log in or register to post comments