public bool EnsurePlaybackStreamIsDead() { if (CurrentState == State.NotReady) { return(false); } bool I_Closed_The_Stream = m_CurrentAudioStream != null; if (I_Closed_The_Stream) { m_CurrentAudioStream.Close(); m_CurrentAudioStream = null; } m_CurrentAudioPCMFormat = null; m_CurrentAudioDataLength = 0; m_CurrentAudioStreamProvider = null; return(I_Closed_The_Stream); }
public void PlayBytes(StreamProviderDelegate currentAudioStreamProvider, long dataLength, AudioLibPCMFormat pcmInfo, long bytesFrom, long bytesTo) { if (pcmInfo == null) { throw new ArgumentNullException("PCM format cannot be null !"); } if (currentAudioStreamProvider == null) { throw new ArgumentNullException("Stream cannot be null !"); } if (dataLength <= 0) { throw new ArgumentOutOfRangeException("Duration cannot be <= 0 !"); } if (CurrentState == State.NotReady) { return; } if (CurrentState != State.Stopped) { Debug.Fail("Attempting to play when not stopped ? " + CurrentState); return; } #if USE_SOUNDTOUCH if (false && pcmInfo.NumberOfChannels > 1) { m_UseSoundTouch = false; //TODO: stereo all scrambled with SoundTouch !! } else { m_UseSoundTouch = m_UseSoundTouchBackup; } #endif // USE_SOUNDTOUCH m_CurrentAudioStreamProvider = currentAudioStreamProvider; m_CurrentAudioStream = m_CurrentAudioStreamProvider(); m_CurrentAudioPCMFormat = pcmInfo; m_CurrentAudioDataLength = dataLength; long startPosition = 0; if (bytesFrom > 0) { startPosition = m_CurrentAudioPCMFormat.AdjustByteToBlockAlignFrameSize(bytesFrom); } long endPosition = 0; if (bytesTo > 0) { endPosition = m_CurrentAudioPCMFormat.AdjustByteToBlockAlignFrameSize(bytesTo); } if (m_CurrentAudioPCMFormat.BytesAreEqualWithMillisecondsTolerance(startPosition, 0)) { startPosition = 0; } if (m_CurrentAudioPCMFormat.BytesAreEqualWithMillisecondsTolerance(endPosition, dataLength)) { endPosition = dataLength; } if (m_CurrentAudioPCMFormat.BytesAreEqualWithMillisecondsTolerance(endPosition, 0)) { endPosition = 0; } if (endPosition != 0 && m_CurrentAudioPCMFormat.BytesAreEqualWithMillisecondsTolerance(endPosition, startPosition)) { return; } if (startPosition >= 0 && (endPosition == 0 || startPosition < endPosition) && endPosition <= dataLength) { if (m_FwdRwdRate == 0) { startPlayback(startPosition, endPosition); Console.WriteLine("starting playback "); } else if (m_FwdRwdRate > 0) { FastForward(startPosition); Console.WriteLine("fast forward "); } else if (m_FwdRwdRate < 0) { if (startPosition == 0) { startPosition = m_CurrentAudioStream.Length; } Rewind(startPosition); Console.WriteLine("Rewind "); } } else { //throw new Exception("Start/end positions out of bounds of audio asset."); DebugFix.Assert(false); } }