Exemplo n.º 1
0
        /// <summary>
        /// Iterates over all video sources in the current study and hands them over to the ViewContainerManager
        /// </summary>
        /// <param name="currentStudy">The <see cref="StudyData"/> of the current data.</param>
        private void PrepareMedia(StudyData currentStudy)
        {
            List <MediaSource> media = new List <MediaSource>();

            foreach (var mediaSource in currentStudy.MediaSources)
            {
                if (mediaSource.File.StartsWith("https"))
                {
                    media.Add(mediaSource);
                }
                else
                {
                    string filePath = Path.Combine(dataPath, mediaSource.File);
                    if (System.IO.File.Exists(filePath))
                    {
#if UNITY_WSA && !UNITY_EDITOR
                        // As per https://forum.unity.com/threads/url-for-videoplayer-in-uwp.503331/ we copy the file to Application.persistentDataPath, otherwise we get file access violations on UWP/WSA.
                        string wsaFilePath = Path.Combine(Application.persistentDataPath, Math.Abs(filePath.GetHashCode()).ToString() + "_" + Path.GetFileName(filePath));
                        System.IO.File.Copy(filePath, wsaFilePath, true);
                        mediaSource.File = wsaFilePath;
                        media.Add(mediaSource);
#else
                        mediaSource.File = filePath;
                        media.Add(mediaSource);
#endif
                    }
                }
            }

            Services.ContainerManager().UpdateVideoSources(media);
        }