📄 playlist.java
字号:
/*
* JCollapse - Java Collapse Game
* Copyright (C) 2005 Erico Gon鏰lves Rimoli
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package sourceforge.net.projects.jcollapse.engine.sound;
import java.util.Collection;
import java.util.TreeMap;
/**
* Store a PlayList of Sound's and manage this
* @author erico
*/
public class PlayList {
private TreeMap<String, Sound> m_PlayList = new TreeMap<String, Sound>();
/**
* Constructor for PlayList
*/
public PlayList() {
}
/**
* Add a new Sound to PlayList
* @param name the name of Sound
* @param sound the Sound
*/
public void addSound( String name, Sound sound ) {
m_PlayList.put( name, sound );
}
/**
* Get the Sound
* @param name the name of Sound
* @return the Sound by name
*/
public Sound getSound( String name ) {
return m_PlayList.get( name );
}
/**
* Return a collection of sounds stored in PlayList
* @return a collection of sounds stored in PlayList
*/
public Collection<Sound> getSoundCollection() {
return m_PlayList.values();
}
/**
* Remove the Sound from PlayList
* @param name the name of Sound
* @return the removed Sound
*/
public Sound removeSound( String name ) {
return m_PlayList.remove( name );
}
/**
* Clear the playlist
*/
public void clear() {
m_PlayList.clear();
}
/**
* The size of PlayList
* @return the size of PlayList
*/
public int size() {
return m_PlayList.size();
}
/**
* Play Sound by name
* @param name name of Sound
*/
public void play( String name ) {
getSound( name ).play();
}
/**
* Pause Sound by name
* @param name name of Sound
*/
public void pause( String name ) {
getSound( name ).pause();
}
/**
* Dispause the game
* @param name name of Sound
*/
public void resume( String name ) {
getSound( name ).resume();
}
/**
* Stop Sound by name
* @param name name of Sound
*/
public void stop( String name ) {
getSound( name ).stop();
}
/**
* Play sound in loop mode
* @param name the Sound name
* @param loop enable or not the loop mode
*/
public void setLoop( String name, boolean loop ) {
getSound( name ).setLoop( loop );
}
/**
* Initialize Sound system
* @param name the name of the Sound
* @throws SoundException fired when a Sound initialization exception occur
*/
public void initialize( String name ) throws SoundException {
getSound( name ).initialize();
}
/**
* Stop playback and release resources used by Sound
* @param name the name of sound
*/
public void release( String name ) {
getSound( name ).release();
}
/**
* Stop all playback and release all resources used by Sound's
*/
public void release() {
for( Sound s : m_PlayList.values() )
if( s.isInitialized() )
s.release();
}
/**
* Initilize all Sound's
* @throws SoundException fired when any SoundException occurs
*/
public void initialize() throws SoundException {
for( Sound s : m_PlayList.values() )
s.initialize();
}
/**
* Get information about sound initialization. If Sound is ready to
* play, return true
* @param name the Sound name
* @return return true if Sound is ready to play
*/
public boolean isInitialized( String name ) {
return getSound( name ).isInitialized();
}
/**
* If all Sound's are initializad, return true. Initialized means that Sound is
* ready to be played
* @return true if all Sound's are ready to be played
*/
public boolean isInitialized() {
for( Sound s : m_PlayList.values() )
if( !s.isInitialized() )
return false;
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -