private void ChangeState(string soundName, SoundState state) { SoundItem soundItem = GetSoundItemByName(soundName); SoundConfigData audioData = soundConfig.GetDataByKey(soundName); if (audioData == null || soundItem == null) { return; } soundItem.State = state; switch (state) { case SoundState.Loading: LoadingState(audioData); break; case SoundState.Play: PlayState(soundName, soundItem); break; case SoundState.Pause: PauseState(soundItem); break; case SoundState.Stop: StopState(soundName, soundItem); break; case SoundState.Error: ErrorState(soundName); break; } }
private void PlatformPlay() { if (_soundPlayer != null) _soundPlayer.Play(); soundState = SoundState.Playing; }
private void PlatformPause() { if (_soundPlayer != null) _soundPlayer.Stop(); soundState = SoundState.Paused; }
/// <summary> /// Set the playback state of the currently playing music track (Pause, Resume or Stop) /// </summary> /// <param name="state">The state to set</param> private void SetMusicPlaybackState(SoundState state) { if (currentInGameMusicInstance == null) { return; } switch (state) { case SoundState.Playing: currentInGameMusicInstance.Resume(); TimeManager.ResumeTimer(currentInGameMusicInstance.GetHashCode().ToString()); break; case SoundState.Paused: currentInGameMusicInstance.Pause(); TimeManager.PauseTimer(currentInGameMusicInstance.GetHashCode().ToString()); break; case SoundState.Stopped: currentInGameMusicInstance.Stop(); TimeManager.RemoveTimer(currentInGameMusicInstance.GetHashCode().ToString()); break; } }
public void Stop(bool immediate) { #if DIRECTX if (_voice != null) { if (immediate) { _voice.Stop(0); _voice.FlushSourceBuffers(); } else { _voice.Stop((int)PlayFlags.Tails); } } _paused = false; #else if (_sound != null) { #if ANDROID _sound.Stop(_streamId); _streamId = -1; #else _sound.Stop(); #endif soundState = SoundState.Stopped; } #endif }
public void Play() { if (!hasSourceId) { bufferIds = AL.GenBuffers(BufferCount); sourceId = AL.GenSource(); ALError error = AL.GetError(); if (error != ALError.NoError) { throw new Exception(AL.GetErrorString(error)); } hasSourceId = true; } soundState = SoundState.Playing; if (bufferFillerThread == null) { bufferIdsToFill = bufferIds; currentBufferToFill = 0; OnBufferNeeded(EventArgs.Empty); bufferFillerThread = new Thread(new ThreadStart(BufferFiller)); bufferFillerThread.Start(); } AL.SourcePlay(sourceId); }
void OnAudioFilterRead(float[] data, int numchannels) { if (currentState == SoundState.Playing && stream != null) { if (numchannels != stream.Channels) { Debug.LogError($"Stream/Player channel mismatch: {stream.Channels}, {numchannels}"); switch (numchannels) { case 1: //Down-channel stream = stream.IsolateChannel(0); break; case 2: //Up-channel stream = stream.UpChannel(); break; default: Debug.LogError($"Completely unexpected Player channel count: {numchannels}"); break; } } int readSamples = stream.Read(data, 0, data.Length); if (readSamples < data.Length) { currentState = SoundState.Stopped; playbackEndedNotifier?.Invoke(); } } }
private void ChangeState(SoundState newState) { if (newState > currentState) { currentState = newState; } }
void HandleSoundBufferRecycled(object sender, EventArgs e) { sourceId = 0; hasSourceId = false; soundState = SoundState.Stopped; //Console.WriteLine ("recycled: " + soundEffect.Name); }
private void PlatformStop(bool immediate) { if (HasSourceId) { if (!controller.CheckInitState()) { return; } AL.SourceStop(SourceId); ALHelper.CheckError("Failed to stop source."); #if SUPPORTS_EFX // Reset the SendFilter to 0 if we are NOT using revert since // sources are recyled OpenALSoundController.Efx.BindSourceToAuxiliarySlot(SourceId, 0, 0, 0); ALHelper.CheckError("Failed to unset reverb."); AL.Source(SourceId, ALSourcei.EfxDirectFilter, 0); ALHelper.CheckError("Failed to unset filter."); #endif AL.Source(SourceId, ALSourcei.Buffer, 0); ALHelper.CheckError("Failed to free source from buffer."); controller.FreeSource(this); } SoundState = SoundState.Stopped; }
private SoundState PlatformGetState() { if (!HasSourceId) { return(SoundState.Stopped); } var alState = AL.GetSourceState(SourceId); ALHelper.CheckError("Failed to get source state."); switch (alState) { case ALSourceState.Initial: case ALSourceState.Stopped: SoundState = SoundState.Stopped; break; case ALSourceState.Paused: SoundState = SoundState.Paused; break; case ALSourceState.Playing: SoundState = SoundState.Playing; break; } return(SoundState); }
public void Resume() { #if DIRECTX if (_voice != null) { // Restart the sound if (and only if) it stopped playing if (!_loop) { if (_voice.State.BuffersQueued == 0) { _voice.Stop(); _voice.FlushSourceBuffers(); _voice.SubmitSourceBuffer(_effect._buffer, null); } } _voice.Start(); } _paused = false; #else if (_sound != null) { if (soundState == SoundState.Paused) { #if ANDROID _sound.Resume(_streamId); #else _sound.Resume(); #endif } soundState = SoundState.Playing; } #endif }
public void SetStream(IBGCStream stream, bool disposeWhenComplete = false) { if (disposeStream && this.stream != null && !ReferenceEquals(stream, this.stream)) { this.stream.Dispose(); } if (stream != null) { int numChannels = stream.Channels; if (numChannels != 1 && numChannels != 2) { Debug.LogError($"Completely unexpected stream channel count: {numChannels}"); if (disposeWhenComplete) { stream.Dispose(); } stream = null; disposeWhenComplete = false; } } this.stream = stream; disposeStream = disposeWhenComplete; currentState = SoundState.Stopped; ClearBuffers(); WarmUpBuffers(); }
private SoundState PlatformGetState() { if (!hasSourceId) { return(SoundState.Stopped); } var alState = AL.GetSourceState(sourceId); switch (alState) { case ALSourceState.Initial: case ALSourceState.Stopped: soundState = SoundState.Stopped; break; case ALSourceState.Paused: soundState = SoundState.Paused; break; case ALSourceState.Playing: soundState = SoundState.Playing; break; } return(soundState); }
public void Stop(bool immediate) { if (handle == IntPtr.Zero) { return; } if (immediate) { FAudio.FAudioSourceVoice_Stop(handle, 0, 0); FAudio.FAudioSourceVoice_FlushSourceBuffers(handle); FAudio.FAudioVoice_DestroyVoice(handle); handle = IntPtr.Zero; usingReverb = false; INTERNAL_state = SoundState.Stopped; if (isDynamic) { FrameworkDispatcher.Streams.Remove( this as DynamicSoundEffectInstance ); (this as DynamicSoundEffectInstance).ClearBuffers(); } } else { if (isDynamic) { throw new InvalidOperationException(); } FAudio.FAudioSourceVoice_ExitLoop(handle, 0); } }
/// <param name="sampleRate">Sample rate, in Hertz (Hz).</param> /// <param name="channels">Number of channels (mono or stereo).</param> public DynamicSoundEffectInstance(int sampleRate, AudioChannels channels) { SoundEffect.Initialize(); if (SoundEffect._systemState != SoundEffect.SoundSystemState.Initialized) { throw new NoAudioHardwareException("Audio has failed to initialize. Call SoundEffect.Initialize() before sound operation to get more specific errors."); } if ((sampleRate < 8000) || (sampleRate > 48000)) { throw new ArgumentOutOfRangeException("sampleRate"); } if ((channels != AudioChannels.Mono) && (channels != AudioChannels.Stereo)) { throw new ArgumentOutOfRangeException("channels"); } _sampleRate = sampleRate; _channels = channels; _state = SoundState.Stopped; PlatformCreate(); // This instance is added to the pool so that its volume reflects master volume changes // and it contributes to the playing instances limit, but the source/voice is not owned by the pool. _isPooled = false; _isDynamic = true; }
/// <summary> /// Event handler that resets internal state of this instance. The sound state will report /// SoundState.Stopped after this event handler. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void HandleSoundBufferRecycled(object sender, EventArgs e) { sourceId = 0; hasSourceId = false; soundState = SoundState.Stopped; //Console.WriteLine ("recycled: " + soundEffect.Name); }
private void SyncStateToPlayer(SoundType type, SoundState state) { switch (state) { case SoundState.Resource: //if (m_ResourcePlayer[(int)type]==null) //{ // switch (type) // { // case SoundType.Pause: // ;//m_ResourcePlayer[(int)type] = new System.Media.SoundPlayer(Res.Bellatrix_Pause); // break; // case SoundType.Resume: // ;//m_ResourcePlayer[(int)type] = new System.Media.SoundPlayer(Res.Pollux_Resume); // break; // case SoundType.WorkDone: // ;//m_ResourcePlayer[(int)type] = new System.Media.SoundPlayer(Res.CanisMajor_WorkDone); // break; // case SoundType.RestTimeOut: // ;//m_ResourcePlayer[(int)type] = new System.Media.SoundPlayer(Res.Fermium_RestTimeOut); // break; // } //} break; case SoundState.File: if (m_wmplayer == null) { m_wmplayer = new WMPLib.WindowsMediaPlayer(); m_wmplayer.PlayStateChange += new WMPLib._WMPOCXEvents_PlayStateChangeEventHandler(Player_PlayStateChange); } break; } }
public void Pause() { if (State == SoundState.Playing) { Invoke(_player.Pause); State = SoundState.Stopped; } }
public void Pause() { if (handle != IntPtr.Zero && State == SoundState.Playing) { FAudio.FAudioSourceVoice_Stop(handle, 0, 0); INTERNAL_state = SoundState.Paused; } }
public void Stop() { if (_sound != null) { _sound.Stop(); soundState = SoundState.Stopped; } }
public void Play() { if (_sound != null) { _sound.Play(); soundState = SoundState.Playing; } }
public void Pause() { if (_sound != null) { _sound.Pause(); soundState = SoundState.Paused; } }
public void Stop() { if (hasSourceId && soundBuffer != null) { controller.StopSound(soundBuffer); } soundState = SoundState.Stopped; }
public void Resume() { if (hasSourceId) { controller.PlaySound(soundBuffer); } soundState = SoundState.Playing; }
public void Pause () { if ( _sound != null ) { _sound.Pause(); soundState = SoundState.Paused; } }
public void Stop() { if (State == SoundState.Playing) { Invoke(_player.Stop); State = SoundState.Stopped; } }
public void Play() { if (State != SoundState.Playing) { Invoke(_player.Play); State = SoundState.Playing; } }
private void PlatformPause() { if (streamId == 0) return; s_soundPool.Pause(streamId); soundState = SoundState.Paused; }
public void Stop() { lock (ControlLock) { _State = SoundState.Stopped; Inst?.Stop(); } }
public void Pause() { lock (ControlLock) { _State = SoundState.Paused; Inst?.Pause(); } }
public void Pause() { if (hasSourceId) { AL.SourcePause(sourceId); soundState = SoundState.Paused; } }
public void Pause() { if (hasSourceId) { controller.PauseSound(soundBuffer); soundState = SoundState.Paused; } }
public void Resume() { lock (ControlLock) { _State = SoundState.Playing; Inst?.Resume(); } }
public void Play() { lock (ControlLock) { _State = SoundState.Playing; Inst?.Play(); } }
private void PlatformStop(bool immediate) { if (_soundPlayer != null ) { _soundPlayer.Stop(); } soundState = SoundState.Stopped; }
public void Play() { if (soundEffect != null) { soundEffect.Play(); SoundState previousStateTemp = previousState; previousState = SoundState.Playing; if (SoundStateChanged != null) SoundStateChanged.Invoke(previousStateTemp, previousState); } }
public void Load() { if (Status == SoundState.Unloaded) { Status = SoundState.Loading; // I commented out this code because we let windows handle loading mp3s. // Static song ctor requires a URI, which is a pain in the butt, // so we're going to just reflect out the ctor. /*var ctor = typeof(Song).GetConstructor( BindingFlags.NonPublic | BindingFlags.Instance, null, new[] { typeof(string), typeof(string), typeof(int) }, null);*/ // m_Song = (Song)ctor.Invoke(new object[] { Name, Path, 0 }); Status = SoundState.Loaded; } }
private void PlatformDispose(bool disposing) { if (disposing) { if (_soundPlayer != null) { _soundPlayer.Stop(); _soundPlayer.Dispose(); } if (_audioBuffer != null) _audioBuffer.Dispose(); } _soundPlayer = null; _audioBuffer = null; soundState = SoundState.Stopped; }
public void ChangState() { if (Count % 2 == 0) { currentSoundState = SoundState.OFF; mutte.SetActive(true); Count++; StopGameAudio(); } else { currentSoundState = SoundState.ON; mutte.SetActive(false); Count++; PlayMenuAudio(); } }
public void SetSound(Sound sound) { if (soundEffect != null) soundEffect.Stop(); previousState = SoundState.Stopped; string path = CatrobatContext.Instance.CurrentProject.BasePath + "/" + Project.SoundsPath + "/" + sound.FileName; using (IStorage storage = StorageSystem.GetStorage()) { if (storage.FileExists(path)) using (Stream stream = storage.OpenFile(path, StorageFileMode.Open, StorageFileAccess.Read)) { byte[] soundArray = new byte[stream.Length]; stream.Read(soundArray, 0, soundArray.Length); stream.Close(); soundEffect = new SoundEffect(soundArray, Microphone.Default.SampleRate, AudioChannels.Mono).CreateInstance(); } } checkSoundThread = new System.Threading.Thread(checkIfSoundFinished); }
public void OnSoundButtonPressed() { SoundEnabled += 1; Vibration.Vibrate(); _soundButton.GetComponent<Image>().sprite = GeneralSettings.SoundButtonSprite; }
/// <summary> /// When the source is available, the sound buffer playback is stopped. Either way, /// the state of the instance will always be SoundState.Stopped after this method is /// called. /// </summary> public void Stop () { if (hasSourceId) { //Console.WriteLine ("stop " + sourceId + " : " + soundEffect.Name); controller.StopSound (soundBuffer); } soundState = SoundState.Stopped; }
/// <summary> /// When the sound state is paused, and the source is available, then the sound /// is played using the ResumeSound method from the OpenALSoundController. Otherwise, /// the sound is played using the Play() method. Upon success, the sound state should /// be SoundState.Playing. /// </summary> public void Resume () { if (hasSourceId) { if (soundState == SoundState.Paused) { controller.ResumeSound(soundBuffer); soundState = SoundState.Playing; } } else { Play(); } }
/// <summary> /// If no source is ready, then this method does not change the current state of the instance. Otherwise, /// if the controller can not reserve the source then InstancePLayLimitException is thrown. Finally, the sound /// buffer is sourced to OpenAL, then ApplyState is called and then the sound is set to play. Upon success, /// the sound state is set to SoundState.Playing. /// </summary> public virtual void Play () { if (hasSourceId) { return; } bool isSourceAvailable = controller.ReserveSource (soundBuffer); if (!isSourceAvailable) throw new InstancePlayLimitException(); int bufferId = soundBuffer.OpenALDataBuffer; AL.Source(soundBuffer.SourceId, ALSourcei.Buffer, bufferId); ApplyState (); controller.PlaySound (soundBuffer); //Console.WriteLine ("playing: " + sourceId + " : " + soundEffect.Name); soundState = SoundState.Playing; }
/// <summary> /// When the sound state is playing and the source is created, this method will pause /// the sound playback and set the state to SoundState.Paused. Otherwise, no change is /// made to the state of this instance. /// </summary> public void Pause () { if (hasSourceId && soundState == SoundState.Playing) { controller.PauseSound (soundBuffer); soundState = SoundState.Paused; } }
//Update all of the elements that need updating in the Controller Detect Screen public override void Update(GameTime theTime) { MouseState mouse = Mouse.GetState(); Rectangle hoverPosition = new Rectangle(mouse.X, mouse.Y, 1, 1); if (hoverPosition.Intersects(btnKembaliPosition)) { btnKembali = btnKembaliHover; } else { btnKembali = btnKembaliActive; } if (mouse.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed) { Point pointer = new Point(mouse.X, mouse.Y); if (btnKembaliPosition.Contains(pointer)) { Game1.MOUSE_DOWN.Play(); Thread.Sleep(200); if (PlayScreen.SUB_LEVEL == Game1.LEVEL11 || PlayScreen.SUB_LEVEL == Game1.LEVEL12) { ScreenEvent.Invoke(Game1.LEVEL1, new EventArgs()); return; } else if (PlayScreen.SUB_LEVEL == Game1.LEVEL21 || PlayScreen.SUB_LEVEL == Game1.LEVEL22) { ScreenEvent.Invoke(Game1.LEVEL2, new EventArgs()); return; } else { ScreenEvent.Invoke(Game1.LEVEL_SCREEN, new EventArgs()); return; } } soundState = soundInstance.State; if (btnSoal1Position.Contains(pointer)) { if (currentSound == 1 && soundState == SoundState.Playing) { soundInstance.Stop(); btnSoal1 = btnPlay; } else { soundInstance.Stop(); soundInstance = soundSoal[0].CreateInstance(); btnSoal1 = btnStop; soundInstance.Play(); soundState = soundInstance.State; currentSound = 1; btnSoal2 = btnPlay; btnSoal3 = btnPlay; btnSoal4 = btnPlay; btnSoal5 = btnPlay; } } else if (btnSoal2Position.Contains(pointer)) { if (currentSound == 2 && soundState == SoundState.Playing) { soundInstance.Stop(); btnSoal2 = btnPlay; } else { soundInstance.Stop(); soundInstance = soundSoal[1].CreateInstance(); btnSoal2 = btnStop; soundInstance.Play(); soundState = soundInstance.State; currentSound = 2; btnSoal1 = btnPlay; btnSoal3 = btnPlay; btnSoal4 = btnPlay; btnSoal5 = btnPlay; } } else if (btnSoal3Position.Contains(pointer)) {if (currentSound == 3 && soundState == SoundState.Playing) { soundInstance.Stop(); btnSoal3 = btnPlay; } else { soundInstance.Stop(); soundInstance = soundSoal[2].CreateInstance(); btnSoal3 = btnStop; soundInstance.Play(); soundState = soundInstance.State; currentSound = 3; btnSoal1 = btnPlay; btnSoal2 = btnPlay; btnSoal4 = btnPlay; btnSoal5 = btnPlay; } } else if (btnSoal4Position.Contains(pointer)) { if (currentSound == 4 && soundState == SoundState.Playing) { soundInstance.Stop(); btnSoal4 = btnPlay; } else { soundInstance.Stop(); soundInstance = soundSoal[3].CreateInstance(); btnSoal4 = btnStop; soundInstance.Play(); soundState = soundInstance.State; currentSound = 4; btnSoal1 = btnPlay; btnSoal2 = btnPlay; btnSoal3 = btnPlay; btnSoal5 = btnPlay; } } else if (btnSoal5Position.Contains(pointer)) { if (currentSound == 5 && soundState == SoundState.Playing) { soundInstance.Stop(); btnSoal5 = btnPlay; } else { soundInstance.Stop(); soundInstance = soundSoal[4].CreateInstance(); btnSoal5 = btnStop; soundInstance.Play(); soundState = soundInstance.State; currentSound = 5; btnSoal1 = btnPlay; btnSoal2 = btnPlay; btnSoal3 = btnPlay; btnSoal4 = btnPlay; } } Thread.Sleep(200); } if (soundInstance.State == SoundState.Stopped) { btnSoal1 = btnPlay; btnSoal2 = btnPlay; btnSoal3 = btnPlay; btnSoal4 = btnPlay; btnSoal5 = btnPlay; } soundState = soundInstance.State; }
public void Play() { if ( _sound != null ) { _sound.Play(); soundState = SoundState.Playing; } }
public void Stop() { if (hasSourceId) { _done = true; AL.SourceStop(sourceId); int pendingBuffers = PendingBufferCount; if (pendingBuffers > 0) AL.SourceUnqueueBuffers(sourceId, PendingBufferCount); } soundState = SoundState.Stopped; }
private SoundState PlatformGetState() { if (_soundPlayer != null) { if (soundState == SoundState.Playing && _soundPlayer.Status != SoundStatus.Playing) { soundState = SoundState.Stopped; } } return soundState; }
public void Play () { #if WINRT if (_voice != null) { // Choose the correct buffer depending on if we are looped. var buffer = _loop ? _effect._loopedBuffer : _effect._buffer; if (_voice.State.BuffersQueued > 0) { _voice.Stop(); _voice.FlushSourceBuffers(); } _voice.SubmitSourceBuffer(buffer, null); _voice.Start(); } _paused = false; #else if ( _sound != null ) { #if ANDROID if (soundState == SoundState.Paused) _sound.Resume(_streamId); else _streamId = _sound.Play(); #else if (soundState == SoundState.Paused) _sound.Resume(); else _sound.Play(); #endif soundState = SoundState.Playing; } #endif }
public void Stop() { #if WINRT if (_voice != null) { _voice.Stop(0); _voice.FlushSourceBuffers(); } _paused = false; #else if ( _sound != null ) { #if ANDROID _sound.Stop(_streamId); _streamId = -1; #else _sound.Stop(); #endif soundState = SoundState.Stopped; } #endif }
public void Pause () { #if WINRT if (_voice != null) _voice.Stop(); _paused = true; #else if ( _sound != null ) { #if ANDROID _sound.Pause(_streamId); #else _sound.Pause(); #endif soundState = SoundState.Paused; } #endif }
internal bool RefreshState() { if (this.soundState != SoundState.Playing || AL.GetSourceState(this.sourceId) != ALSourceState.Stopped) return false; ALHelper.Check(); this.soundState = SoundState.Stopped; return true; }
public void Resume() { #if WINRT if (_voice != null) { // Restart the sound if (and only if) it stopped playing if (!_loop) { if (_voice.State.BuffersQueued == 0) { _voice.Stop(); _voice.FlushSourceBuffers(); _voice.SubmitSourceBuffer(_effect._buffer, null); } } _voice.Start(); } _paused = false; #else if ( _sound != null ) { if (soundState == SoundState.Paused) { #if ANDROID _sound.Resume(_streamId); #else _sound.Resume(); #endif } soundState = SoundState.Playing; } #endif }
public void Play() { if ( _sound != null ) { if (soundState == SoundState.Paused) _sound.Resume(); else _sound.Play(); soundState = SoundState.Playing; } }
public void Stop(bool immediate) { #if WINRT if (_voice != null) _voice.Stop(immediate ? 0 : (int)PlayFlags.Tails); _paused = false; #else if ( _sound != null ) { #if ANDROID _sound.Stop(_streamId); _streamId = -1; #else _sound.Stop(); #endif soundState = SoundState.Stopped; } #endif }
public void Play() { if (this.isDisposed) throw new ObjectDisposedException("SoundEffectInstance (" + this.soundEffect.Name + ")"); if (this.soundState == SoundState.Playing) return; AL.SourcePlay(this.sourceId); ALHelper.Check(); this.soundState = SoundState.Playing; }
public void Stop() { if ( _sound != null ) { _sound.Stop(); soundState = SoundState.Stopped; } }
public void Stop(bool immediate = false) { if (this.isDisposed) throw new ObjectDisposedException("SoundEffectInstance (" + this.soundEffect.Name + ")"); if (this.soundState == SoundState.Stopped) return; AL.SourceStop(this.sourceId); ALHelper.Check(); this.soundState = SoundState.Stopped; }