Ejemplo n.º 1
0
    /// <summary>
    /// Plays a sound. Returns an instance handle that can be passed to StopSound() to stop playback of the sound.
    /// </summary>
    /// <param name="sound">The sound to play.</param>
    /// <param name="repeat">Whether or not the sound should repeat until stopped.</param>
    /// <param name="fadeTime">The amount of time (in seconds) to fade in the sound's volume.</param>
    public static SoundInstance PlaySound(Sound sound, bool repeat = false, float fadeTime = 0)
    {
        // Start playing the new sound:
        int channel = SDL_mixer.Mix_FadeInChannel(-1, sound.Handle, repeat ? -1 : 0, GetFadeTimeMs(fadeTime));

        // Silently fail when we run out of channels:
        if (channel == -1)
        {
            return(new SoundInstance());
        }

        // Invalidate old sound instances using this channel:
        foreach (var instanceAndChannel in SoundInstances)
        {
            if (instanceAndChannel.Value == channel)
            {
                SoundInstances.Remove(instanceAndChannel.Key);
                break;
            }
        }

        // Return a new sound instance for this channel:
        SoundInstance instance = new SoundInstance();

        SoundInstances[instance] = channel;
        return(instance);
    }
Ejemplo n.º 2
0
        public int FadeInChannel(int MS, int Channel = -1, int Loops = 0)
        {
            int Result = SDL_mixer.Mix_FadeInChannel(Channel, myPtr, Loops, MS);

            if (Result == -1)
            {
                throw new SDLErrorException(Result);
            }

            return(Result);
        }