Exemplo n.º 1
0
 public void Play(AudioClip clip, AudioParameters audioParameters)
 {
     _audioParameters  = audioParameters;
     _audioSource.clip = clip;
     _audioSource.loop = audioParameters.Loop;
     _audioSource.Play();
 }
Exemplo n.º 2
0
 public void Play(string path, AudioParameters audioParameters = null)
 {
     if (audioParameters != null)
     {
         PlayAsync(path, audioParameters);
     }
     else
     {
         PlayAsync(path, _defaultParameters);
     }
 }
Exemplo n.º 3
0
 public async void Play(string path, AudioParameters audioParameters = null)
 {
     RefreshToken();
     if (audioParameters != null)
     {
         await PlayAsync(path, audioParameters, _cancellationTokenSource.Token);
     }
     else
     {
         await PlayAsync(path, _defaultLoopParameters, _cancellationTokenSource.Token);
     }
 }
Exemplo n.º 4
0
        private async void PlayAsync(string path, AudioParameters audioParameters)
        {
            if (!IsPlayAccessible())
            {
                return;
            }

            AudioPlayer audioPlayer = _sourcePool.Pop();

            var clip = await _audioClipCache.GetItem(path);

            audioPlayer.Play(clip, audioParameters);

            await ReleaseAfterPlayed(audioPlayer);
        }
Exemplo n.º 5
0
        private async Task PlayAsync(string path, AudioParameters audioParameters, CancellationToken token)
        {
            try
            {
                if (_audioPlayer.IsPlaying)
                {
                    await _audioPlayer.FadeVolume(0, token);
                }

                _audioClipCache.Release(_audioPlayer.ClipName);

                var clip = await _audioClipCache.GetItem(path);

                token.ThrowIfCancellationRequested();

                _audioPlayer.Play(clip, audioParameters);

                await _audioPlayer.FadeVolume(audioParameters.Volume, token);
            }
            catch (OperationCanceledException) { }
        }