Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

get file path stored in Application.persistentDataPath

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

  1. shb

    shb

    Joined:
    Oct 7, 2012
    Posts:
    23
    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 () {
    3.  
    4.         string vidCachePath =  Application.persistentDataPath + "/vid.mp4";
    5.         Debug.Log ("vidCachePath:" + vidCachePath);
    6.  
    7.         File.WriteAllBytes(vidCachePath, vidRaw.bytes);
    8.  
    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:
    vidCachePath:/idbfs/f8f10363e2c50656aec5544619bc554d/vid.mp4
    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. {
    3.  
    4.     var str = Pointer_stringify(url);
    5.  
    6.     var video = document.createElement('video');
    7.     video.style.display = 'none';
    8.     video.src = str;
    9.  
    10.     return videoInstances.push(video) - 1;
    11. },
    12.  
    How Can I play video inside Application.persistentDataPath that starts with something like /idbfs/XXXX ?