public void Play(AudioClip clip, AudioParameters audioParameters) { _audioParameters = audioParameters; _audioSource.clip = clip; _audioSource.loop = audioParameters.Loop; _audioSource.Play(); }
public void Play(string path, AudioParameters audioParameters = null) { if (audioParameters != null) { PlayAsync(path, audioParameters); } else { PlayAsync(path, _defaultParameters); } }
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); } }
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); }
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) { } }