Ejemplo n.º 1
0
 private async void Service_VideoPlaybackStateChanged(object sender, VideoPlaybackState state)
 {
     await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
     {
         VisualStateManager.GoToState(this, state == VideoPlaybackState.Playing ? "ShowVideo" : "PickChannel", true);
     });
 }
Ejemplo n.º 2
0
    //These events can be used for controlling the other application, for example UI, etc
    private void MPlay_OnPlayModeChanged(VideoPlaybackState state)
    {
        Debug.Log("VideoPlaybackState: " + state.ToString());

        if (state == VideoPlaybackState.END_OF_FILE)
        {
            _play.SeekTo(0);
            _play.Play();
        }
        if (_loadingIndicator)
        {
            if (state == VideoPlaybackState.PLAYING)
            {
                _loadingIndicator.SetActive(false);
            }
            else
            {
                _loadingIndicator.SetActive(true);
            }
        }
    }
Ejemplo n.º 3
0
        private async Task SetPlaybackStateAsync(VideoPlaybackState state)
        {
            string function = string.Empty;

            switch (state)
            {
            case VideoPlaybackState.Stopped:
                function = "stop";
                break;

            case VideoPlaybackState.Playing:
                function = "play";
                break;

            case VideoPlaybackState.Paused:
                function = "pause";
                break;
            }

            await webView?.InvokeScriptAsync(function, null);
        }
        /// <summary>
        /// A copy method for a TMDbDetail class instance.
        /// </summary>
        /// <param name="detail">A TMDbDetail class instance to construct a TMDbDetailExt class instance.</param>
        /// <param name="duration">A video duration in milliseconds.</param>
        /// <param name="fileNameFull">A full file name for a video this class would represent of.</param>
        /// <param name="imageFileCache">if set to <c>true</c> the class uses file system for caching image files.</param>
        /// <param name="imageFileCacheDir">A full path to use for the image file cache.</param>
        /// <param name="image">A poster/still image which represents the video file. If set to null a web download is tried.</param>
        /// <param name="videoPlaybackState">Indicates the state of how the video was interacted with before.</param>
        /// <returns>A TMDbDetailExt class instance containing the data from the given TMDbDetail class instance.</returns>
        public static TMDbDetailExt FromTMDbDetail(TMDbDetail detail, int duration,
                                                   string fileNameFull, bool imageFileCache, string imageFileCacheDir, Image image, VideoPlaybackState videoPlaybackState)
        {
            // create a new TMDbDetailExt class instance..
            TMDbDetailExt result = new TMDbDetailExt
            {
                // copy the data..
                Description       = detail.Description,
                Episode           = detail.Episode,
                EpisodeID         = detail.EpisodeID,
                DetailDescription = detail.DetailDescription,
                FileName          = detail.FileName,
                ID = detail.ID,
                PosterOrStillURL = detail.PosterOrStillURL,
                Season           = detail.Season,
                SeasonID         = detail.SeasonID,
                Title            = detail.Title
                                   // END: copy the data..
            };

            if (image == null) // if the given image parameter was null try to download the image from the web..
            {
                try
                {
                    // download the image data from the web..
                    using (WebClient webClient = new WebClient())
                    {
                        // download the data as byte array..
                        byte[] imageData = webClient.DownloadData(result.PosterOrStillURL);
                        // using (MemoryStream ms = new MemoryStream(imageData)) Exception: A generic error occurred in GDI+

                        // construct a MemoryStream instance of the downloaded image data..
                        MemoryStream ms = new MemoryStream(imageData);

                        // set the image..
                        result.Image = Image.FromStream(ms);
                    }
                }
                catch
                {
                }
            }
            else // an image was given..
            {
                result.Image = image; // ..so set the image..
            }

            // if there is no TMDb ID for the video and the given image was null the image will be null..
            if (detail.ID == -1 && image == null)
            {
                result.Image = null;
            }

            // set the previous playback state of the video..
            result.VideoPlaybackState = videoPlaybackState;

            // set the duration..
            result.Duration = TimeSpan.FromMilliseconds(duration);

            try // try to set the file size of the video..
            {
                result.FileSize = new FileInfo(fileNameFull).Length;
            }
            catch
            {
                result.FileSize = 0;
            }

            // set the file system caching value..
            result.ImageFileCache = imageFileCache;

            // set the file system cache path..
            result.ImageFileCacheDir = imageFileCacheDir;

            // dump the image to the file system cache path if "conditions" are met..
            result.DumpImage();

            return(result); // return the TMDbDetailExt class instance
        }
