/// <summary> /// Begins playing the given clip. /// </summary> /// <param name="file">The clip to play.</param> public void Play(VorbisFileInstance clip) { DequeuUsedBuffers(); CurrentFormat = DetermineFormat(clip); CurrentRate = DetermineRate(clip); CurrentClip = clip; eof = false; // Buffer initial audio int usedBuffers = 0; for (int i = 0; i < BufferCount; i++) { int bytesRead = clip.read(SegmentBuffer, SegmentBuffer.Length, _BIGENDIANREADMODE, _WORDREADMODE, _SGNEDREADMODE, null); if (bytesRead > 0) { // Buffer the segment AL.BufferData(Buffers[i], CurrentFormat, SegmentBuffer, bytesRead, CurrentRate); usedBuffers++; } else if (bytesRead == 0) { // Clip is too small to fill the initial buffer, so stop // buffering. break; } else { // TODO: There was an error reading the file throw new System.IO.IOException("Error reading or processing OGG file"); } } // Start playing the clip AL.SourceQueueBuffers(Source, usedBuffers, Buffers); AL.SourcePlay(Source); }
// PLAY public void PlaySource(VorbisFileInstance source) { // Remove any empty buffers RemoveEmptyBuffers(); // Set up all the source parameters AudioFormat = DetermineSourceFormat(source); AudioRate = DetermineSourceRate(source); // Initialize the source to play SourceFile = source; FileHasEnded = false; // Start buffer int processedBuffers = 0; for (int i = 0; i < BufferCount; i++) { int bytesRead = source.read(SegmentBuffer, SegmentBuffer.Length, _BIGENDIANREADMODE, _WORDREADMODE, _SGNEDREADMODE, null); if (bytesRead > 0) { AL.BufferData(Buffers[i], AudioFormat, SegmentBuffer, bytesRead, AudioRate); processedBuffers++; } else if (bytesRead == 0) { break; } else { throw new System.IO.IOException("Unable to open OGG File"); } } // Play buffered clip AL.SourceQueueBuffers(Source, processedBuffers, Buffers); AL.SourcePlay(Source); }