indexing description: "Objects that manages all the sound events" author: "Florian Keusch, fkeusch@student.ethz.ch, Markus Neidhart, nemarkus@student.ethz.ch and UC Team" date: "$Date$" revision: "$Revision$" class MUSIC_PLAYER inherit EM_AUDIO_CONSTANTS export {NONE} all end create make feature -- Initialization make is -- create `musictrack' do -- set default sound string sound_dir := "sound" create extensions.make extensions.put_last ("ogg") -- create music_player create music_player.make_with_path (sound_dir, extensions, false, true) max_volume := Em_max_volume end feature -- player functions reinit is -- reinit player do music_player.playlist.make_with_path (sound_dir, extensions, true) end open_sound (track: STRING) is -- opens the soundfile specified by `track'. Has to be a .ogg file. do music_player.playlist.make_with_file (track) music_player.play end play () is -- plays loaded soundfile do music_player.play end stop () is -- stop loaded soundfile do music_player.stop end pause () is -- pause loaded soundfile if playing -- unpause loaded soundfile if stopped do if music_player.is_paused then music_player.play else music_player.pause end end next () is -- plays the next song do music_player.forth end previous () is -- plays the previous song do music_player.back end set_volume (vol: INTEGER) is -- sets the volume require volume_in_range: vol >= 0 and vol <= max_volume do music_player.set_volume (vol) end turn_up is -- set the volume louder do if music_player.volume <= Em_max_volume - 10 then music_player.set_volume(music_player.volume + 10) else music_player.set_volume (Em_max_volume) end end turn_down is -- turns the volume down do if music_player.volume >= 10 then music_player.set_volume(music_player.volume - 10) else music_player.set_volume (0) end end mute is -- set volume to 1 -- backup old volume do if music_player.volume = 0 then music_player.set_volume (volume_before_mute) else volume_before_mute := music_player.volume music_player.set_volume (0) end end play_song (a_string: STRING) is -- plays the song with the string -- caution: string must exist do music_player.playlist.make_with_file (a_string) music_player.play end feature -- Implemenation music_player: EM_MUSIC_PLAYER extensions: DS_LINKED_LIST[STRING_8] volume_before_mute: INTEGER feature -- Status is_playing: BOOLEAN is -- checks if player is playing do result := music_player.is_playing and not music_player.is_paused end is_stopped: BOOLEAN is -- checks if player is stopped do result := not music_player.is_playing end is_paused: BOOLEAN is -- checks whether player is paused do result := music_player.is_paused end song_nr: INTEGER is -- get the song number do result := music_player.playlist.index end song_title: STRING is -- get the song title -- with path do result := music_player.music_playing.filename end volume: INTEGER is -- gives back the music volume do result := music_player.volume end song_title_cut: STRING is -- get the song title cut local s: STRING do create s.make_from_string (song_title.substring (sound_dir.count + 2,song_title.count)) s.remove_tail (4) result := s end is_empty: BOOLEAN is -- checks if player has items to play do result := music_player.playlist.count = 0 end feature -- Access max_volume: INTEGER sound_dir: STRING -- string that indicates the sound directory end -- class MUSIC_PLAYER