public bool StartOpenChunkedMediaFromBuffer(ulong length, bool autoPlay = true)
        {
            _mediaPath       = new MediaPath("buffer", MediaPathType.AbsolutePathOrURL);
            _autoPlayOnStart = autoPlay;

            if (_controlInterface == null)
            {
                Initialise();
            }

            return(StartOpenMediaFromBufferInternal(length));
        }
        public bool OpenMediaFromBuffer(byte[] buffer, bool autoPlay = true)
        {
            _mediaPath       = new MediaPath("buffer", MediaPathType.AbsolutePathOrURL);
            _autoPlayOnStart = autoPlay;

            if (_controlInterface == null)
            {
                Initialise();
            }

            return(OpenMediaFromBufferInternal(buffer));
        }
        void ISerializationCallbackReceiver.OnAfterDeserialize()
        {
            if (!string.IsNullOrEmpty(m_VideoPath))
            {
                MediaPathType mediaPathType = MediaPathType.AbsolutePathOrURL;
                switch (m_VideoLocation)
                {
                default:
                case FileLocation.AbsolutePathOrURL:
                    mediaPathType = MediaPathType.AbsolutePathOrURL;
                    break;

                case FileLocation.RelativeToProjectFolder:
                    mediaPathType = MediaPathType.RelativeToProjectFolder;
                    break;

                case FileLocation.RelativeToStreamingAssetsFolder:
                    mediaPathType = MediaPathType.RelativeToStreamingAssetsFolder;
                    break;

                case FileLocation.RelativeToDataFolder:
                    mediaPathType = MediaPathType.RelativeToDataFolder;
                    break;

                case FileLocation.RelativeToPersistentDataFolder:
                    mediaPathType = MediaPathType.RelativeToPersistentDataFolder;
                    break;
                }
                _mediaPath   = new MediaPath(m_VideoPath, mediaPathType);
                _mediaSource = MediaSource.Path;
                m_VideoPath  = null;
            }

            /*
             * if (m_StereoPacking != _fallbackMediaHints.stereoPacking)
             * {
             *      _fallbackMediaHints.stereoPacking = m_StereoPacking;
             * }
             * if (m_AlphaPacking != _fallbackMediaHints.alphaPacking)
             * {
             *      _fallbackMediaHints.alphaPacking = m_AlphaPacking;
             * }
             */
        }
        private IEnumerator LoadSubtitlesCoroutine(string url, MediaPath mediaPath)
        {
            UnityEngine.Networking.UnityWebRequest www = UnityEngine.Networking.UnityWebRequest.Get(url);
                        #if UNITY_2017_2_OR_NEWER
            yield return(www.SendWebRequest());
                        #else
            yield return(www.Send());
                        #endif

            string subtitleData = string.Empty;

                        #if UNITY_2020_1_OR_NEWER
            if (www.result == UnityEngine.Networking.UnityWebRequest.Result.Success)
                        #elif UNITY_2017_1_OR_NEWER
            if (!www.isNetworkError)
                        #else
            if (!www.isError)
                        #endif
            {
                subtitleData = ((UnityEngine.Networking.DownloadHandler)www.downloadHandler).text;
            }
            else
            {
                Debug.LogError("[AVProVideo] Error loading subtitles '" + www.error + "' from " + url);
            }

            if (_subtitlesInterface.LoadSubtitlesSRT(subtitleData))
            {
                _subtitlePath      = mediaPath;
                _sideloadSubtitles = false;
            }
            else
            {
                Debug.LogError("[AVProVideo] Failed to load subtitles" + url, this);
            }

            _loadSubtitlesRoutine = null;

            www.Dispose();
        }
예제 #5
0
 public MediaPath(MediaPath copy)
 {
     _pathType = copy.PathType;
     _path     = copy.Path;
 }
        public bool EnableSubtitles(MediaPath mediaPath)
        {
            bool result = false;

            if (_subtitlesInterface != null)
            {
                if (mediaPath != null && !string.IsNullOrEmpty(mediaPath.Path))
                {
                    string fullPath = mediaPath.GetResolvedFullPath();

                    bool checkForFileExist = true;
                    if (fullPath.Contains("://"))
                    {
                        checkForFileExist = false;
                    }
#if (!UNITY_EDITOR && UNITY_ANDROID)
                    checkForFileExist = false;
#endif

                    if (checkForFileExist && !System.IO.File.Exists(fullPath))
                    {
                        Debug.LogError("[AVProVideo] Subtitle file not found: " + fullPath, this);
                    }
                    else
                    {
                        Helper.LogInfo("Opening subtitles " + fullPath, this);

                        _previousSubtitleIndex = -1;

                        try
                        {
                            if (fullPath.Contains("://"))
                            {
                                // Use coroutine and WWW class for loading
                                if (_loadSubtitlesRoutine != null)
                                {
                                    StopCoroutine(_loadSubtitlesRoutine);
                                    _loadSubtitlesRoutine = null;
                                }
                                _loadSubtitlesRoutine = StartCoroutine(LoadSubtitlesCoroutine(fullPath, mediaPath));
                            }
                            else
                            {
                                // Load directly from file
                                string subtitleData = System.IO.File.ReadAllText(fullPath);
                                if (_subtitlesInterface.LoadSubtitlesSRT(subtitleData))
                                {
                                    _subtitlePath      = mediaPath;
                                    _sideloadSubtitles = false;
                                    result             = true;
                                }
                                else
                                {
                                    Debug.LogError("[AVProVideo] Failed to load subtitles" + fullPath, this);
                                }
                            }
                        }
                        catch (System.Exception e)
                        {
                            Debug.LogError("[AVProVideo] Failed to load subtitles " + fullPath, this);
                            Debug.LogException(e, this);
                        }
                    }
                }
                else
                {
                    Debug.LogError("[AVProVideo] No subtitle file path specified", this);
                }
            }
            else
            {
                _queueSubtitlePath = mediaPath;
            }

            return(result);
        }