private void FillBuffer(IWaveProvider playbackProvider, int frameCount) { var buffer = renderClient.GetBuffer(frameCount); var readLength = frameCount * bytesPerFrame; int actualFrameCount = 0; if (playbackState == PlaybackState.Paused) { byte[] rb = new byte[readLength]; Marshal.Copy(rb, 0, buffer, readLength); actualFrameCount = readLength / bytesPerFrame; } else if (playbackState == PlaybackState.Playing) { int read = playbackProvider.Read(readBuffer, 0, readLength); if (read == 0) { playbackState = PlaybackState.Stopped; PlaybackStopped?.Invoke(this, new StoppedEventArgs()); } Marshal.Copy(readBuffer, 0, buffer, read); actualFrameCount = read / bytesPerFrame; /*if (actualFrameCount != frameCount) * { * Debug.WriteLine(String.Format("WASAPI wanted {0} frames, supplied {1}", frameCount, actualFrameCount )); * }*/ } renderClient.ReleaseBuffer(actualFrameCount, AudioClientBufferFlags.None); }
void SendPlaybackStopped(object sender, EventArgs e) { _isPlaying = false; State = PlaybackState.Stopped; PlaybackStopped?.Invoke(this, EventArgs.Empty); _controlsAlwaysVisible = true; ShowController(); }
protected virtual void OnPlaybackStopped(StoppedEventArgs e) { _playing = false; if (e.Exception != null) { PlaybackStopped?.Invoke(this, e); } }
public NAudioMusicPlayer() { _woEvent = new WaveOutEvent(); _woEvent.PlaybackStopped += (sender, e) => { _state = MusicPlayerState.Stopped; PlaybackStopped?.Invoke(this, EventArgs.Empty); }; }
private PlaybackStoppedEventArgs OnPlaybackEnded() { var e = new PlaybackStoppedEventArgs { NextShadow = nextSongShadow }; PlaybackStopped?.Invoke(this, e); return(e); }
/// <summary> /// Proxy event handler for receiving playback stopped event from WaveOut /// </summary> protected void EventHandler_stopped(object sender, StoppedEventArgs args) { bool isEnd = streamProcessor.EndReached; if (isEnd) { Stop(); } PlaybackStopped?.Invoke(sender, isEnd); }
private void OnPlaybackStop(uBaseObject mediaInfo) { if (PlaybackStopped != null) { PlaybackStopped.Invoke(this, new PlaybackStoppedEventArgs { MediaInfo = mediaInfo }); } }
private void Timer_Tick(object sender, ElapsedEventArgs e) { var state = _audioSource.State; if ((_lastSourceState == ALSourceState.Paused || _lastSourceState == ALSourceState.Playing) && state == ALSourceState.Stopped) { PlaybackStopped?.Invoke(this, EventArgs.Empty); } _lastSourceState = state; }
private void M_player_PlaybackStopped() { PlaybackStopped?.Invoke(); if (m_isStopInitiatedByUser) { m_isStopInitiatedByUser = false; return; } Next(); Play(); }
public TSoundTask(string filePath, int volume, bool loop, PlaybackStopped stoppedHandler) { this.filePath = filePath; this.volume = volume; this.audioFileReader = new LoopAudioFileReader(filePath, loop); this.audioFileReader.Volume = volume / 100f; this.waveOutDevice = new WaveOut(); this.waveOutDevice.Init(this.audioFileReader); this.waveOutDevice.PlaybackStopped += onPlaybackStopped; this.playbackStoppedHandler = stoppedHandler; }
/// <summary> /// Stops playing the current sequence, but does not reset the time back /// to 0. This will effectivly leave the scene as it was when the /// sequence was playing. Still fires the PlaybackStopped event. /// </summary> public void pausePlayback() { if (playing) { medicalController.OnLoopUpdate -= medicalController_OnLoopUpdate; playing = false; if (PlaybackStopped != null) { PlaybackStopped.Invoke(this); } } }
public void Clear() { Stop(false); if (disposeStream && stream != null) { stream.Dispose(); } stream = null; disposeStream = false; playbackEndedNotifier = null; ClearBuffers(); }
private void OnPlaybackStopped(object sender, StoppedEventArgs e) { // If we are internally waiting for a stop to happen, // call the hook instead of forwarding the event (see Seek method). if (continuationOnStoppedHook != null) { continuationOnStoppedHook(); continuationOnStoppedHook = null; return; } PlaybackStopped?.Invoke(sender, EventArgs.Empty); }
public void Play() { PlaybackState = PlaybackState.Playing; int read = 0; byte[] buffer = new byte[ReadRate]; while ((read = prov.Read(buffer, 0, ReadRate)) > 0) { BufferUpdated?.Invoke(this, new BufferUpdatedEventArgs(buffer, 0, read)); } PlaybackStopped?.Invoke(this, new StoppedEventArgs()); }
/// <summary> /// Processes the media session event. /// </summary> private void ProcessEvent() { while (m_Session != null) { try { m_Session.GetEvent(1, out IMFMediaEvent _event);//requests events and returns immediately _event.GetType(out MediaEventType eventtype); switch (eventtype) { case MediaEventType.MESessionEnded: PlaybackState = PlaybackState.Stopped; PlaybackStopped?.Invoke(this, new StoppedEventArgs()); break; case MediaEventType.MESessionTopologyStatus: //topology loaded Guid guidManager = typeof(IAudioSessionManager).GUID; (new MMDeviceEnumeratorComObject() as IMMDeviceEnumerator). GetDefaultAudioEndpoint(CoreAudioApi.DataFlow.Render, CoreAudioApi.Role.Multimedia, out IMMDevice endoint); endoint.Activate(ref guidManager, ClsCtx.ALL, IntPtr.Zero, out object _manager); IAudioSessionManager manager = _manager as IAudioSessionManager; manager.GetSimpleAudioVolume(Guid.Empty, 0, out m_volume); m_Session.GetClock(out m_clock); Guid guid_ratecontrol = typeof(IMFRateControl).GUID; Guid MF_RATE_CONTROL_SERVICE = Guid.Parse("866fa297-b802-4bf8-9dc9-5e3b6a9f53c9"); MediaFoundationInterop.MFGetService(m_Session, ref MF_RATE_CONTROL_SERVICE, ref guid_ratecontrol, out object _control); //gets rate control m_rate = _control as IMFRateControl; Prepared = true; break; } _event = null; } catch (COMException e) { if (e.HResult == MediaFoundationErrors.MF_E_NO_EVENTS_AVAILABLE) { continue; } else { throw e; } } catch (ThreadAbortException) { break; } } }
public void Stop() { if (m_Session == null) { throw new InvalidOperationException("This player hasn't initialized yet"); } if (!Prepared) { throw new InvalidOperationException("This player is still loading."); } m_Session.Stop(); PlaybackState = PlaybackState.Stopped; PlaybackStopped?.Invoke(this, new StoppedEventArgs()); }
public RecordingManager() { _waveIn = new WaveIn(); _waveIn.DataAvailable += _waveIn_DataAvailable; _waveIn.WaveFormat = new WaveFormat(44100, 1); if (WaveIn.DeviceCount > 0) { _waveIn.StartRecording(); } _waveOut = new WaveOut(); _waveOut.Init(this); _waveOut.PlaybackStopped += (s, e) => { PlaybackStopped?.Invoke(); }; }
/// <summary> /// Stop playing the current sequence. /// </summary> public void stopPlayback() { if (playing) { medicalController.OnLoopUpdate -= medicalController_OnLoopUpdate; playing = false; if (currentSequence != null) { currentSequence.setPosition(0.0f); } if (PlaybackStopped != null) { PlaybackStopped.Invoke(this); } } }
private void OnPlaybackStopped(object sender, StoppedEventArgs args) { lock (_path) { if (_outputDevice != null) { _outputDevice.Dispose(); _outputDevice = null; if (_audioFile != null) { _audioFile.Dispose(); _audioFile = null; } } } IsPlaying = false; PlaybackStopped?.Invoke(sender, args); }
public void Play() { int ms = 100; int perRead = prov.WaveFormat.AverageBytesPerSecond / ms; byte[] buffer = new byte[prov.WaveFormat.AverageBytesPerSecond]; Task.Run(() => { if (disposing) { return; } while (prov.Read(buffer, 0, perRead) > 0) { Task.Delay(ms).Wait(); } PlaybackStopped?.Invoke(this, new StoppedEventArgs()); }); }
private void Wave_PlaybackStopped(object sender, StoppedEventArgs e) { if (disposeReaders.Count > 0) { lock (disposeReaders) { while (disposeReaders.Count > 0) { disposeReaders.Dequeue().Dispose(); } Monitor.Pulse(disposeReaders); } ExecutePlayState(); } else { PlaybackStopped?.Invoke(this, e); } }
private void StopInternal(bool songEndedByCallback) { ResourceStopped?.Invoke(this, new SongEndEventArgs(songEndedByCallback)); if (songEndedByCallback) { var result = Next(CurrentPlayData?.Invoker ?? InvokerData.Anonymous, false); if (result.Ok) { return; } Log.Info("Song queue ended: {0}", result.Error); } else { playerConnection.Stop(); } CurrentPlayData = null; PlaybackStopped?.Invoke(this, EventArgs.Empty); }
public void Play() { Task.Run(() => { PlaybackState = PlaybackState.Playing; int read = 0; byte[] buffer = new byte[prov.WaveFormat.SampleRate]; while ((read = prov.Read(buffer, 0, prov.WaveFormat.SampleRate)) > 0 && !disposing) { while (PlaybackState != PlaybackState.Playing) { if (disposing) { return; } } } PlaybackStopped?.Invoke(this, new StoppedEventArgs()); }); }
private async Task StopInternal(bool songEndedByCallback) { await ResourceStopped.InvokeAsync(this, new SongEndEventArgs(songEndedByCallback)); if (songEndedByCallback) { try { await Next(CurrentPlayData?.Invoker ?? InvokerData.Anonymous, false); return; } catch (AudioBotException ex) { Log.Info("Song queue ended: {0}", ex.Message); } } else { playerConnection.Stop(); } CurrentPlayData = null; PlaybackStopped?.Invoke(this, EventArgs.Empty); }
public void Clear() { Stop(false); stream = null; playbackEndedNotifier = null; }
protected virtual void OnPlaybackStopped(StoppedEventArgs e) { playing = false; PlaybackStopped?.Invoke(this, e); }
private void OnPlayBackStopped(object sender, StoppedEventArgs e) { PlaybackStopped?.Invoke(); _player?.Dispose(); _audioFileReader?.Dispose(); }
private void OnPlaybackEnded() { Log.Info("Playback ended for some reason"); PlaybackStopped?.Invoke(this, EventArgs.Empty); }
public void Play() { if (IsRecording) { throw new ApplicationException("Can't play while recording."); } if (!File.Exists(FilePath)) { throw new FileNotFoundException("Could not find sound file"); } if (new FileInfo(FilePath).Length == 0) { throw new Exception("Trying to play empty file"); } // Current version doesn't use IrrKlang for playback. // Recently we've had all kinds of problems with IrrKlang playback, // mainly connected with the sound completed event. // One version crashed if a sound completed event happened and the handler // wasn't in the right AppDomain (breaking many unit tests) // Another version crahsed at the end of the sound, even in a real app. // The current version, according to my tests, never generates the sound completed event. // So, just use the built-in system sound player. _player.Stop(); _player.SoundLocation = FilePath; var worker = new BackgroundWorker(); IsPlaying = true; worker.DoWork += (sender, args) => { try { _player.PlaySync(); PlaybackStopped?.Invoke(this, new EventArgs()); IsPlaying = false; } catch (Exception e) { // Try to clean things up as best we can...no easy way to test this, though. // We don't want to be permanently in the playing state. IsPlaying = false; // And, in case something critical is waiting for this... PlaybackStopped?.Invoke(this, new EventArgs()); // Maybe the system has another way of playing it that works? e.g., most default players will handle mp3. // But it seems risky...maybe we will be trying to play another sound or do some recording? // Decided not to do this for now. // Process.Start(FilePath); // The main thread has gone on with other work, don't have any current way to report the exception. } }; worker.RunWorkerAsync(); //if (_sound != null) //{ // try // { // _engine.RemoveAllSoundSources(); // Stops sounds currently playing // } // catch (Exception) // { // // The most likely exception is that the sound has finished playing // } // _engine.StopAllSounds(); // Stops sounds after playing // _sound.Dispose(); // _sound = null; //} //if (!File.Exists(_path)) // throw new FileNotFoundException("Could not find sound file", _path); //_sound = _engine.Play2D(_path); //if (_sound != null) //{ // _sound.setSoundStopEventReceiver(_irrklangEventProxy, _engine); // return; //} //if (new FileInfo(_path).Length == 0) throw new Exception("Empty File"); //// if BytesPerSecond is 0 or _sound is null, it's probably a format we don't recognize. See if the OS knows how to play it. //Process.Start(_path); }
public void Stop() { waveOut.Stop(); inStream.Position = 0; PlaybackStopped.Invoke(this, EventArgs.Empty); }