Пример #1
0
        /// <summary>
        /// Play the youtube video in the attached Video Player component.
        /// </summary>
        /// <param name="videoUrl">Youtube url (e.g. https://www.youtube.com/watch?v=VIDEO_ID)</param>
        /// <returns>A Task to await</returns>
        /// <exception cref="NotSupportedException">When the youtube url doesn't contain any supported streams</exception>
        public async Task PlayVideoAsync(string videoUrl = null)
        {
            try
            {
                videoUrl = videoUrl ?? youtubeUrl;

                var metaData = await YoutubeDl.GetVideoMetaDataAsync(videoUrl,
                                                                     is360Video?YoutubeDlOptions.Three60 : YoutubeDlOptions.Default);

                m_VideoPlayer.source = VideoSource.Url;

                //Resetting the same url restarts the video...
                if (m_VideoPlayer.url != metaData.Url)
                {
                    m_VideoPlayer.url = metaData.Url;
                }

                m_VideoPlayer.Play();
                youtubeUrl = videoUrl;
                YoutubeVideoStarting?.Invoke(youtubeUrl);
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
        }
Пример #2
0
        public async Task PlayVideoAsync(string videoUrl = null)
        {
            try
            {
                //videoUrl = videoUrl ?? youtubeUrl;
                var videoId = GetVideoId(videoUrl);
                Debug.Log(videoId);
                var streamInfoSet = await youtubeClient.GetVideoMediaStreamInfosAsync(videoId);

                var streamInfo = streamInfoSet.WithHighestVideoQualitySupported();
                if (streamInfo == null)
                {
                    throw new NotSupportedException($"No supported streams in youtube video '{videoId}'");
                }

                videoPlayer.source = VideoSource.Url;

                //Resetting the same url restarts the video...
                if (videoPlayer.url != streamInfo.Url)
                {
                    videoPlayer.url = streamInfo.Url;
                }

                videoPlayer.Play();
                youtubeUrl = videoUrl;
                YoutubeVideoStarting?.Invoke(youtubeUrl);
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
        }
Пример #3
0
        public async Task PlayVideoAsync(string videoUrl = null)
        {
            try
            {
                videoUrl = videoUrl ?? youtubeUrl;
                var streamManifest = await youtubeClient.Videos.Streams.GetManifestAsync(videoUrl);

                // var streamInfo = streamManifest.WithHighestVideoQualitySupported();
                var videoQuality = streamManifest.GetVideoQualityList();
                if (labels.Count == 0)
                {
                    foreach (var v in videoQuality)
                    {
                        labels.Add(v.ToString());
                    }
                    dropdownResolution.ClearOptions();
                    dropdownResolution.AddOptions(labels);
                    qualityChoosen = 0;
                }
                var streamInfo = streamManifest.WithCustomVideoQualitySupported(videoQuality[qualityChoosen]);
                if (streamInfo == null)
                {
                    throw new NotSupportedException($"No supported streams in youtube video '{videoUrl}'");
                }

                videoPlayer.source = VideoSource.Url;

                //Resetting the same url restarts the video...
                if (videoPlayer.url != streamInfo.Url)
                {
                    videoPlayer.url = streamInfo.Url;
                }

                videoPlayer.Play();
                youtubeUrl = videoUrl;
                YoutubeVideoStarting?.Invoke(youtubeUrl);
                videoPlayer.Stop();
                ready = true;
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
        }
        /// <summary>
        /// Play the youtube video in the attached Video Player component.
        /// </summary>
        /// <param name="videoUrl">Youtube url (e.g. https://www.youtube.com/watch?v=VIDEO_ID)</param>
        /// <returns>A Task to await</returns>
        /// <exception cref="NotSupportedException">When the youtube url doesn't contain any supported streams</exception>
        public async Task PlayVideoAsync(string videoUrl = null)
        {
            try
            {
                if (overrideURLWithInputField && !string.IsNullOrEmpty(m_inputField.text))
                {
                    youtubeUrl = m_inputField.text;
                }

                OnVideoLoad.Invoke();

                videoUrl = videoUrl ?? youtubeUrl;
                var videoId       = GetVideoId(videoUrl);
                var streamInfoSet = await youtubeClient.GetVideoMediaStreamInfosAsync(videoId);

                var streamInfo = streamInfoSet.WithHighestVideoQualitySupported();
                if (streamInfo == null)
                {
                    OnVideoPlay.Invoke();
                    throw new NotSupportedException($"No supported streams in youtube video '{videoId}'");
                }

                videoPlayer.source = VideoSource.Url;

                //Resetting the same url restarts the video...
                if (videoPlayer.url != streamInfo.Url)
                {
                    videoPlayer.url = streamInfo.Url;
                }

                videoPlayer.Play();
                youtubeUrl = videoUrl;
                YoutubeVideoStarting?.Invoke(youtubeUrl);
                OnVideoPlay.Invoke();
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
                OnEndDownload.Invoke();
            }
        }
Пример #5
0
        /// <summary>
        /// Play the youtube video in the attached Video Player component.
        /// </summary>
        /// <param name="videoUrl">Youtube url (e.g. https://www.youtube.com/watch?v=VIDEO_ID)</param>
        /// <returns>A Task to await</returns>
        /// <exception cref="NotSupportedException">When the youtube url doesn't contain any supported streams</exception>
        public async Task PlayVideoAsync(string videoUrl = null)
        {
            try
            {
                videoUrl = videoUrl ?? youtubeUrl;
                var videoId       = GetVideoId(videoUrl);
                var streamInfoSet = await youtubeClient.GetVideoMediaStreamInfosAsync(videoId);

                var streamInfo = streamInfoSet.WithHighestVideoQualitySupported();
                if (streamInfo == null)
                {
                    throw new NotSupportedException($"No supported streams in youtube video '{videoId}'");
                }

                videoPlayer = gameObject.GetComponent <VideoPlayer>();
                audioSource = gameObject.GetComponent <AudioSource>();
                //Set Audio Output to AudioSource
                videoPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource;

                //Assign the Audio from Video to AudioSource to be played
                videoPlayer.EnableAudioTrack(0, true);
                videoPlayer.SetTargetAudioSource(0, audioSource); videoPlayer.source = VideoSource.Url;

                //Resetting the same url restarts the video...
                if (videoPlayer.url != streamInfo.Url)
                {
                    videoPlayer.url = streamInfo.Url;
                }
                videoPlayer.playbackSpeed = 1;
                videoPlayer.Play();
                youtubeUrl = videoUrl;
                YoutubeVideoStarting?.Invoke(youtubeUrl);
                youtubeVideoStartedEvent?.Invoke();
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
        }