Exemple #1
0
        async UniTask PlayVideo(string url)
        {
            _mediaPlayer.VideoSource = url;

            // Start observing OnMediaError before PrepareVideo because
            // PrepareVideo itself can trigger MediaError events
            var error    = _mediaPlayer.OnMediaErrorAsObservable().ToUniTask(useFirstValue: true);
            var complete = _mediaPlayer.OnVideoPreparedAsObservable().ToUniTask(useFirstValue: true);

            _mediaPlayer.PrepareVideo().ThrowIfFail();

            // Throw exception in case an error happens,
            // otherwise wait until preparation is completed
            await UniTask.WhenAny(error, complete);

            // Play video
            _mediaPlayer.IsLooping = true;
            _mediaPlayer.Play().ThrowIfFail();
        }