View Javadoc

    1   /*
    2    * All Rights Reserved.
    3    * Copyright (C) 1999-2005 Tsukuba Bunko.
    4    *
    5    * Licensed under the BSD License ("the License"); you may not use
    6    * this file except in compliance with the License.
    7    * You may obtain a copy of the License at
    8    *
    9    *       http://www.tsukuba-bunko.org/licenses/LICENSE.txt
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   *
    17   * $Id: SoundHandler.java,v 1.2 2005/08/19 03:18:11 ppoi Exp $
    18   */
    19  package tsukuba_bunko.peko.scenario.stage;
    20
    21  import	org.xml.sax.Attributes;
    22
    23  import	tsukuba_bunko.peko.Logger;
    24
    25  import tsukuba_bunko.peko.canvas.stage.AudioPlayer;
    26  import	tsukuba_bunko.peko.scenario.PSMLUtil;
    27
    28
    29  /***
    30   * <samp>start-bgm</samp>, <samp>stop-bgm</samp>, <samp>start-se</samp>,
    31   * <samp>stop-se</samp> 要素を処理する <code>ElementHandler</code> です。
    32   * @author	$Author: ppoi $
    33   * @version	$Revision: 1.2 $ $Date: 2005/08/19 03:18:11 $
    34   */
    35  public class SoundHandler	extends StageElementHandler	{
    36
    37  	/***
    38  	 * <code>SoundHandler</code> のインスタンスを作成します。
    39  	 */
    40  	public SoundHandler()
    41  	{
    42  		super();
    43  	}
    44
    45
    46  //
    47  //	ContentHandler の実装
    48  //
    49  	public void startDocument()
    50  	{
    51  	}
    52
    53  	public void endDocument()
    54  	{
    55  	}
    56
    57  	public void startElement( String namespaceURI, String localName, String qName, Attributes attrs )
    58  	{
    59  		String	id = PSMLUtil.getAttributeValue( attrs, "id" );
    60  		if( id == null )	{
    61  			Logger.error( MessageIDs.SCN3003E, new Object[]{getSceneContext().getCurrentPath()} );
    62  			return;
    63  		}
    64
    65  		String	clipName = null;
    66  		String	loop = null;
    67  		boolean	lp = false;
    68
    69  		StageCoordinator	coordinator = getStageCoordinator();
    70  		if( "play-bgm".equals(localName) )	{
    71  			clipName = PSMLUtil.getAttributeValue( attrs, "clip" );
    72  			if( clipName == null )	{
    73  				Logger.warn( MessageIDs.SCN3004W, new Object[]{getSceneContext().getCurrentPath()} );
    74  				return;
    75  			}
    76
    77  			loop = PSMLUtil.getAttributeValue( attrs, "loop" );
    78  			if( loop != null )	{
    79  				lp = (loop.equalsIgnoreCase("true") || loop.equalsIgnoreCase("yes") || loop.equalsIgnoreCase("on"));
    80  			}
    81  			else	{
    82  				lp = true;
    83  			}
    84
    85  			coordinator.playBGM( id, clipName, lp );
    86  		}
    87  		else if( "play-se".equals(localName) )	{
    88  			clipName = PSMLUtil.getAttributeValue( attrs, "clip" );
    89  			if( clipName == null )	{
    90  				Logger.warn( MessageIDs.SCN3004W, new Object[]{getSceneContext().getCurrentPath()} );
    91  				return;
    92  			}
    93
    94  			loop = PSMLUtil.getAttributeValue( attrs, "loop" );
    95  			if( loop != null )	{
    96  				lp = (loop.equalsIgnoreCase("true") || loop.equalsIgnoreCase("yes") || loop.equalsIgnoreCase("on"));
    97  			}
    98  			else	{
    99  				lp = false;
    100 			}
    101
    102 			coordinator.playSE( id, clipName, lp );
    103 		}
    104 		else if( "stop-bgm".equals(localName) )	{
    105 			int	fadeoutMode = AudioPlayer.STOP_WITH_ASYNC_FADEOUT;
    106 			String	fadeout = PSMLUtil.getAttributeValue( attrs, "fadeout" );
    107 			if( fadeout != null )	{
    108 				if( "sync".equals(fadeout) )	{
    109 					fadeoutMode = AudioPlayer.STOP_WITH_SYNC_FADEOUT;
    110 				}
    111 				else if( "none".equals(fadeout) )	{
    112 					fadeoutMode = AudioPlayer.STOP_IMMEDIATELY;
    113 				}
    114 				else if( "async".equals(fadeout) )	{
    115 					fadeoutMode = AudioPlayer.STOP_WITH_ASYNC_FADEOUT;
    116 				}
    117 				else	{
    118 					Logger.warn( MessageIDs.SCN3007W, new Object[]{getSceneContext().getCurrentPath(), "async"} );
    119 				}
    120 			}
    121 			coordinator.stopBGM( id, fadeoutMode );
    122 		}
    123 		else if( "stop-se".equals(localName) )	{
    124 			int	fadeoutMode = AudioPlayer.STOP_WITH_ASYNC_FADEOUT;
    125 			String	fadeout = PSMLUtil.getAttributeValue( attrs, "fadeout" );
    126 			if( fadeout != null )	{
    127 				if( "sync".equals(fadeout) )	{
    128 					fadeoutMode = AudioPlayer.STOP_WITH_SYNC_FADEOUT;
    129 				}
    130 				else if( "none".equals(fadeout) )	{
    131 					fadeoutMode = AudioPlayer.STOP_IMMEDIATELY;
    132 				}
    133 				else if( "async".equals(fadeout) )	{
    134 					fadeoutMode = AudioPlayer.STOP_WITH_ASYNC_FADEOUT;
    135 				}
    136 				else	{
    137 					Logger.warn( MessageIDs.SCN3007W, new Object[]{getSceneContext().getCurrentPath(), "async"} );
    138 				}
    139 			}
    140 			coordinator.stopSE( id, fadeoutMode );
    141 		}
    142 	}
    143 }