Search Unity

  1. Get the latest news, tutorials and offers directly to your inbox with our newsletters. Sign up now.
    Dismiss Notice

get file path stored in Application.persistentDataPath

Discussion in 'WebGL' started by shb, Feb 4, 2017.

  1. shb


    Oct 7, 2012
    Here is my situation.
    1. I need to play video on my webgl project.
    2. The video should come with extra downloading (asset bundles), not from embeded with build in StreamingAssets folder from initial download.
    3. I found WebGL Movie texture example by Unity from asset store.
    4. If I put my video in Streaming folder as it is, It works.
    5. To embed video file in asset bundles, I changed video file extension from .mp4->.txt then I assigned it to one of my script's TextAsset type public variable in inspector. then when it starts I copied back my TextAsset object to Application.persistenDataPath with it's original extension (.mp4)

    Code (CSharp):
    1. public TextAsset vidRaw;
    2.     void Start () {
    4.         string vidCachePath =  Application.persistentDataPath + "/vid.mp4";
    5.         Debug.Log ("vidCachePath:" + vidCachePath);
    7.         File.WriteAllBytes(vidCachePath, vidRaw.bytes);
    7. Then I tried to playback the video from the newly created video.
    Code (CSharp):
    1.   tex = new WebGLMovieTexture(vidCachePath);
    2.         cube.GetComponent<MeshRenderer>().material = new Material (Shader.Find("Diffuse"));
    3.         cube.GetComponent<MeshRenderer>().material.mainTexture = tex;

    8. But it doesn't work.
    I can see the video file created in indexedDB path like:
    and I can check the file size is also ok.

    But in jslib side, just passing the indexedDB path to the video.src doesn't seem to be enough.
    Code (JavaScript):
    1. WebGLMovieTextureCreate: function(url)
    2. {
    4.     var str = Pointer_stringify(url);
    6.     var video = document.createElement('video');
    7. = 'none';
    8.     video.src = str;
    10.     return videoInstances.push(video) - 1;
    11. },
    How Can I play video inside Application.persistentDataPath that starts with something like /idbfs/XXXX ?