Ejemplo n.º 1
0
        public void Setup()
        {
            _diskProvider = Mocker.Resolve <IDiskProvider>("ActualDiskProvider");

            Mocker.SetConstant <IDiskProvider>(_diskProvider);

            Mocker.GetMock <IConfigService>()
            .Setup(x => x.WriteAudioTags)
            .Returns(WriteAudioTagsType.Sync);

            var imageFile = Path.Combine(_testdir, "nin.png");
            var imageSize = _diskProvider.GetFileSize(imageFile);

            // have to manually set the arrays of string parameters and integers to values > 1
            _testTags = Builder <AudioTag> .CreateNew()
                        .With(x => x.Track               = 2)
                        .With(x => x.TrackCount          = 33)
                        .With(x => x.Disc                = 44)
                        .With(x => x.DiscCount           = 55)
                        .With(x => x.Date                = new DateTime(2019, 3, 1))
                        .With(x => x.Year                = 2019)
                        .With(x => x.OriginalReleaseDate = new DateTime(2009, 4, 1))
                        .With(x => x.OriginalYear        = 2009)
                        .With(x => x.Performers          = new[] { "Performer1" })
                        .With(x => x.AlbumArtists        = new[] { "방탄소년단" })
                        .With(x => x.Genres              = new[] { "Genre1", "Genre2" })
                        .With(x => x.ImageFile           = imageFile)
                        .With(x => x.ImageSize           = imageSize)
                        .Build();
        }
