예제 #1
0
        private void SetImageToThumbnail()
        {
            if (file == null || hasRequestedThumbnail)
            {
                return;
            }

            LRUCache <string, Sprite> thumbnailCache = null;

            thumbnailCache =
                CacheManager.Instance.GetCache <string, Sprite>(THUMBNAIL_CACHE_NAME, THUMBNAIL_CACHE_CAPACITY);

            if (thumbnailCache != null)
            {
                Sprite thumbnail = thumbnailCache.Get(file.FullName);
                if (thumbnail != null)
                {
                    SetThumbnailFromSprite(thumbnail);
                    hasRequestedThumbnail = true;
                    return;
                }
            }

            if (IsInTransition)
            {
                // There was no cached thumbnail so try to load it asynchronously.
                MediaHelpers.GetThumbnail(file.FullName, OnThumbnailLoaded);
                hasRequestedThumbnail = true;
            }
        }
예제 #2
0
   public static void GetVideoFrame(string path, long positionMilliseconds, int frameHeight, Action <Byte[], long> callback)
   {
 #if UNITY_ANDROID && !UNITY_EDITOR
       MediaHelpers.GetAndroidVideoFrame(path, positionMilliseconds, frameHeight, callback);
 #else
       if (callback != null)
       {
           callback(null, 0);
       }
 #endif
   }
예제 #3
0
   public static void GetThumbnail(string path, Action <string, Byte[], bool> callback)
   {
 #if UNITY_ANDROID && !UNITY_EDITOR
       MediaHelpers.GetAndroidThumbnail(path, callback);
 #else
       if (callback != null)
       {
           callback(null, null, false);
       }
 #endif
   }
        private void LoadFrame(long frameMilliseconds)
        {
            activeRequestsCount++;

            string path = playOptions.Path;

            if (path.StartsWith(PATH_PREFIX))
            {
                path = path.Substring(PATH_PREFIX.Length, path.Length - PATH_PREFIX.Length);
            }
            // When the key exists but the value is null we are in the process of fetching this frame
            MediaHelpers.GetVideoFrame(path, frameMilliseconds, FRAME_HEIGHT, OnFrameLoaded);
        }
예제 #5
0
        private void OnThumbnailLoaded(string filePath, byte[] thumbnailBytes, bool cancelled)
        {
            if (file == null)
            {
                return;
            }

            if (file.FullName != filePath)
            {
                return;
            }

            if (thumbnailBytes == null)
            {
                if (cancelled)
                {
                    MediaHelpers.GetThumbnail(file.FullName, OnThumbnailLoaded);
                }
                return;
            }

            Texture2D thumbnail = new Texture2D(2, 2);

            thumbnail.LoadImage(thumbnailBytes);

            Vector2 size = imageTransform.sizeDelta;

            float aspectRatio = size.x / size.y;
            float width       = thumbnail.width;
            float height      = thumbnail.height;

            height = width / aspectRatio;
            if (height > thumbnail.height)
            {
                height = thumbnail.height;
                width  = height * aspectRatio;
            }

            float  rectX           = (thumbnail.width * 0.5f) - (width * 0.5f);
            float  rectY           = (thumbnail.height * 0.5f) - (height * 0.5f);
            Rect   rect            = new Rect(rectX, rectY, width, height);
            Sprite thumbnailSprite = Sprite.Create(thumbnail, rect, new Vector2(0.5f, 0.5f));

            LRUCache <string, Sprite> thumbnailCache = null;

            thumbnailCache =
                CacheManager.Instance.GetCache <string, Sprite>(THUMBNAIL_CACHE_NAME, THUMBNAIL_CACHE_CAPACITY);
            thumbnailCache.Set(file.FullName, thumbnailSprite);

            SetThumbnailFromSprite(thumbnailSprite);
        }
예제 #6
0
        private void LoadFrameAndAnalyze(BaseVideoPlayer videoPlayer)
        {
            string path = videoPlayer.FilePath;

            if (path.StartsWith(PATH_PREFIX))
            {
                path = path.Substring(PATH_PREFIX.Length, path.Length - PATH_PREFIX.Length);
            }

            // Seek to an arbitrary frame in hopes that it has good image data to analyze.
            // and isn't just a black fade transition or something like that.
            long framePositionMilliseconds = videoPlayer.DurationMilliseconds / 4;

            MediaHelpers.GetVideoFrame(path, framePositionMilliseconds, -1, OnFrameLoaded);
        }
예제 #7
0
        private void OnFileChosen(FileInfo file, int fileIndex)
        {
            MediaHelpers.MediaType mediaType = MediaHelpers.GetMediaType(file);

            if (mediaType == MediaHelpers.MediaType.Invalid)
            {
                return;
            }

            CreateMediaPlayer(mediaType);
            TryPlayMedia(mediaType, file, currentPlayer);

            mediaSelectorContainer.SetActive(false);
            currentFileIndex = fileIndex;
        }
예제 #8
0
        private void OnFileChosen(DVDFileInfo file, int fileIndex)
        {
            MediaHelpers.MediaType mediaType = MediaHelpers.GetMediaType(file);
            if (mediaType == MediaHelpers.MediaType.Invalid)
            {
                return;
            }
            //CreateMediaPlayer(mediaType);
            //TryPlayMedia(mediaType, file, currentPlayer);
            if (mediaType == MediaHelpers.MediaType.Video)
            {
                JVideoDescriptionInfo jVideo = new JVideoDescriptionInfo(-1, file.fileName, file.fileUrl, file.fileUrl,
                                                                         0, 0, (int)StereoType.ST3D_LR, 0, 0, System.DateTime.Now, null, null);
                PlayerDataControl.GetInstance().SetJVideoDscpInfoByLiveUrl(jVideo);
                PlayerRoot.SetActive(true);
            }
            else
            {
                return;
            }

            mediaSelectorContainer.SetActive(false);
            currentFileIndex = fileIndex;
        }
예제 #9
0
        private void IncrementFile(bool previousDirection)
        {
            FileSelectorPageProvider fileSelector = GetComponent <FileSelectorPageProvider>();

            Assert.IsNotNull(fileSelector);

            FileInfo[] files = fileSelector.SubFiles;

            if (files == null || files.Length <= 1)
            {
                return;
            }

            if (currentPlayer == null)
            {
                return;
            }

            if (currentFileIndex == -1)
            {
                return;
            }

            int nextIndex;

            if (previousDirection)
            {
                nextIndex = currentFileIndex - 1;
            }
            else
            {
                nextIndex = currentFileIndex + 1;
            }

            if (nextIndex >= files.Length)
            {
                nextIndex = 0;
            }
            else if (nextIndex < 0)
            {
                nextIndex = files.Length - 1;
            }

            FileInfo nextFile = files[nextIndex];

            MediaHelpers.MediaType mediaType = MediaHelpers.GetMediaType(nextFile);

            bool success = TryPlayMedia(mediaType, nextFile, currentPlayer);

            // Wrong media player type.
            if (!success)
            {
                CreateMediaPlayer(mediaType);
                TryPlayMedia(mediaType, nextFile, currentPlayer);
                PlaybackControlsManager playbackControlsManager =
                    currentPlayerObject.GetComponentInChildren <PlaybackControlsManager>();
                if (playbackControlsManager != null)
                {
                    playbackControlsManager.SetPlaybackControlsOpen(true);
                }
            }

            mediaSelectorContainer.SetActive(false);
            currentFileIndex = nextIndex;
        }