indexing description: "[ EiffelMedia AUDIO example. Plays a sound file using SDL_mixer. ]" date: "$Date$" revision: "$Revision$" class SOUND inherit EM_SHARED_SUBSYSTEMS export {NONE} all end EM_AUDIO_CONSTANTS export {NONE} all end KL_SHARED_FILE_SYSTEM export {NONE} all end KL_SHARED_EXECUTION_ENVIRONMENT export {NONE} all end create make feature -- Initialization make is -- This example shows how to simply play music. -- As there is nothing else using CPU resources, -- this example shows how to set better values as -- standard ones. local player: EM_MUSIC_PLAYER do -- create event loop create event_loop.make_poll -- Initialize video subsystem Video_subsystem.set_video_surface_width (640) Video_subsystem.set_video_surface_height (480) Video_subsystem.set_video_bpp (24) Video_subsystem.set_fullscreen (False) Video_subsystem.set_opengl (False) video_subsystem.set_hardware_surface (False) video_subsystem.set_software_surface (True) Video_subsystem.enable -- Initialize audio subsystem Audio_subsystem.enable if Audio_subsystem.is_enabled and Video_subsystem.is_enabled then -- Open mixer with a frequency of 44.1 kHz Audio_subsystem.mixer.open (44100, Em_audio_format_s16sys, Em_stereo, Em_default_chunk_size) -- Initialize musicplayer with one single file create player.make_with_file (file_system.pathname (Music_directory, "wish_you_were_here.ogg"), false) player.set_repeat (true) player.play event_loop.key_down_event.subscribe (agent handle_key_down_event (?)) event_loop.quit_event.subscribe (agent handle_quit_event (?)) event_loop.dispatch -- Free up resources Audio_subsystem.disable Video_subsystem.disable else io.put_string ("Audio or video subsystem could not be enabled!%N") end end feature -- Events handle_key_down_event (a_keyboard_event: EM_KEYBOARD_EVENT) is -- Handle key down event. require a_keyboard_event_not_void: a_keyboard_event /= Void do if a_keyboard_event.key = a_keyboard_event.sdlk_return then event_loop.stop end end handle_quit_event (a_quit_event: EM_QUIT_EVENT) is -- Handle quit event. require a_quit_event_not_void: a_quit_event /= Void do event_loop.stop end feature {NONE} -- Implementation Music_directory: STRING is -- Music directory once Result := file_system.pathname_from_file_system ("$EM/example/resources/music", unix_file_system) Result := execution_environment.interpreted_string (Result) if not file_system.directory_exists (Result) then Result := "." end end event_loop: EM_EVENT_LOOP -- Event loop end