PageRenderTime 20ms CodeModel.GetById 14ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/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
23use strict;
24use warnings;
25
26use lib 'lib';
27use SDL;
28use SDLx::Sound;
29use SDLx::App;
30use SDL::Event;
31use SDL::Events; 
32
33my $app = SDLx::App->new(
34		height => 120,
35		width  => 480,
36		depth  => 16,
37		title  => 'Sound example',
38		);
39my $snd = SDLx::Sound->new();
40
41# load and play a sound
42my $play = $snd->play('test/data/sample.wav');
43
44# pause or resume on keydown 
45$app->add_event_handler( sub{
46		my $e = $_[0];
47		$_[1]->stop() if $e->type == SDL_QUIT;
48		if( $e->type == SDL_KEYDOWN )
49		{ 
50		print "Ai\n"; 
51		if($play){
52		$snd->pause;
53		$play=0;
54		}else{
55		$snd->resume;
56		$play=1;
57		} 
58		}    
59		} );
60
61$app->run();
62