< 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:69
Uncovered lines:4
Coverable lines:73
Total lines:158
Line coverage:94.5% (69 of 73)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
WebVideoPlayer(...)0%110100%
Update()0%6.116085.71%
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;
 18611        public bool isError => GetState() == VideoState.ERROR;
 3112        public bool visible { get; set; } = true;
 13
 14        public readonly string url;
 15
 16        private string videoPlayerId;
 17
 18        private readonly IVideoPluginWrapper plugin;
 19
 20        private bool isReady = false;
 21        private bool playWhenReady = false;
 3122        private float playStartTime = -1;
 23
 3124        public WebVideoPlayer(string id, string url, bool useHls, IVideoPluginWrapper plugin)
 25        {
 3126            videoPlayerId = id;
 3127            this.plugin = plugin;
 3128            this.url = url;
 3129            texture = new Texture2D(1, 1);
 3130            plugin.Create(id, url, useHls);
 3131        }
 32
 33        public void Update()
 34        {
 6335            switch (plugin.GetState(videoPlayerId))
 36            {
 37                case VideoState.ERROR:
 238                    Debug.LogError(plugin.GetError(videoPlayerId));
 239                    break;
 40                case VideoState.READY:
 2041                    if (!isReady)
 42                    {
 1143                        isReady = true;
 1144                        texture.UpdateExternalTexture((IntPtr)plugin.GetTexture(videoPlayerId));
 1145                        texture.Apply();
 46                    }
 47
 2048                    if (playWhenReady)
 49                    {
 150                        PlayInternal();
 151                        playWhenReady = false;
 52                    }
 53
 154                    break;
 55                case VideoState.PLAYING:
 056                    if (visible)
 057                        plugin.TextureUpdate(videoPlayerId);
 58
 59                    break;
 60            }
 3761        }
 62
 63        public void Play()
 64        {
 1165            if (isError)
 166                return;
 67
 1068            if (!isReady)
 69            {
 670                playWhenReady = true;
 671                return;
 72            }
 73
 474            PlayInternal();
 475        }
 76
 77        private void PlayInternal()
 78        {
 579            plugin.Play(videoPlayerId, playStartTime);
 580            playStartTime = -1;
 581        }
 82
 83        public void Pause()
 84        {
 1685            if (isError)
 186                return;
 87
 1588            playStartTime = plugin.GetTime(videoPlayerId);
 1589            plugin.Pause(videoPlayerId);
 1590            playWhenReady = false;
 1591        }
 92
 93        public void SetVolume(float volume)
 94        {
 3995            if (isError)
 196                return;
 97
 3898            plugin.SetVolume(videoPlayerId, volume);
 3899            this.volume = volume;
 38100        }
 101
 102        public void SetTime(float timeSecs)
 103        {
 3104            if (isError)
 1105                return;
 106
 2107            playStartTime = timeSecs;
 2108            plugin.SetTime(videoPlayerId, timeSecs);
 2109        }
 110
 111        public void SetLoop(bool loop)
 112        {
 18113            if (isError)
 1114                return;
 115
 17116            plugin.SetLoop(videoPlayerId, loop);
 17117        }
 118
 119        public void SetPlaybackRate(float playbackRate)
 120        {
 17121            if (isError)
 1122                return;
 123
 16124            plugin.SetPlaybackRate(videoPlayerId, playbackRate);
 16125        }
 126
 127        public float GetTime()
 128        {
 40129            if (isError)
 1130                return 0;
 131
 39132            return plugin.GetTime(videoPlayerId);
 133        }
 134
 135        public float GetDuration()
 136        {
 41137            if (isError)
 1138                return 0;
 139
 40140            float duration = plugin.GetDuration(videoPlayerId);
 141
 40142            if (float.IsNaN(duration))
 1143                duration = -1;
 144
 40145            return duration;
 146        }
 147
 148        public VideoState GetState()
 149        {
 291150            return (VideoState)plugin.GetState(videoPlayerId);
 151        }
 152
 153        public void Dispose()
 154        {
 16155            plugin.Remove(videoPlayerId);
 16156        }
 157    }
 158}