/examples/SDLx/SDLx_Sound.pl

http://github.com/PerlGameDev/SDL · Perl · 62 lines · 32 code · 7 blank · 23 comment · 5 complexity · c32fab60961f40479a56ae076002b9e6 MD5 · raw file

  1. #!/usr/bin/perl
  2. #==========================================================================
  3. #
  4. # FILE: SDLx_Sound.pl
  5. #
  6. # USAGE: ./examples/SDLx_Sound.pl
  7. #
  8. #
  9. # DESCRIPTION: Sound tests
  10. # A SDLx::Sound can play, pause, resume and stop
  11. #
  12. # OPTIONS: ---
  13. # REQUIREMENTS: ---
  14. # BUGS: ---
  15. # NOTES: ---
  16. # AUTHOR: Ricardo Filipo (rf), ricardo.filipo@gmail.com
  17. # COMPANY: Mito-Lógica design e soluções de comunicação ltda
  18. # VERSION: 1.0
  19. # CREATED: 16-08-2010 21:47:33
  20. # REVISION: ---
  21. #==========================================================================
  22. use strict;
  23. use warnings;
  24. use lib 'lib';
  25. use SDL;
  26. use SDLx::Sound;
  27. use SDLx::App;
  28. use SDL::Event;
  29. use SDL::Events;
  30. my $app = SDLx::App->new(
  31. height => 120,
  32. width => 480,
  33. depth => 16,
  34. title => 'Sound example',
  35. );
  36. my $snd = SDLx::Sound->new();
  37. # load and play a sound
  38. my $play = $snd->play('test/data/sample.wav');
  39. # pause or resume on keydown
  40. $app->add_event_handler( sub{
  41. my $e = $_[0];
  42. $_[1]->stop() if $e->type == SDL_QUIT;
  43. if( $e->type == SDL_KEYDOWN )
  44. {
  45. print "Ai\n";
  46. if($play){
  47. $snd->pause;
  48. $play=0;
  49. }else{
  50. $snd->resume;
  51. $play=1;
  52. }
  53. }
  54. } );
  55. $app->run();