5.6 VideoPlayer to play captured videos?

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

What path are you trying to load them from?

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.

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?

I’m not aware of another API that allows you to handle files with windows store applications. I’ve followed the microsoft documentation here:

and

I’ve also verified that pictures are checked in the app manifest, which according to MS documentation should give access to the camera roll. Any other ideas?

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})

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:

using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.Video;

#if WINDOWS_UWP
    using Windows.Storage;
    using Windows.Storage.Search;
    using Windows.System;
    using System.Collections.Generic;
    using System;
#endif

public class VideoLoading : MonoBehaviour
{

    string cameraFolderPath;
    bool videosLoaded = false;

#if WINDOWS_UWP
    IReadOnlyList<StorageFile> videoFiles;
#endif

    void Awake ()
    {

#if WINDOWS_UWP
        FindAllVideosInCameraRoll();

        while (!videosLoaded)
        {
            Debug.Log("Waiting for videos to be loaded...");
        }

        if (videoFiles.Count > 0)
        {
            //For now we will just play the first video available for debugging purposes.
            Debug.Log("Loading movie from list: " + videoFiles[0].Path);
            StartCoroutine(LoadVideoFromFile(videoFiles[0].Path));
        }
#endif

    }

#if WINDOWS_UWP

     async void FindAllVideosInCameraRoll()
    {

        QueryOptions queryOption = new QueryOptions
        (CommonFileQuery.OrderByTitle, new string[] {".mp4"});

        queryOption.FolderDepth = FolderDepth.Deep;

        cameraFolderPath = KnownFolders.CameraRoll.Path;

        videoFiles  = await KnownFolders.CameraRoll.CreateFileQueryWithOptions
          (queryOption).GetFilesAsync();

        foreach (StorageFile file in videoFiles)
        {
            Debug.Log("Found video file: " + file.Path);
        }

        videosLoaded = true;

    }
#endif

    IEnumerator LoadVideoFromFile(string fileName)
    {
        string videoPath = Path.Combine(cameraFolderPath, fileName);

        Debug.Log("Playing Video at " + videoPath);

        VideoPlayer videoplayer = this.GetComponent<VideoPlayer>();
        videoplayer.url = videoPath;
        videoplayer.Prepare();
        videoplayer.Play();

        yield return null;

    }
}

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.

1 Like

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.

You might want to try taking a look at the rest APIs

Link:

Look for mixed reality capture