Specify a fallback sound path in the constructor to be used if
a sound cannot be found. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2315 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: SoundManager.java,v 1.50 2003/03/17 18:50:18 ray Exp $
|
// $Id: SoundManager.java,v 1.51 2003/03/22 18:14:00 ray Exp $
|
||||||
|
|
||||||
package com.threerings.media.sound;
|
package com.threerings.media.sound;
|
||||||
|
|
||||||
@@ -90,11 +90,15 @@ public class SoundManager
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a sound manager.
|
* Constructs a sound manager.
|
||||||
|
*
|
||||||
|
* @param defaultClipPath The pathname of a sound clip to use as a
|
||||||
|
* fallback if another sound clip cannot be located.
|
||||||
*/
|
*/
|
||||||
public SoundManager (ResourceManager rmgr)
|
public SoundManager (ResourceManager rmgr, String defaultClipPath)
|
||||||
{
|
{
|
||||||
// save things off
|
// save things off
|
||||||
_rmgr = rmgr;
|
_rmgr = rmgr;
|
||||||
|
_defaultClipPath = defaultClipPath;
|
||||||
|
|
||||||
if (!SOUND_ENABLED) return;
|
if (!SOUND_ENABLED) return;
|
||||||
|
|
||||||
@@ -664,14 +668,7 @@ public class SoundManager
|
|||||||
data = new byte[names.length][];
|
data = new byte[names.length][];
|
||||||
String bundle = c.getValue("bundle", (String)null);
|
String bundle = c.getValue("bundle", (String)null);
|
||||||
for (int ii=0; ii < names.length; ii++) {
|
for (int ii=0; ii < names.length; ii++) {
|
||||||
InputStream clipin = null;
|
data[ii] = loadClipData(bundle, names[ii]);
|
||||||
try {
|
|
||||||
clipin = _rmgr.getResource(bundle, names[ii]);
|
|
||||||
} catch (FileNotFoundException fnfe) {
|
|
||||||
// try from the classpath
|
|
||||||
clipin = _rmgr.getResource(names[ii]);
|
|
||||||
}
|
|
||||||
data[ii] = StreamUtils.streamAsBytes(clipin, BUFFER_SIZE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -707,6 +704,43 @@ public class SoundManager
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read the data from the resource manager.
|
||||||
|
*/
|
||||||
|
protected byte[] loadClipData (String bundle, String path)
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
InputStream clipin = null;
|
||||||
|
try {
|
||||||
|
clipin = _rmgr.getResource(bundle, path);
|
||||||
|
} catch (FileNotFoundException fnfe) {
|
||||||
|
// try from the classpath
|
||||||
|
try {
|
||||||
|
clipin = _rmgr.getResource(path);
|
||||||
|
} catch (FileNotFoundException fnfe2) {
|
||||||
|
Log.warning("Could not locate sound data [bundle=" + bundle +
|
||||||
|
", path=" + path + "].");
|
||||||
|
if (_defaultClipPath != null) {
|
||||||
|
try {
|
||||||
|
clipin = _rmgr.getResource(_defaultClipPath);
|
||||||
|
} catch (FileNotFoundException fnfe3) {
|
||||||
|
Log.warning("Additionally, the default fallback " +
|
||||||
|
"sound could not be located [path=" +
|
||||||
|
_defaultClipPath + "].");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.warning("No fallback default sound specified!");
|
||||||
|
}
|
||||||
|
// if we couldn't load the default, rethrow
|
||||||
|
if (clipin == null) {
|
||||||
|
throw fnfe2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return StreamUtils.streamAsBytes(clipin, BUFFER_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
protected Config getConfig (SoundKey key)
|
protected Config getConfig (SoundKey key)
|
||||||
{
|
{
|
||||||
Config c = (Config) _configs.get(key.pkgPath);
|
Config c = (Config) _configs.get(key.pkgPath);
|
||||||
@@ -1043,6 +1077,9 @@ public class SoundManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** The path of the default sound to use for missing sounds. */
|
||||||
|
protected String _defaultClipPath;
|
||||||
|
|
||||||
/** The resource manager from which we obtain audio files. */
|
/** The resource manager from which we obtain audio files. */
|
||||||
protected ResourceManager _rmgr;
|
protected ResourceManager _rmgr;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user