<commit_before>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;

/// <summary>
/// This class handles all the full-screen videos in the launcher.
/// </summary>
public class VideoManager : MonoBehaviour {

    public enum VideoState { Loading, Playing, Stopped }
    public VideoState state = VideoState.Stopped;

    public VideoPlayer player;
    public AudioSource audioSource;
    public string currentVideo;

    /// <summary>
    /// Plays a new video in the background.
    /// </summary>
    /// <param name="newVideo">A VideoClip to play in the background.</param>
    /// <param name="loop">Whether the video should loop.</param>
    /// <param name="audioClip">If there is a audio component to the video.</param>
    /// <returns>Whether it was successful.</returns>
    public void PlayVideo(string url, bool loop, bool playAudio)
    {
        StopVideo();

        if (url != "" && url != null)
        {
            state = VideoState.Loading;

            currentVideo = url;
            player.isLooping = loop;
            audioSource.enabled = playAudio;

            StartCoroutine(playVideo(url));
        }
    }

    /// <summary>
    /// Overloaded method where it assumes that there is no audio with the video.
    /// </summary>
    /// <param name="newVideo"></param>
    /// <param name="loop"></param>
    public void PlayVideo(VideoClip newVideo, bool loop, bool playAudio)
    {
        PlayVideo(newVideo.originalPath, loop, playAudio);
    }

    IEnumerator playVideo(string url)
    {
        //Disable Play on Awake for both Video and Audio
        player.playOnAwake = true;
        audioSource.playOnAwake = true;

        //We want to play from video clip not from url
        player.source = VideoSource.Url;
        player.url = currentVideo;

        //Set video To Play then prepare Audio to prevent Buffering
        player.Prepare();

        //Wait until video is prepared
        while (!player.isPrepared)
        {
            Debug.Log("Preparing Video");
            yield return null;
        }

        Debug.Log("Done Preparing Video");

        //Play Video
        state = VideoState.Playing;
        player.Play();

        Debug.Log("Playing Video");
        while (player.isPlaying)
        {
            Debug.LogWarning("Video Time: " + Mathf.FloorToInt((float)player.time));
            yield return null;
        }

        Debug.Log("Done Playing Video");

        state = VideoState.Stopped;<commit_msg>Cut down on VideoManager logs.<commit_after>﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;

/// <summary>
/// This class handles all the full-screen videos in the launcher.
/// </summary>
public class VideoManager : MonoBehaviour {

    public enum VideoState { Loading, Playing, Stopped }
    public VideoState state = VideoState.Stopped;

    public VideoPlayer player;
    public AudioSource audioSource;
    public string currentVideo;

    /// <summary>
    /// Plays a new video in the background.
    /// </summary>
    /// <param name="newVideo">A VideoClip to play in the background.</param>
    /// <param name="loop">Whether the video should loop.</param>
    /// <param name="audioClip">If there is a audio component to the video.</param>
    /// <returns>Whether it was successful.</returns>
    public void PlayVideo(string url, bool loop, bool playAudio)
    {
        StopVideo();

        if (url != "" && url != null)
        {
            state = VideoState.Loading;

            currentVideo = url;
            player.isLooping = loop;
            audioSource.enabled = playAudio;

            StartCoroutine(playVideo(url));
        }
    }

    /// <summary>
    /// Overloaded method where it assumes that there is no audio with the video.
    /// </summary>
    /// <param name="newVideo"></param>
    /// <param name="loop"></param>
    public void PlayVideo(VideoClip newVideo, bool loop, bool playAudio)
    {
        PlayVideo(newVideo.originalPath, loop, playAudio);
    }

    IEnumerator playVideo(string url)
    {
        //Disable Play on Awake for both Video and Audio
        player.playOnAwake = true;
        audioSource.playOnAwake = true;

        //We want to play from video clip not from url
        player.source = VideoSource.Url;
        player.url = currentVideo;

        //Set video To Play then prepare Audio to prevent Buffering
        player.Prepare();

        GM.Instance.logger.Debug("Preparing Video " + url);
        
        //Wait until video is prepared
        while (!player.isPrepared)
        {
            
            yield return null;
        }

        GM.Instance.logger.Debug("Done Preparing Video " + url);

        //Play Video
        state = VideoState.Playing;
        player.Play();

        GM.Instance.logger.Debug("Playing Video " + url);
        while (player.isPlaying)
        {
            // Debug.LogWarning("Video Time: " + Mathf.FloorToInt((float)player.time));
            yield return null;
        }

        GM.Instance.logger.Debug("Done Playing Video " + url);

        state = VideoState.Stopped;
{'fraction_non_alphanumeric': 0.10997294163123308, 'fraction_numerical': 0.0, 'mean_word_length': 2.165137614678899, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4998167', 'n_tokens_mistral': 1399, 'n_tokens_neox': 1351, 'n_words': 423}