< Summary

Class:DCL.AssetPromise_AudioClip
Assembly:AssetPromiseKeeper
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/AudioClip/AssetPromise_AudioClip.cs
Covered lines:29
Uncovered lines:6
Coverable lines:35
Total lines:94
Line coverage:82.8% (29 of 35)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
AssetPromise_AudioClip(...)0%110100%
AssetPromise_AudioClip(...)0%220100%
OnLoad(...)0%3.583060%
OnCancelLoading()0%220100%
AddToLibrary()0%2.062075%
OnBeforeLoadOrReuse()0%110100%
OnAfterLoadOrReuse()0%110100%
GetId()0%110100%
GetAudioTypeFromUrlName(...)0%7.96062.5%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/AudioClip/AssetPromise_AudioClip.cs

#LineLine coverage
 1using System;
 2using UnityEngine;
 3using UnityEngine.Networking;
 4
 5namespace DCL
 6{
 7    public class AssetPromise_AudioClip : AssetPromise<Asset_AudioClip>
 8    {
 9        private readonly string url;
 10        private readonly string id;
 11        private readonly AudioType audioType;
 12        private readonly IWebRequestController webRequestController;
 13
 14        private WebRequestAsyncOperation webRequestAsyncOperation;
 15
 4816        public AssetPromise_AudioClip(string clipPath, ContentProvider provider) : this(clipPath, provider, Environment.
 17
 2418        public AssetPromise_AudioClip(string clipPath, ContentProvider provider, IWebRequestController webRequestControl
 19        {
 2420            this.url = provider.GetContentsUrl(clipPath);
 2421            this.id = this.url != null ? this.url.Substring(this.url.LastIndexOf('/') + 1) : $"{GetHashCode()}";
 2422            this.audioType = GetAudioTypeFromUrlName(clipPath);
 2423            this.webRequestController = webRequestController;
 2424        }
 25
 26        protected override void OnLoad(Action OnSuccess, Action OnFail)
 27        {
 2328            if (string.IsNullOrEmpty(url))
 29            {
 030                OnFail?.Invoke();
 031                return;
 32            }
 33
 2334            webRequestAsyncOperation = webRequestController.GetAudioClip(url, audioType,
 35                request =>
 36                {
 1637                    asset.audioClip = DownloadHandlerAudioClip.GetContent(request);
 1638                    OnSuccess?.Invoke();
 1639                },
 40                request =>
 41                {
 342                    OnFail?.Invoke();
 343                });
 2344        }
 45
 46        protected override void OnCancelLoading()
 47        {
 748            webRequestAsyncOperation?.Dispose();
 749            webRequestAsyncOperation = null;
 750        }
 51
 52        protected override bool AddToLibrary()
 53        {
 1654            if (!library.Add(asset))
 55            {
 056                return false;
 57            }
 1658            asset = library.Get(asset.id);
 1659            return true;
 60        }
 61
 2662        protected override void OnBeforeLoadOrReuse() { }
 63
 1964        protected override void OnAfterLoadOrReuse() { }
 65
 66        public override object GetId()
 67        {
 14068            return id;
 69        }
 70
 71        private static AudioType GetAudioTypeFromUrlName(string url)
 72        {
 2473            if (string.IsNullOrEmpty(url))
 74            {
 075                Debug.LogError("GetAudioTypeFromUrlName >>> Null url!");
 076                return AudioType.UNKNOWN;
 77            }
 78
 2479            string ext = url.Substring(url.Length - 3).ToLower();
 80
 81            switch (ext)
 82            {
 83                case "mp3":
 084                    return AudioType.MPEG;
 85                case "wav":
 986                    return AudioType.WAV;
 87                case "ogg":
 1288                    return AudioType.OGGVORBIS;
 89                default:
 390                    return AudioType.UNKNOWN;
 91            }
 92        }
 93    }
 94}