Ejemplo n.º 5
0
    // Update is called once per frame
    void Update()
    {
        if (null == _play)
        {
            return;
        }

        if (0 == _videoFiles.Length)
        {
            return;
        }

        if (Input.GetKeyDown(KeyCode.Escape))
        {
#if UNITY_EDITOR
            UnityEditor.EditorApplication.isPlaying = false;
#else
            Application.Quit();
#endif
        }
#if (UNITY_EDITOR_WIN || UNITY_EDITOR_OSX || UNITY_STANDALONE || UNITY_STANDALONE_OSX)
        //controls
        else if (Input.GetKey(KeyCode.LeftArrow))
        {
            _rotationOffset *= Quaternion.Euler(0.0f, -1.0f, 0.0f);
            _play.SetViewRotationOffset(_rotationOffset);
        }
        else if (Input.GetKey(KeyCode.RightArrow))
        {
            _rotationOffset *= Quaternion.Euler(0.0f, 1.0f, 0.0f);
            _play.SetViewRotationOffset(_rotationOffset);
        }
        else if (Input.GetKey(KeyCode.UpArrow))
        {
            _rotationOffset *= Quaternion.Euler(-1.0f, 0.0f, 0.0f);
            _play.SetViewRotationOffset(_rotationOffset);
        }
        else if (Input.GetKey(KeyCode.DownArrow))
        {
            _rotationOffset *= Quaternion.Euler(1.0f, 0.0f, 0.0f);
            _play.SetViewRotationOffset(_rotationOffset);
        }
        else if (Input.GetKey(KeyCode.Return))
        {
            _rotationOffset = Quaternion.identity;
            _play.SetViewRotationOffset(_rotationOffset);
        }
#else
        _play.SetViewRotationOffset(_rotationOffset); //this could be set with some input values
#endif

        /*Tim ~ Something is different in this instance of Unity that is causing the Main Camera to be Null in 2017.1.1,
         * I can only say that my experience with unity camera enumeration and recognition how shown a lot of inconsistent behavior.*/

        //Camera.main.transform.parent.transform.rotation = _rotationOffset;
        //Camera.allCameras[0].transform.parent.transform.rotation = _rotationOffset;

        bool pressed = Input.GetButtonDown("Fire1");

        VideoPlaybackState state = VideoPlaybackState.INVALID;
        //simple input controls
        if (_startPlay && null != _play && Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.Space) || pressed)
        {
            state = _play.GetCurrentVideoPlaybackState();
            if (state == VideoPlaybackState.PLAYING)
            {
                _play.Stop();
            }
            _startPlay = true;
        }

        //begin the playback when the player is in good state (ie. previous video has been stopped)
        if (_startPlay)
        {
            state = _play.GetCurrentVideoPlaybackState();
            if ((VideoPlaybackState.IDLE == state))
            {
                _startPlay  = false;
                _videoIndex = (_videoIndex + 1) % _videoFiles.Length;

                if (!_play.LoadVideo(_videoFiles [_videoIndex]))
                {
                    Debug.LogError("Error: Could not load! (" + _play.GetLastError().ToString() + ")");
                    return;
                }
                //start playing when the file/stream is ready
                if (!_play.Play())
                {
                    Debug.LogError("Error: Could not start the playback! (" + _play.GetLastError().ToString() + ")");
                    return;
                }
            }
        }
    }
Ejemplo n.º 6
0
 private void VideoPlaybackStateChanged(object sender, VideoPlaybackState state)
 {
     _SynchronizationContext.Post((o) => { PlaybackState = state; }, null);
 }