Exemplo n.º 1
0
        public override void Play()
        {
            if (IsPlaying == false)
            {
                channel = SdlMixer.Mix_PlayChannel(-1, sound, LoopCount);

                if (channel == -1)
                {
                    Trace.WriteLine(string.Format("Error: {0}", SdlMixer.Mix_GetError()));
                }
            }
            else
            {
                SdlMixer.Mix_PlayChannel(channel, sound, LoopCount);
            }

            SetPanning();
            SetVolume();

            watch.Reset();
            watch.Start();

            audio.RegisterChannel(channel, this);

            mIsPlaying = true;
        }
Exemplo n.º 2
0
        public void SetGetError()
        {
            string error = "Hi there";

            SdlMixer.Mix_SetError(error);
            Assert.AreEqual(SdlMixer.Mix_GetError(), error);
        }
        /**
         * Constructor initializes SDL Audio
         * allocates DEFAULTNUMCHANNELS channels
         * and sets the SDL ChannelFinished delegate
         *
         * @param theEngine The Engine.
         */
        public AudioComponent(MirrorEngine engine)
            : base(engine)
        {
            if (Sdl.SDL_InitSubSystem(Sdl.SDL_INIT_AUDIO) != 0)
            {
                throw new Exception("Could not init SDL Audio: " + Sdl.SDL_GetError());
            }

            if (SdlMixer.Mix_OpenAudio(44100, (short)Sdl.AUDIO_S16SYS, 2, 2048) == -1)
            {
                throw new Exception("Could not init SDL_Mixer: " + SdlMixer.Mix_GetError());
            }

            //Channel Setup
            openChannels = new LinkedList <int>();
            addChannels(DEFAULTNUMCHANNELS);
            cfinished = freeChannel;
            SdlMixer.Mix_ChannelFinished(cfinished);
        }
        /**
         * Plays a Handle to an ogg file. Any previously playing music will be stopped
         *
         * @param song The song to play. Providing no song will play the currentSong.
         *
         * @param loop whether or not to loop the music.
         */
        public void playSong(bool loop, Handle song = null)
        {
            if (song == null)
            {
                song = currentSong;
            }
            if (song == null)
            {
                return;
            }

            SongSample sample   = song.getResource <SongSample>();
            int        retValue = SdlMixer.Mix_PlayMusic(sample.handle, (loop) ? -1 : 1);

            if (retValue == -1)
            {
                Trace.WriteLine("Music::play(): Could not play music: " + SdlMixer.Mix_GetError());
            }
            else
            {
                currentSong = song;
            }
        }