Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

5.6 VideoPlayer to play captured videos?

Discussion in 'VR' started by shaddad, Apr 5, 2017.

  1. shaddad

    shaddad

    Joined:
    Dec 1, 2016
    Posts:
    23
    Hi All,

    Has anyone had any luck using the new video player to play videos captured in the photo library on the hololens? I can play media included in the build, or mp4s online great, but when I try to access videos on the HoloLens I am getting a cryptic access is denied error.

    Thanks,
    Sam
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,628
    What path are you trying to load them from?
     
  3. shaddad

    shaddad

    Joined:
    Dec 1, 2016
    Posts:
    23
    I'm making a call to Windows.Storage.StorageLibrary.GetLibraryAsync(Windows.Storage.KnownLibraryId.Pictures) to get the pictures storage location, then searching the Camera Roll folder for mp4 files. I'm then setting the full video path to the url member of the video player.
     
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,628
    I don't think windows store applications are allowed to read from that path directly. Does it work if you try to just read from that path using C# File APIs?
     
  5. shaddad

    shaddad

    Joined:
    Dec 1, 2016
    Posts:
    23
  6. Unity_Wesley

    Unity_Wesley

    Unity Technologies

    Joined:
    Sep 17, 2015
    Posts:
    558
    I have had better luck with the method using the File System in System.IO. This allows me to read and write files to the Hololens.

    example file path string
    string filePath = Path.Combine(Application.persistentDataPath, {File Name})
     
  7. shaddad

    shaddad

    Joined:
    Dec 1, 2016
    Posts:
    23
    Thanks guys for your help, but I think there is something still I may be missing. I am able to get the string path to the video which appears correct:

    C:\Data\Users\HoloLens\Pictures\Camera Roll\20170329_140000_HoloLens.mp4

    I then set this path to the video player url. I then get this exception:

    WindowsVideoMedia error 0x80070005 while reading C:\Data\Users\HoloLens\Pictures\Camera Roll\20170329_140000_HoloLens.mp4

    Context: MFCreateSourceReaderFromURL
    Error details: Access is denied.

    Unless there is another way to get a different string path to the same file that would have read permissions I am not sure what else to try. Perhaps there is a way to open the file and assign it as a video clip instead of as a url? I am not sure if that is possible though.

    My code is below:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using System.IO;
    4. using UnityEngine;
    5. using UnityEngine.Video;
    6.  
    7. #if WINDOWS_UWP
    8.     using Windows.Storage;
    9.     using Windows.Storage.Search;
    10.     using Windows.System;
    11.     using System.Collections.Generic;
    12.     using System;
    13. #endif
    14.  
    15. public class VideoLoading : MonoBehaviour
    16. {
    17.  
    18.     string cameraFolderPath;
    19.     bool videosLoaded = false;
    20.  
    21. #if WINDOWS_UWP
    22.     IReadOnlyList<StorageFile> videoFiles;
    23. #endif
    24.  
    25.     void Awake ()
    26.     {
    27.  
    28. #if WINDOWS_UWP
    29.         FindAllVideosInCameraRoll();
    30.  
    31.         while (!videosLoaded)
    32.         {
    33.             Debug.Log("Waiting for videos to be loaded...");
    34.         }
    35.  
    36.         if (videoFiles.Count > 0)
    37.         {
    38.             //For now we will just play the first video available for debugging purposes.
    39.             Debug.Log("Loading movie from list: " + videoFiles[0].Path);
    40.             StartCoroutine(LoadVideoFromFile(videoFiles[0].Path));
    41.         }
    42. #endif
    43.  
    44.     }
    45.  
    46. #if WINDOWS_UWP
    47.  
    48.      async void FindAllVideosInCameraRoll()
    49.     {
    50.  
    51.         QueryOptions queryOption = new QueryOptions
    52.         (CommonFileQuery.OrderByTitle, new string[] {".mp4"});
    53.  
    54.         queryOption.FolderDepth = FolderDepth.Deep;
    55.  
    56.         cameraFolderPath = KnownFolders.CameraRoll.Path;
    57.  
    58.         videoFiles  = await KnownFolders.CameraRoll.CreateFileQueryWithOptions
    59.           (queryOption).GetFilesAsync();
    60.  
    61.         foreach (StorageFile file in videoFiles)
    62.         {
    63.             Debug.Log("Found video file: " + file.Path);
    64.         }
    65.  
    66.         videosLoaded = true;
    67.  
    68.     }
    69. #endif
    70.  
    71.     IEnumerator LoadVideoFromFile(string fileName)
    72.     {
    73.         string videoPath = Path.Combine(cameraFolderPath, fileName);
    74.  
    75.         Debug.Log("Playing Video at " + videoPath);
    76.  
    77.         VideoPlayer videoplayer = this.GetComponent<VideoPlayer>();
    78.         videoplayer.url = videoPath;
    79.         videoplayer.Prepare();
    80.         videoplayer.Play();
    81.  
    82.         yield return null;
    83.  
    84.     }
    85. }
    86.  
     
  8. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,628
    What Wesley suggested was that you don't save the video to pictures library. Instead, save it to Application.persistentDataPath, which can be read from and written to freely.
     
  9. shaddad

    shaddad

    Joined:
    Dec 1, 2016
    Posts:
    23
    I see. I will try it out, but this will change the requirements for our project, since the thought was that they would be able to import recorded videos from the HoloLens' video capture into our app. Thanks for your help.
     
  10. Unity_Wesley

    Unity_Wesley

    Unity Technologies

    Joined:
    Sep 17, 2015
    Posts:
    558