Exemple #1
0
    public static IEnumerator PlayVideo(Media media, VideoPlayer videoPlayer, Vector2 size, bool enableAudio, MediaPlayCallback callback = null)
    {
        RawImage rawImage = videoPlayer.transform.Find("RawImage").GetComponent <RawImage>();

        if (enableAudio)
        {
            videoPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource;
        }
        videoPlayer.playOnAwake = false;
        videoPlayer.isLooping   = true;
        videoPlayer.source      = VideoSource.Url;
        videoPlayer.url         = media.video_info.variants.OrderByDescending(variant => variant.bitrate).First().url;
        videoPlayer.Prepare();

        while (!videoPlayer.isPrepared)
        {
            yield return(new WaitForSeconds(1));
        }

        rawImage.texture = videoPlayer.texture;
        rawImage.SetNativeSize();
        yield return(SetTextureSize(videoPlayer.transform, size));

        videoPlayer.Play();

        if (callback != null)
        {
            callback();
        }
    }
Exemple #2
0
    public static IEnumerator PlayPhoto(Transform target, string imageURL, Vector2 size, MediaPlayCallback callback = null)
    {
        yield return(SetTexture(
                         target.Find("RawImage"),
                         imageURL,
                         true
                         ));

        yield return(SetTextureSize(target, size));

        if (callback != null)
        {
            callback();
        }
    }