Esempio n. 1
0
        public void Play(MusicAudioSource musicSource)
        {
            currentLength = Length;
            source        = musicSource;
            source.SetVolume(1f, Settings.MusicVolume * Settings.MasterVolume);

            // Queue first buffers
            for (int i = 0; i < MusicAudioBufferRotator.BufferCount - 1; i++)
            {
                source.QueueBuffer(nextBuffer());
            }
        }
Esempio n. 2
0
        public void Tick()
        {
            if (firstTick)
            {
                source.Start();
            }

            firstTick = false;

            if (!paused)
            {
                currentLength--;
                if (!Done)
                {
                    // Let the rotation begin!
                    var buffers = source.BuffersProcessed();
                    for (int i = 0; i < buffers; i++)
                    {
                        // Fill next buffer
                        if (rotator.CurrentWriteRotation < rotator.MaxRotations)
                        {
                            fillBuffer();
                        }

                        // Unqueue last buffer and queue next one
                        source.UnqueueBuffer();

                        if (rotator.CurrentReadRotation < rotator.MaxRotations)
                        {
                            source.QueueBuffer(nextBuffer());
                        }
                    }

                    if (looping && rotator.CurrentWriteRotation == rotator.MaxRotations)
                    {
                        reader.BaseStream.Seek(musicSeekPosition, SeekOrigin.Begin);
                        rotator.Reset();
                    }

                    // If something in tick took too long, the source stops playing automatically. Recognize stop and restart playing.
                    if (buffers >= MusicAudioBufferRotator.BufferCount - 1)
                    {
                        source.Start();
                    }
                }
            }
        }