- Home /
Question by
Repzy · Feb 17, 2018 at 03:00 PM ·
androidassetbundlejar
How to read assetbunde from Application.datapath on android
I'm trying to load a video assetbundle file when the user gets to a specific scene on my android app. Ultimately I want to load this file from external storage on the android device, but for now I'm just trying to get it working from inside the APK. Everything is working perfectly in the editor but once I build the APK it freezes on that scene and is unable to load the video file.
I've spend about two days trying to resolve this so any help is really appreciated! I've looked at similar questions here and bug reports but couldn't find anything to solve this problem. I'm using unity 2017.3. Here's the code:
public class LoadAssetFiles : MonoBehaviour
{
public GameObject video;
public static string GetBundlePathForLoadFromFile (string filePath)
{
#if UNITY_EDITOR
string streamingAssetsPath = Application.streamingAssetsPath;
#else
string streamingAssetsPath = Application.dataPath + "!/assets/"
#endif
return Path.Combine(streamingAssetsPath, filePath);
}
IEnumerator Start()
{
var videoBundleLoadRequest = AssetBundle.LoadFromFileAsync GetBundlePathForLoadFromFile("videotest"));
yield return videoBundleLoadRequest;
var myLoadedAssetBundle = videoBundleLoadRequest.assetBundle;
var assetLoadRequest = myLoadedAssetBundle.LoadAssetAsync<VideoPlayer>("VideoFile");
yield return assetLoadRequest;
VideoClip videoAsset = assetLoadRequest.asset as VideoClip
video.GetComponent<VideoPlayer>.clip = videoAsset;
myLoadedAssetBundle.Unload(false);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612152820im_/https://answers.unity.com/themes/thub/images/avi.jpg)