< Summary

Class:DCL.Components.Video.Plugin.WebVideoPlayer
Assembly:MainScripts
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/Video/Plugins/WebVideoPlayer.cs
Covered lines:72
Uncovered lines:4
Coverable lines:76
Total lines:166
Line coverage:94.7% (72 of 76)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
WebVideoPlayer(...)0%110100%
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    {
 08        public Texture2D texture { private set; get; }
 09        public float volume { private set; get; }
 110        public bool playing => GetState() == VideoState.PLAYING;
 67711        public bool isError => GetState() == VideoState.ERROR;
 3112        public bool visible { get; set; } = true;
 013        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;
 3122        private float playStartTime = -1;
 23
 3124        private string lastError = "";
 25
 3126        public WebVideoPlayer(string id, string url, bool useHls, IVideoPluginWrapper plugin)
 27        {
 3128            videoPlayerId = id;
 3129            this.plugin = plugin;
 3130            this.url = url;
 3131            plugin.Create(id, url, useHls);
 3132        }
 33
 34        public void Update()
 35        {
 7736            switch (plugin.GetState(videoPlayerId))
 37            {
 38                case VideoState.ERROR:
 239                    string newError = plugin.GetError(videoPlayerId);
 40
 241                    if ( newError != lastError )
 42                    {
 243                        lastError = newError;
 244                        Debug.LogError(lastError);
 45                    }
 46
 247                    break;
 48                case VideoState.READY:
 1949                    if (!isReady)
 50                    {
 1951                        isReady = true;
 52
 1953                        texture = plugin.PrepareTexture(videoPlayerId);
 54                    }
 55
 1956                    if (playWhenReady)
 57                    {
 158                        PlayInternal();
 159                        playWhenReady = false;
 60                    }
 61
 162                    break;
 63                case VideoState.PLAYING:
 264                    if (visible)
 065                        plugin.TextureUpdate(videoPlayerId);
 66
 67                    break;
 68            }
 5369        }
 70
 71        public void Play()
 72        {
 1173            if (isError)
 174                return;
 75
 1076            if (!isReady)
 77            {
 378                playWhenReady = true;
 379                return;
 80            }
 81
 782            PlayInternal();
 783        }
 84
 85        private void PlayInternal()
 86        {
 887            plugin.Play(videoPlayerId, playStartTime);
 888            playStartTime = -1;
 889        }
 90
 91        public void Pause()
 92        {
 1693            if (isError)
 194                return;
 95
 1596            playStartTime = plugin.GetTime(videoPlayerId);
 1597            plugin.Pause(videoPlayerId);
 1598            playWhenReady = false;
 1599        }
 100
 101        public void SetVolume(float volume)
 102        {
 54103            if (isError)
 1104                return;
 105
 53106            plugin.SetVolume(videoPlayerId, volume);
 53107            this.volume = volume;
 53108        }
 109
 110        public void SetTime(float timeSecs)
 111        {
 3112            if (isError)
 1113                return;
 114
 2115            playStartTime = timeSecs;
 2116            plugin.SetTime(videoPlayerId, timeSecs);
 2117        }
 118
 119        public void SetLoop(bool loop)
 120        {
 18121            if (isError)
 1122                return;
 123
 17124            plugin.SetLoop(videoPlayerId, loop);
 17125        }
 126
 127        public void SetPlaybackRate(float playbackRate)
 128        {
 17129            if (isError)
 1130                return;
 131
 16132            plugin.SetPlaybackRate(videoPlayerId, playbackRate);
 16133        }
 134
 135        public float GetTime()
 136        {
 47137            if (isError)
 1138                return 0;
 139
 46140            return plugin.GetTime(videoPlayerId);
 141        }
 142
 143        public float GetDuration()
 144        {
 48145            if (isError)
 1146                return 0;
 147
 47148            float duration = plugin.GetDuration(videoPlayerId);
 149
 47150            if (float.IsNaN(duration))
 1151                duration = -1;
 152
 47153            return duration;
 154        }
 155
 156        public VideoState GetState()
 157        {
 1253158            return (VideoState)plugin.GetState(videoPlayerId);
 159        }
 160
 161        public void Dispose()
 162        {
 2163            plugin.Remove(videoPlayerId);
 2164        }
 165    }
 166}