// Operaciones

    /// Constructor a partir de un nombre de fichero
    public Sonido(string nombreFichero)
    {
        punteroInterno = SdlMixer.Mix_LoadMUS(nombreFichero);
    }
Exemple #2
0
        public static void Run()
        {
            Sdl.SDL_Event evt;
            bool          quitFlag = false;
            int           flags    = (Sdl.SDL_HWSURFACE | Sdl.SDL_DOUBLEBUF | Sdl.SDL_ANYFORMAT);
            int           bpp      = 16;
            int           width    = 352;
            int           height   = 240;

            Sdl.SDL_Init(Sdl.SDL_INIT_EVERYTHING);
            Sdl.SDL_WM_SetCaption("Tao.Sdl Example - SmpegPlayer", "");
            surfacePtr = Sdl.SDL_SetVideoMode(
                width,
                height,
                bpp,
                flags);
            SdlMixer.Mix_OpenAudio(SdlMixer.MIX_DEFAULT_FREQUENCY, unchecked (Sdl.AUDIO_S16LSB), 2, 1024);
            Smpeg.SMPEG_Info info = new Smpeg.SMPEG_Info();

            string filePath      = Path.Combine("..", "..");
            string fileDirectory = "Data";
            string fileName      = "SdlExamples.SmpegPlayer.mpg";

            if (File.Exists(fileName))
            {
                filePath      = "";
                fileDirectory = "";
            }
            else if (File.Exists(Path.Combine(fileDirectory, fileName)))
            {
                filePath = "";
            }

            string file = Path.Combine(Path.Combine(filePath, fileDirectory), fileName);

            //SdlMixer.MixFunctionDelegate audioMixer = new SdlMixer.MixFunctionDelegate(this.player);
            //int freq;
            //short format;
            //int channels;
            SdlMixer.Mix_CloseAudio();
            IntPtr intPtr = Smpeg.SMPEG_new(file, out info, 1);

            //Smpeg.SMPEG_enableaudio(intPtr, 0);
            //SdlMixer.Mix_QuerySpec(out freq, out unchecked(format), out channels);
            //Sdl.SDL_AudioSpec audiofmt = new Tao.Sdl.Sdl.SDL_AudioSpec();
            //audiofmt.freq = freq;
            //audiofmt.format = unchecked(format);
            //audiofmt.channels = (byte) channels;
            //Console.WriteLine("Freq: " + audiofmt.freq);
            //Console.WriteLine("Format: " + audiofmt.format);
            //Console.WriteLine("Channels: " + audiofmt.channels);

            Smpeg.SMPEG_getinfo(intPtr, out info);
            Console.WriteLine("Time: " + info.total_time.ToString());
            Console.WriteLine("Width: " + info.width.ToString());
            Console.WriteLine("Height: " + info.height.ToString());
            Console.WriteLine("Size: " + info.total_size.ToString());
            Console.WriteLine("Smpeg_error: " + Smpeg.SMPEG_error(intPtr));

            //Smpeg.SMPEG_actualSpec(intPtr, ref audiofmt);
            //SdlMixer.Mix_HookMusic(audioMixer, intPtr);
            Smpeg.SMPEG_setdisplay(intPtr, surfacePtr, IntPtr.Zero, null);

            Smpeg.SMPEG_play(intPtr);
            //Smpeg.SMPEG_loop(intPtr, 1);
            //Smpeg.SMPEG_enableaudio(intPtr, 1);

            try
            {
                while ((Smpeg.SMPEG_status(intPtr) == Smpeg.SMPEG_PLAYING) &&
                       (quitFlag == false))
                {
                    Sdl.SDL_PollEvent(out evt);

                    if (evt.type == Sdl.SDL_QUIT)
                    {
                        quitFlag = true;
                    }
                    else if (evt.type == Sdl.SDL_KEYDOWN)
                    {
                        if ((evt.key.keysym.sym == (int)Sdl.SDLK_ESCAPE) ||
                            (evt.key.keysym.sym == (int)Sdl.SDLK_q))
                        {
                            quitFlag = true;
                        }
                    }
                }
            }
            catch
            {
                Smpeg.SMPEG_stop(intPtr);
                Smpeg.SMPEG_delete(intPtr);
                Sdl.SDL_Quit();
                throw;
            }
            finally
            {
                Smpeg.SMPEG_stop(intPtr);
                Smpeg.SMPEG_delete(intPtr);
                Sdl.SDL_Quit();
            }
        }
        public static void Run()
        {
            int  flags    = (Sdl.SDL_HWSURFACE | Sdl.SDL_DOUBLEBUF | Sdl.SDL_ANYFORMAT);
            int  bpp      = 16;
            int  width    = 640;
            int  height   = 480;
            bool quitFlag = false;

            Random rand = new Random();

            string filePath      = Path.Combine("..", "..");
            string fileDirectory = "Data";
            string fileName      = "SdlExamples.Rectangles.sound.ogg";

            if (File.Exists(fileName))
            {
                filePath      = "";
                fileDirectory = "";
            }
            else if (File.Exists(Path.Combine(fileDirectory, fileName)))
            {
                filePath = "";
            }

            string file = Path.Combine(Path.Combine(filePath, fileDirectory), fileName);

            Sdl.SDL_Event evt;

            try
            {
                Sdl.SDL_Init(Sdl.SDL_INIT_EVERYTHING);
                Sdl.SDL_WM_SetCaption("Tao.Sdl Example - Rectangles", "");
                IntPtr surfacePtr = Sdl.SDL_SetVideoMode(
                    width,
                    height,
                    bpp,
                    flags);

                int result = SdlMixer.Mix_OpenAudio(
                    SdlMixer.MIX_DEFAULT_FREQUENCY,
                    (short)SdlMixer.MIX_DEFAULT_FORMAT,
                    2,
                    1024);
                IntPtr chunkPtr = SdlMixer.Mix_LoadMUS(file);

                SdlMixer.MusicFinishedDelegate musicStopped =
                    new SdlMixer.MusicFinishedDelegate(musicHasStopped);
                SdlMixer.Mix_HookMusicFinished(musicStopped);

                result = SdlMixer.Mix_PlayMusic(chunkPtr, 1);
                if (result == -1)
                {
                    Console.WriteLine("Music Error: " + Sdl.SDL_GetError());
                }

                int rmask = 0x00000000;
                int gmask = 0x00ff0000;
                int bmask = 0x0000ff00;
                int amask = 0x000000ff;

                IntPtr rgbSurfacePtr = Sdl.SDL_CreateRGBSurface(
                    flags,
                    width,
                    height,
                    bpp,
                    rmask,
                    gmask,
                    bmask,
                    amask);

                Sdl.SDL_Rect rect = new Sdl.SDL_Rect(
                    0,
                    0,
                    (short)width,
                    (short)height);
                result = Sdl.SDL_FillRect(rgbSurfacePtr, ref rect, 0);

                Sdl.SDL_Rect rect2;

                IntPtr videoInfoPointer = Sdl.SDL_GetVideoInfo();
                if (videoInfoPointer == IntPtr.Zero)
                {
                    throw new ApplicationException(string.Format("Video query failed: {0}", Sdl.SDL_GetError()));
                }

                Sdl.SDL_VideoInfo videoInfo = (Sdl.SDL_VideoInfo)
                                              Marshal.PtrToStructure(videoInfoPointer,
                                                                     typeof(Sdl.SDL_VideoInfo));
                Console.WriteLine("Hi There");

                Sdl.SDL_PixelFormat pixelFormat = (Sdl.SDL_PixelFormat)
                                                  Marshal.PtrToStructure(videoInfo.vfmt,
                                                                         typeof(Sdl.SDL_PixelFormat));

                Console.WriteLine(videoInfo.hw_available);
                Console.WriteLine(videoInfo.wm_available);
                Console.WriteLine(videoInfo.blit_hw);
                Console.WriteLine(videoInfo.blit_hw_CC);
                Console.WriteLine(videoInfo.blit_hw_A);
                Console.WriteLine(videoInfo.blit_sw);
                Console.WriteLine(videoInfo.blit_hw_CC);
                Console.WriteLine(videoInfo.blit_hw_A);
                Console.WriteLine(videoInfo.blit_fill);
                Console.WriteLine(videoInfo.video_mem);
                Console.WriteLine(pixelFormat.BitsPerPixel);
                Console.WriteLine(pixelFormat.BytesPerPixel);
                Console.WriteLine(pixelFormat.Rmask);
                Console.WriteLine(pixelFormat.Gmask);
                Console.WriteLine(pixelFormat.Bmask);
                Console.WriteLine(pixelFormat.Amask);

                int             numevents = 10;
                Sdl.SDL_Event[] events    = new Sdl.SDL_Event[numevents];
                events[0].type           = Sdl.SDL_KEYDOWN;
                events[0].key.keysym.sym = (int)Sdl.SDLK_p;
                events[1].type           = Sdl.SDL_KEYDOWN;
                events[1].key.keysym.sym = (int)Sdl.SDLK_z;
                int result2 = Sdl.SDL_PeepEvents(events, numevents, Sdl.SDL_ADDEVENT, Sdl.SDL_KEYDOWNMASK);
                Console.WriteLine("Addevent result: " + result2);

                while (quitFlag == false)
                {
                    result = Sdl.SDL_PollEvent(out evt);

                    if (evt.type == Sdl.SDL_QUIT)
                    {
                        quitFlag = true;
                    }
                    else if (evt.type == Sdl.SDL_KEYDOWN)
                    {
                        if ((evt.key.keysym.sym == (int)Sdl.SDLK_ESCAPE) ||
                            (evt.key.keysym.sym == (int)Sdl.SDLK_q))
                        {
                            quitFlag = true;
                        }
                        if (evt.key.keysym.sym == (int)Sdl.SDLK_p)
                        {
                            Console.WriteLine("Key p event was added");
                        }
                        if (evt.key.keysym.sym == (int)Sdl.SDLK_z)
                        {
                            Console.WriteLine("Key z event was added");
                        }
                    }

                    rect2 = new Sdl.SDL_Rect(
                        (short)rand.Next(-300, width),
                        (short)rand.Next(-300, height),
                        (short)rand.Next(20, 300),
                        (short)rand.Next(20, 300));

                    try
                    {
                        result = Sdl.SDL_FillRect(
                            surfacePtr,
                            ref rect2,
                            rand.Next(100000));
                        result = Sdl.SDL_BlitSurface(
                            rgbSurfacePtr,
                            ref rect2,
                            surfacePtr,
                            ref rect);
                        result = Sdl.SDL_Flip(surfacePtr);
                    }
                    catch (Exception) { }
                }
            }
            catch
            {
                Sdl.SDL_Quit();
                throw;
            }
            finally
            {
                Sdl.SDL_Quit();
            }
        }
Exemple #4
0
 ///< Frees the memory used by SdlMixer.
 public void unload()//not being called yet.
 {
     SdlMixer.Mix_FreeMusic(handle);
 }