public static void Main() { int audio_rate = 44100; ushort audio_format = SDL.AUDIO_S16SYS; int audio_channels = 2; int audio_buffers = 4096; int audio_volume = SDL_mixer.MIX_MAX_VOLUME; int timeleft = 50; SDL.SDL_Init(SDL.SDL_INIT_AUDIO); if (SDL_mixer.Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) < 0) { return; } else { SDL_mixer.Mix_QuerySpec(out audio_rate, out audio_format, out audio_channels); } SDL_mixer.Mix_AllocateChannels(32); SDL_mixer.Mix_VolumeMusic(audio_volume / 3); System.IntPtr music = SDL_mixer.Mix_LoadMUS("Tetris_theme.ogg"); System.IntPtr wave = SDL_mixer.Mix_LoadWAV("Meow.ogg"); SDL_mixer.Mix_FadeInMusic(music, 1, 2000); while (SDL_mixer.Mix_PlayingMusic() != 0) { SDL.SDL_Delay(100); timeleft--; if (timeleft == 0) { break; } if (timeleft == 25) { SDL_mixer.Mix_PlayChannel(-1, wave, 0); } } SDL_mixer.Mix_FadeOutMusic(2000); SDL_mixer.Mix_FreeMusic(music); SDL_mixer.Mix_FreeChunk(wave); SDL.SDL_Delay(500); SDL_mixer.Mix_CloseAudio(); SDL.SDL_Quit(); }
/// <summary> /// Plays music, stopping any currently playing music first. /// </summary> /// <param name="music">The music to play.</param> /// <param name="looping">Whether or not the music should repeat until stopped.</param> /// <param name="fadeTime">The amount of time (in seconds) to fade in the music's volume.</param> public static void PlayMusic(Music music, bool looping = true, float fadeTime = 0) { SDL_mixer.Mix_FadeInMusic(music.Handle, looping ? -1 : 0, GetFadeTimeMs(fadeTime)); }
public void FadeIn(int MS, int Loops = 0) { Util.ThrowIfResultIsError(SDL_mixer.Mix_FadeInMusic(myPtr, Loops, MS)); }
private void LoadAndPlayMusic() { MusicPointer = SDL_mixer.Mix_LoadMUS(MusicFilePath); SDL_mixer.Mix_FadeInMusic(MusicPointer.Value, -1, 1000); SDL_mixer.Mix_VolumeMusic(MusicVolume); }