Reputation: 313
I want to play the video in AR camera. Totally I have 10 videos and one videoplayer. And I am downloading the video player from the server as an asset bundle with name videoplayer.unit3d and storing into sd card. when I am scanning the imageTarget I am reading the video asset bundle file using AssetBundle.LoadFromFile()
function and for the first time its working fine.
If I scan the second imageTarget it is showing following error
"Can't be loaded because another AssetBundle with the same files is already loaded"
I have tried a bundle.Unload(true);
and Caching.cleanchache()
but its not working throwing same error. Also tried bundle.Unload(false);
private void loadObject(string resourcePath, string objectName, TrackableBehaviour trackableBehaviuor, string videoUrl)
{
Debug.Log("Resource path " + resourcePath + " objectName " + objectName);
Debug.Log("Video Url from sd card " + videoUrl);
FileInfo fileInfo = new FileInfo(resourcePath);
if (!fileInfo.Exists)
return;
Debug.Log("File is present");
AssetBundle bundle = AssetBundle.LoadFromFile(resourcePath, 0, 0);//www.assetBundle;
Debug.Log("Bundle data is " + bundle);
if (bundle == null)
{
AndroidJavaObject jObject = new AndroidJavaObject("com.ezvidya.buzzle.activity.UnityActivity");
jObject.Call("showErrorDialog");
return;
}
else
{
AndroidJavaObject jo = new AndroidJavaObject("com.ezvidya.buzzle.activity.UnityActivity");
jo.Call("closeScanDialog");
}
//Load an asset from the loaded bundle
AssetBundleRequest bundleRequest = bundle.LoadAssetAsync(objectName, typeof(GameObject));
//bundle.Unload(false);
Caching.CleanCache();
//get object
GameObject cubeFromSDCard = bundleRequest.asset as GameObject;
if (cubeFromSDCard != null)
{
// instantiate augmentation object and parent to trackable
GameObject augmentation = (GameObject)GameObject.Instantiate(cubeFromSDCard);
augmentation.transform.parent = trackableBehaviuor.gameObject.transform;
augmentation.transform.localPosition = cubeFromSDCard.transform.localPosition;//new Vector3(0f, 0f, 0f);
augmentation.transform.localRotation = cubeFromSDCard.transform.localRotation;//Quaternion.identity;
augmentation.transform.localEulerAngles = cubeFromSDCard.transform.localEulerAngles;
augmentation.transform.localScale = cubeFromSDCard.transform.localScale;// new Vector3(22f, 22f, 22f);
Debug.Log("$$$$$$$$$$$$$$$$ Local Position from asset object " + cubeFromSDCard.transform.localPosition);
Debug.Log("$$$$$$$$$$$$$$$$ Local Rotation from asset object " + cubeFromSDCard.transform.localEulerAngles);
Debug.Log("$$$$$$$$$$$$$$$$ Local Scale from asset object " + cubeFromSDCard.transform.localScale);
Debug.Log("$$$$$$$$$$$$$$$$ Position from asset object " + cubeFromSDCard.transform.position);
Debug.Log("$$$$$$$$$$$$$$$$ Rotation from asset object " + cubeFromSDCard.transform.eulerAngles);
Debug.Log("$$$$$$$$$$$$$$$$ Scale from asset object " + cubeFromSDCard.transform.lossyScale);
// Caching.CleanCache();
if (videoUrl != null && videoUrl.Length > 0)
{
VideoPlaybackBehaviour video = augmentation.GetComponent<VideoPlaybackBehaviour>();
video.m_autoPlay = true;
Debug.Log("Autoplay is " + video.AutoPlay);
video.m_path = videoUrl;
// Pause other videos before playing this one
// Play this video on texture where it left off
//OnTrackingFound(false);
if (video != null && video.AutoPlay)
{
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, 0);
}
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);
}
}
}
augmentation.gameObject.SetActive(true);
}
//bundle.Unload(false);
}
Upvotes: 3
Views: 21597
Reputation: 21
I have resolved this problem using add below two lines,
private AssetBundle myLoadedAssetBundle;
string bundleUrl="";
IEnumerator LoadAssetBundle ()
{
if (myLoadedAssetBundle != null) {
myLoadedAssetBundle.Unload(false); //scene is unload from here
}
while (!Caching.ready)
yield return null;
WWW www = WWW.LoadFromCacheOrDownload(bundleUrl, 1);
yield return www;
if (!string.IsNullOrEmpty(www.error))
{
Debug.Log(www.error);
yield return null;
}
myLoadedAssetBundle = www.assetBundle;
}
Upvotes: 2
Reputation: 313
I have found the answer, After Instantiate
the Gameobject just call bundle.Unload(false);
it solved my problem.
Upvotes: 9