Ejemplo n.º 2
0
        private void VerifySame(AudioTag a, AudioTag b, string[] skipProperties)
        {
            foreach (var property in typeof(AudioTag).GetProperties())
            {
                if (skipProperties.Contains(property.Name))
                {
                    continue;
                }

                if (property.CanRead)
                {
                    if (property.PropertyType.GetInterfaces().Any(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IEquatable <>)) ||
                        Nullable.GetUnderlyingType(property.PropertyType) != null)
                    {
                        var val1 = property.GetValue(a, null);
                        var val2 = property.GetValue(b, null);
                        val1.Should().Be(val2, $"{property.Name} should be equal");
                    }
                    else if (typeof(IEnumerable).IsAssignableFrom(property.PropertyType))
                    {
                        var val1 = (IEnumerable)property.GetValue(a, null);
                        var val2 = (IEnumerable)property.GetValue(b, null);

                        if (val1 != null || val2 != null)
                        {
                            val1.Should().BeEquivalentTo(val2, $"{property.Name} should be equal");
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
 public AudioEntry(SoundEffectInstance soundEffect, AudioTag tag, bool isMuted, float maxVolume)
 {
     Tag                = tag;
     SoundEffect        = soundEffect;
     SoundEffect.Volume = maxVolume;
     IsMuted            = isMuted;
     MaxVolume          = maxVolume;
 }
Ejemplo n.º 4
0
 public static void SetVolume(AudioTag tag, float volume)
 {
     foreach (AudioEntry audioEntry in audioCache.Values)
     {
         if (audioEntry.Tag == tag)
         {
             audioEntry.SoundEffect.Volume = volume * audioEntry.MaxVolume;
         }
     }
 }
Ejemplo n.º 5
0
 public static void ToggleMuteWithTag(AudioTag tag, bool muted)
 {
     foreach (AudioEntry audioEntry in audioCache.Values)
     {
         if (audioEntry.Tag == tag)
         {
             audioEntry.IsMuted = muted;
         }
     }
 }
Ejemplo n.º 6
0
        public static void AddSound(string name, string path, bool isLooped = false, AudioTag audioTag = AudioTag.SOUND_EFFECT, bool isMuted = false, float maxVolume = 1)
        {
            if (maxVolume < 0 || maxVolume > 1)
            {
                throw new Exception("Max volume should be a value between 0 and 1");
            }
            SoundEffectInstance audio = AssetUtil.LoadSoundEffect(path).CreateInstance();

            audio.IsLooped = isLooped;
            audioCache.Add(name, new AudioEntry(audio, audioTag, isMuted, maxVolume));
        }
Ejemplo n.º 7
0
        public void should_set_quality_and_mediainfo_for_corrupt_file(string filename, string[] skipProperties)
        {
            // use missing to simulate corrupt
            var tag      = Subject.ReadAudioTag(filename.Replace("nin", "missing"));
            var expected = new AudioTag();

            VerifySame(tag, expected, skipProperties);
            tag.Quality.Should().NotBeNull();
            tag.MediaInfo.Should().NotBeNull();

            ExceptionVerification.ExpectedErrors(1);
        }
    public void PlaySound(AudioTag audioTag)
    {
        if (EazySoundManager.GetAudio(dict_AudioClips[audioTag]) == null)
        {
            EazySoundManager.PlaySound(dict_AudioClips[audioTag], sound_Volume);
        }

        else if (!EazySoundManager.GetAudio(dict_AudioClips[audioTag]).IsPlaying)
        {
            EazySoundManager.PlaySound(dict_AudioClips[audioTag], sound_Volume);
        }
    }
Ejemplo n.º 9
0
    void PlayUISound()
    {
        AudioTag[] audioTags = new AudioTag[5] {
            AudioTag.BUTTON_CLICK_1, AudioTag.BUTTON_CLICK_2, AudioTag.BUTTON_CLICK_3, AudioTag.BUTTON_CLICK_4, AudioTag.BUTTON_CLICK_5
        };
        int i = UnityEngine.Random.Range(0, 5);

        if (MilitakiriAudioManager.Instance == null)
        {
            Debug.LogError("Instance null");
            FindObjectOfType <MilitakiriAudioManager>().PlayUISound(audioTags[i]);
            return;
        }
        MilitakiriAudioManager.Instance.PlayUISound(audioTags[i]);
    }
Ejemplo n.º 10
0
        private AudioManager FetchAudioManager(AudioTag audioTag)
        {
            AudioManager audioManager = null;

            if (this.audioManagers.ContainsKey(audioTag) == false)
            {
                audioManager = this.CreateAudioManager(audioTag);
            }
            else
            {
                audioManager = this.audioManagers[audioTag];
            }

            return(audioManager);
        }
Ejemplo n.º 11
0
        public void should_read_audiotag_from_file_with_no_tags(string filename, string[] skipProperties)
        {
            GivenFileCopy(filename);
            var path = _copiedFile;

            Subject.RemoveAllTags(path);

            var tag      = Subject.ReadAudioTag(path);
            var expected = new AudioTag()
            {
                Performers   = new string[0],
                AlbumArtists = new string[0],
                Genres       = new string[0]
            };

            VerifySame(tag, expected, skipProperties);
            tag.Quality.Should().NotBeNull();
            tag.MediaInfo.Should().NotBeNull();
        }
Ejemplo n.º 12
0
        public void should_read_file_with_only_title_tag(string filename, string[] ignored)
        {
            GivenFileCopy(filename);
            var path = _copiedFile;

            Subject.RemoveAllTags(path);

            var nametag = new AudioTag();

            nametag.Title = "test";
            nametag.Write(path);

            var tag = Subject.ReadTags(path);

            tag.Title.Should().Be("test");

            tag.Quality.Should().NotBeNull();
            tag.MediaInfo.Should().NotBeNull();
        }
Ejemplo n.º 13
0
            public static Tag Parse(byte[] headerBytes, byte[] bodyBytes)
            {
                TagType tagType = (TagType)(headerBytes[0] & 0b00011111);
                Tag     tagBase;

                switch (tagType)
                {
                case TagType.Audio:
                    tagBase = new AudioTag(headerBytes, bodyBytes);
                    break;

                case TagType.Video:
                    tagBase = new VideoTag(headerBytes, bodyBytes);
                    break;

                case TagType.Script:
                    tagBase = new ScriptTag(headerBytes, bodyBytes);
                    break;

                default:
                    throw new UnsupportedFormat(string.Format("Unsupported Tag type 0x{0}", ((uint)tagType).ToString("X2")));
                }
                return(tagBase);
            }
Ejemplo n.º 14
0
        private AudioManager CreateAudioManager(AudioTag audioTag)
        {
            //Creating new game object.
            GameObject newAudioManager = new GameObject();

            //Setting the AudioController gameobject the parent of the AudioManager gameobject.
            newAudioManager.transform.parent = this.transform;

            //Setting the name of the gameobject.
            newAudioManager.name = $"[AudioManager] {audioTag} ";

            //Adding  Audiomanager component.
            AudioManager audioManager = newAudioManager.AddComponent <AudioManager>();

            //Adding AudioSource component.
            newAudioManager.AddComponent <AudioSource>();

            //Setting the audio tag.
            audioManager.AudioTag = audioTag;

            audioManager.Setup();

            return(audioManager);
        }
Ejemplo n.º 15
0
 internal static FlvTag ReadTag(Stream stream)
 {
     try {
         FlvTag tag;
         byte[] buffer = new byte[4];
         int rtn;
         rtn = stream.Read(buffer, 0, 4);
         if (rtn <= 0) {
             return null;
         }
         int type = stream.ReadByte();
         if (type == 8)
             tag = new AudioTag();
         else if (type == 9)
             tag = new VideoTag();
         else if (type == 0x12)
             tag = new ScriptTag();
         else
             tag = new FlvTag();
         tag.presize = ByteUtil.ByteToUInt(buffer, 4);
         tag.tagtype = type;
         tag.datasize = ByteUtil.ReadUI24(stream);
         tag.timestamp = ByteUtil.ReadUI24(stream);
         tag.timestamp_ex = stream.ReadByte();
         tag.streamid = ByteUtil.ReadUI24(stream);
         tag.offset = stream.Position;
         if (tag is ScriptTag) {
             (tag as ScriptTag).ReadScript(stream);
             stream.Seek(tag.offset + tag.DataSize, SeekOrigin.Begin);
         } else if (tag is AudioTag) {
             rtn = stream.Read(buffer, 0, 1);
             if (rtn <= 0)
                 return null;
             tag.taginfo = buffer[0];
             stream.Seek(tag.DataSize - 1, SeekOrigin.Current);
         } else if (tag is VideoTag) {
             rtn = stream.Read(buffer, 0, 2);
             if (rtn <= 0)
                 return null;
             tag.taginfo = buffer[0];
             tag.avcpaktype = buffer[1];
             stream.Seek(tag.DataSize - 2, SeekOrigin.Current);
         }
         return tag;
     } catch {
         return null;
     }
 }
Ejemplo n.º 16
0
 public void SetVolume(AudioTag audioTag, float value = 0)
 {
     Debug.Log(this.FetchAudioManager(audioTag));
 }
Ejemplo n.º 17
0
 internal static FlvTag ReadTag(Stream stream)
 {
     try {
         FlvTag tag;
         byte[] buffer = new byte[4];
         int    rtn;
         rtn = stream.Read(buffer, 0, 4);
         if (rtn <= 0)
         {
             return(null);
         }
         int type = stream.ReadByte();
         if (type == 8)
         {
             tag = new AudioTag();
         }
         else if (type == 9)
         {
             tag = new VideoTag();
         }
         else if (type == 0x12)
         {
             tag = new ScriptTag();
         }
         else
         {
             tag = new FlvTag();
         }
         tag.presize      = ByteUtil.ByteToUInt(buffer, 4);
         tag.tagtype      = type;
         tag.datasize     = ByteUtil.ReadUI24(stream);
         tag.timestamp    = ByteUtil.ReadUI24(stream);
         tag.timestamp_ex = stream.ReadByte();
         tag.streamid     = ByteUtil.ReadUI24(stream);
         tag.offset       = stream.Position;
         if (tag is ScriptTag)
         {
             (tag as ScriptTag).ReadScript(stream);
             stream.Seek(tag.offset + tag.DataSize, SeekOrigin.Begin);
         }
         else if (tag is AudioTag)
         {
             rtn = stream.Read(buffer, 0, 1);
             if (rtn <= 0)
             {
                 return(null);
             }
             tag.taginfo = buffer[0];
             stream.Seek(tag.DataSize - 1, SeekOrigin.Current);
         }
         else if (tag is VideoTag)
         {
             rtn = stream.Read(buffer, 0, 2);
             if (rtn <= 0)
             {
                 return(null);
             }
             tag.taginfo    = buffer[0];
             tag.avcpaktype = buffer[1];
             stream.Seek(tag.DataSize - 2, SeekOrigin.Current);
         }
         return(tag);
     } catch {
         return(null);
     }
 }
 public void PlayUISound(AudioTag audioTag)
 {
     EazySoundManager.PlayUISound(dict_AudioClips[audioTag], sound_Volume);
 }
Ejemplo n.º 19
0
        public void PlayAudio(AudioTag audioTag, AudioClip clip)
        {
            AudioManager audioManager = this.FetchAudioManager(audioTag);

            audioManager.PlayAudio(clip);
        }