< Summary

Class:DCL.Components.Video.Plugin.WebVideoPlayer
Assembly:DCL.Components.Video
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/Video/Plugins/WebVideoPlayer.cs
Covered lines:77
Uncovered lines:1
Coverable lines:78
Total lines:171
Line coverage:98.7% (77 of 78)
Covered branches:0
Total branches:0
Covered methods:24
Total methods:24
Method coverage:100% (24 of 24)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
WebVideoPlayer(...)0%110100%
WebVideoPlayer(...)0%330100%
Update()0%6.016093.75%
Play()0%330100%
PlayInternal()0%110100%
Pause()0%220100%
SetVolume(...)0%220100%
SetTime(...)0%220100%
SetLoop(...)0%220100%
SetPlaybackRate(...)0%220100%
GetTime()0%220100%
GetDuration()0%330100%
GetState()0%110100%
Dispose()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/Video/Plugins/WebVideoPlayer.cs

#LineLine coverage
 1using System;
 2using UnityEngine;
 3
 4namespace DCL.Components.Video.Plugin
 5{
 6    public class WebVideoPlayer : IDisposable
 7    {
 15478        public Texture2D texture { private set; get; }
 879        public float volume { private set; get; }
 2010        public bool playing => GetState() == VideoState.PLAYING;
 160011        public bool isError => GetState() == VideoState.ERROR;
 10112        public bool visible { get; set; } = true;
 9713        public bool isReady { get; private set; } = false;
 14
 15        public readonly string url;
 16
 17        private string videoPlayerId;
 18
 19        private readonly IVideoPluginWrapper plugin;
 20
 21        private bool playWhenReady = false;
 4622        private float playStartTime = -1;
 23
 4624        private string lastError = "";
 25
 26        public WebVideoPlayer(string id, string url, bool useHls, IVideoPluginWrapper plugin)
 3827            : this(id, url, useHls? VideoType.Hls : VideoType.Common, plugin)
 28        {
 3829        }
 30
 4631        public WebVideoPlayer(string id, string url, VideoType videoType, IVideoPluginWrapper plugin)
 32        {
 4633            videoPlayerId = id;
 4634            this.plugin = plugin;
 4635            this.url = url;
 4636            plugin.Create(id, url, videoType);
 4637        }
 38
 39        public void Update()
 40        {
 20741            switch (plugin.GetState(videoPlayerId))
 42            {
 43                case VideoState.ERROR:
 244                    string newError = plugin.GetError(videoPlayerId);
 45
 246                    if ( newError != lastError )
 47                    {
 248                        lastError = newError;
 249                        Debug.LogError(lastError);
 50                    }
 51
 252                    break;
 53                case VideoState.READY:
 3354                    if (!isReady)
 55                    {
 3156                        isReady = true;
 57
 3158                        texture = plugin.PrepareTexture(videoPlayerId);
 59                    }
 60
 3361                    if (playWhenReady)
 62                    {
 463                        PlayInternal();
 464                        playWhenReady = false;
 65                    }
 66
 467                    break;
 68                case VideoState.PLAYING:
 1469                    if (visible)
 070                        plugin.TextureUpdate(videoPlayerId);
 71
 72                    break;
 73            }
 11574        }
 75
 76        public void Play()
 77        {
 1678            if (isError)
 179                return;
 80
 1581            if (!isReady)
 82            {
 783                playWhenReady = true;
 784                return;
 85            }
 86
 887            PlayInternal();
 888        }
 89
 90        private void PlayInternal()
 91        {
 1292            plugin.Play(videoPlayerId, playStartTime);
 1293            playStartTime = -1;
 1294        }
 95
 96        public void Pause()
 97        {
 2298            if (isError)
 199                return;
 100
 21101            playStartTime = plugin.GetTime(videoPlayerId);
 21102            plugin.Pause(videoPlayerId);
 21103            playWhenReady = false;
 21104        }
 105
 106        public void SetVolume(float volume)
 107        {
 74108            if (isError)
 1109                return;
 110
 73111            plugin.SetVolume(videoPlayerId, volume);
 73112            this.volume = volume;
 73113        }
 114
 115        public void SetTime(float timeSecs)
 116        {
 3117            if (isError)
 1118                return;
 119
 2120            playStartTime = timeSecs;
 2121            plugin.SetTime(videoPlayerId, timeSecs);
 2122        }
 123
 124        public void SetLoop(bool loop)
 125        {
 29126            if (isError)
 1127                return;
 128
 28129            plugin.SetLoop(videoPlayerId, loop);
 28130        }
 131
 132        public void SetPlaybackRate(float playbackRate)
 133        {
 28134            if (isError)
 1135                return;
 136
 27137            plugin.SetPlaybackRate(videoPlayerId, playbackRate);
 27138        }
 139
 140        public float GetTime()
 141        {
 61142            if (isError)
 1143                return 0;
 144
 60145            return plugin.GetTime(videoPlayerId);
 146        }
 147
 148        public float GetDuration()
 149        {
 62150            if (isError)
 1151                return 0;
 152
 61153            float duration = plugin.GetDuration(videoPlayerId);
 154
 61155            if (float.IsNaN(duration))
 1156                duration = -1;
 157
 61158            return duration;
 159        }
 160
 161        public VideoState GetState()
 162        {
 3137163            return (VideoState)plugin.GetState(videoPlayerId);
 164        }
 165
 166        public void Dispose()
 167        {
 12168            plugin.Remove(videoPlayerId);
 12169        }
 170    }
 171}