Пример #1
0
 public override void play()
 {
     if (SDL_mixer.Mix_PlayingMusic() == 0)
     {
         if (SDL_mixer.Mix_PlayMusic(music, 0) == -1)
         {
             Console.WriteLine($"There was an issue playing the music. {SDL.SDL_GetError()}");
             Environment.Exit(-1);
         }
     }
 }
Пример #2
0
 public bool IsPlaying(int channel = -1)
 {
     if (channel == MusicChannel)
     {
         return(SDL_mixer.Mix_PlayingMusic() == 1);
     }
     else
     {
         return(SDL_mixer.Mix_Playing(channel) == 1);
     }
 }
    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();
    }
Пример #4
0
 public static bool PlayingMusic()
 {
     return(SDL_mixer.Mix_PlayingMusic() != 0);
 }
Пример #5
0
        static int Main(string[] args)
        {
            SDL.SDL_SetHint(SDL.SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING, "1");
            Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
            Thread.CurrentThread.CurrentCulture   = CultureInfo.InvariantCulture;

            //Start up SDL and create window
            var success = Init();

            if (success == false)
            {
                Console.WriteLine("Failed to initialize!");
            }
            else
            {
                //Load media
                success = LoadMedia();
                if (success == false)
                {
                    Console.WriteLine("Failed to load media!");
                }
                else
                {
                    //Main loop flag
                    bool quit = false;

                    //While application is running
                    while (!quit)
                    {
                        //Event handler
                        SDL.SDL_Event e;

                        //Handle events on queue
                        while (SDL.SDL_PollEvent(out e) != 0)
                        {
                            //User requests quit
                            if (e.type == SDL.SDL_EventType.SDL_QUIT)
                            {
                                quit = true;
                            }
                            //Handle key press
                            else if (e.type == SDL.SDL_EventType.SDL_KEYDOWN)
                            {
                                switch (e.key.keysym.sym)
                                {
                                //Play high sound effect
                                case SDL.SDL_Keycode.SDLK_1:
                                    SDL_mixer.Mix_PlayChannel(-1, _High, 0);
                                    break;

                                //Play medium sound effect
                                case SDL.SDL_Keycode.SDLK_2:
                                    SDL_mixer.Mix_PlayChannel(-1, _Medium, 0);
                                    break;

                                //Play low sound effect
                                case SDL.SDL_Keycode.SDLK_3:
                                    SDL_mixer.Mix_PlayChannel(-1, _Low, 0);
                                    break;

                                //Play scratch sound effect
                                case SDL.SDL_Keycode.SDLK_4:
                                    SDL_mixer.Mix_PlayChannel(-1, _Scratch, 0);
                                    break;

                                case SDL.SDL_Keycode.SDLK_9:
                                    //If there is no music playing
                                    if (SDL_mixer.Mix_PlayingMusic() == 0)
                                    {
                                        //Play the music
                                        SDL_mixer.Mix_PlayMusic(_Music, -1);
                                    }
                                    //If music is being played
                                    else
                                    {
                                        //If the music is paused
                                        if (SDL_mixer.Mix_PausedMusic() == 1)
                                        {
                                            //Resume the music
                                            SDL_mixer.Mix_ResumeMusic();
                                        }
                                        //If the music is playing
                                        else
                                        {
                                            //Pause the music
                                            SDL_mixer.Mix_PauseMusic();
                                        }
                                    }
                                    break;

                                case SDL.SDL_Keycode.SDLK_0:
                                    //Stop the music
                                    SDL_mixer.Mix_HaltMusic();
                                    break;
                                }
                            }
                        }

                        //Clear screen
                        SDL.SDL_SetRenderDrawColor(Renderer, 0xFF, 0xFF, 0xFF, 0xFF);
                        SDL.SDL_RenderClear(Renderer);

                        //Render prompt
                        _PromptTexture.Render(0, 0);

                        //Update screen
                        SDL.SDL_RenderPresent(Renderer);
                    }
                }
            }


            //Free resources and close SDL
            Close();

            if (success == false)
            {
                Console.ReadLine();
            }

            return(0);
        }