@ -64,136 +64,132 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level ;
import java.util.logging.Level ;
import java.util.logging.Logger ;
import java.util.logging.Logger ;
/ * *
/ * *
* This class is the android implementation for { @link AudioRenderer }
* This class is the android implementation for { @link AudioRenderer }
* @author larynx
* @author larynx
*
*
* /
* /
public class AndroidAudioRenderer implements AudioRenderer , SoundPool . OnLoadCompleteListener , MediaPlayer . OnCompletionListener
public class AndroidAudioRenderer implements AudioRenderer , SoundPool . OnLoadCompleteListener , MediaPlayer . OnCompletionListener {
{
private static final Logger logger = Logger . getLogger ( AndroidAudioRenderer . class . getName ( ) ) ;
private static final Logger logger = Logger . getLogger ( AndroidAudioRenderer . class . getName ( ) ) ;
private final static int MAX_NUM_CHANNELS = 16 ;
private final static int MAX_NUM_CHANNELS = 16 ;
private SoundPool soundPool = null ;
private SoundPool soundPool = null ;
private HashMap < AudioNode , MediaPlayer > musicPlaying = new HashMap < AudioNode , MediaPlayer > ( ) ;
private HashMap < AudioNode , MediaPlayer > musicPlaying = new HashMap < AudioNode , MediaPlayer > ( ) ;
private final Vector3f listenerPosition = new Vector3f ( ) ;
private final Vector3f listenerPosition = new Vector3f ( ) ;
// For temp use
// For temp use
private final Vector3f distanceVector = new Vector3f ( ) ;
private final Vector3f distanceVector = new Vector3f ( ) ;
private final AudioManager manager ;
private final AudioManager manager ;
private final Context context ;
private final Context context ;
private final AssetManager am ;
private final AssetManager am ;
private HashMap < Integer , AudioNode > mapLoadingAudioNodes = new HashMap < Integer , AudioNode > ( ) ;
private HashMap < Integer , AudioNode > mapLoadingAudioNodes = new HashMap < Integer , AudioNode > ( ) ;
private final AtomicBoolean lastLoadCompleted = new AtomicBoolean ( ) ;
private final AtomicBoolean lastLoadCompleted = new AtomicBoolean ( ) ;
private Listener listener ;
private Listener listener ;
private boolean audioDisabled = false ;
private boolean audioDisabled = false ;
public AndroidAudioRenderer ( Activity context ) {
public AndroidAudioRenderer ( Activity context )
{
this . context = context ;
this . context = context ;
manager = ( AudioManager ) context . getSystemService ( Context . AUDIO_SERVICE ) ;
manager = ( AudioManager ) context . getSystemService ( Context . AUDIO_SERVICE ) ;
context . setVolumeControlStream ( AudioManager . STREAM_MUSIC ) ;
context . setVolumeControlStream ( AudioManager . STREAM_MUSIC ) ;
am = context . getAssets ( ) ;
am = context . getAssets ( ) ;
}
}
@Override
@Override
public void initialize ( )
public void initialize ( ) {
{
soundPool = new SoundPool ( MAX_NUM_CHANNELS , AudioManager . STREAM_MUSIC , 0 ) ;
soundPool = new SoundPool ( MAX_NUM_CHANNELS , AudioManager . STREAM_MUSIC , 0 ) ;
soundPool . setOnLoadCompleteListener ( this ) ;
soundPool . setOnLoadCompleteListener ( this ) ;
}
}
@Override
@Override
public void updateSourceParam ( AudioNode src , AudioParam param )
public void updateSourceParam ( AudioNode src , AudioParam param ) {
{
//logger.log(Level.INFO, "updateSourceParam " + param);
//logger.log(Level.INFO, "updateSourceParam " + param);
if ( audioDisabled )
if ( audioDisabled ) {
return ;
return ;
}
if ( src . getChannel ( ) < 0 )
if ( src . getChannel ( ) < 0 ) {
return ;
return ;
}
assert src . getChannel ( ) > = 0 ;
assert src . getChannel ( ) > = 0 ;
switch ( param ) {
switch ( param ) {
case Position :
case Position :
if ( ! src . isPositional ( ) )
if ( ! src . isPositional ( ) ) {
return ;
return ;
}
Vector3f pos = src . getWorldTranslation ( ) ;
Vector3f pos = src . getWorldTranslation ( ) ;
break ;
break ;
case Velocity :
case Velocity :
if ( ! src . isPositional ( ) )
if ( ! src . isPositional ( ) ) {
return ;
return ;
}
Vector3f vel = src . getVelocity ( ) ;
Vector3f vel = src . getVelocity ( ) ;
break ;
break ;
case MaxDistance :
case MaxDistance :
if ( ! src . isPositional ( ) )
if ( ! src . isPositional ( ) ) {
return ;
return ;
}
break ;
break ;
case RefDistance :
case RefDistance :
if ( ! src . isPositional ( ) )
if ( ! src . isPositional ( ) ) {
return ;
return ;
}
break ;
break ;
case ReverbFilter :
case ReverbFilter :
if ( ! src . isPositional ( ) | | ! src . isReverbEnabled ( ) )
if ( ! src . isPositional ( ) | | ! src . isReverbEnabled ( ) ) {
return ;
return ;
}
break ;
break ;
case ReverbEnabled :
case ReverbEnabled :
if ( ! src . isPositional ( ) )
if ( ! src . isPositional ( ) ) {
return ;
return ;
}
if ( src . isReverbEnabled ( ) ) {
if ( src . isReverbEnabled ( ) ) {
updateSourceParam ( src , AudioParam . ReverbFilter ) ;
updateSourceParam ( src , AudioParam . ReverbFilter ) ;
}
}
break ;
break ;
case IsPositional :
case IsPositional :
break ;
break ;
case Direction :
case Direction :
if ( ! src . isDirectional ( ) )
if ( ! src . isDirectional ( ) ) {
return ;
return ;
}
Vector3f dir = src . getDirection ( ) ;
Vector3f dir = src . getDirection ( ) ;
break ;
break ;
case InnerAngle :
case InnerAngle :
if ( ! src . isDirectional ( ) )
if ( ! src . isDirectional ( ) ) {
return ;
return ;
}
break ;
break ;
case OuterAngle :
case OuterAngle :
if ( ! src . isDirectional ( ) )
if ( ! src . isDirectional ( ) ) {
return ;
return ;
}
break ;
break ;
case IsDirectional :
case IsDirectional :
if ( src . isDirectional ( ) ) {
if ( src . isDirectional ( ) ) {
updateSourceParam ( src , AudioParam . Direction ) ;
updateSourceParam ( src , AudioParam . Direction ) ;
updateSourceParam ( src , AudioParam . InnerAngle ) ;
updateSourceParam ( src , AudioParam . InnerAngle ) ;
updateSourceParam ( src , AudioParam . OuterAngle ) ;
updateSourceParam ( src , AudioParam . OuterAngle ) ;
} else {
} else {
}
}
break ;
break ;
case DryFilter :
case DryFilter :
if ( src . getDryFilter ( ) ! = null ) {
if ( src . getDryFilter ( ) ! = null ) {
Filter f = src . getDryFilter ( ) ;
Filter f = src . getDryFilter ( ) ;
if ( f . isUpdateNeeded ( ) ) {
if ( f . isUpdateNeeded ( ) ) {
//updateFilter(f);
//updateFilter(f);
}
}
}
}
break ;
break ;
case Looping :
case Looping :
if ( src . isLooping ( ) ) {
if ( src . isLooping ( ) ) {
}
}
break ;
break ;
case Volume :
case Volume :
@ -209,13 +205,13 @@ public class AndroidAudioRenderer implements AudioRenderer, SoundPool.OnLoadComp
}
}
@Override
@Override
public void updateListenerParam ( Listener listener , ListenerParam param )
public void updateListenerParam ( Listener listener , ListenerParam param ) {
{
//logger.log(Level.INFO, "updateListenerParam " + param);
//logger.log(Level.INFO, "updateListenerParam " + param);
if ( audioDisabled )
if ( audioDisabled ) {
return ;
return ;
}
switch ( param ) {
switch ( param ) {
case Position :
case Position :
listenerPosition . set ( listener . getLocation ( ) ) ;
listenerPosition . set ( listener . getLocation ( ) ) ;
@ -237,14 +233,12 @@ public class AndroidAudioRenderer implements AudioRenderer, SoundPool.OnLoadComp
}
}
@Override
@Override
public void update ( float tpf )
public void update ( float tpf ) {
{
float distance ;
float distance ;
float volume ;
float volume ;
// Loop over all mediaplayers
// Loop over all mediaplayers
for ( AudioNode src : musicPlaying . keySet ( ) )
for ( AudioNode src : musicPlaying . keySet ( ) ) {
{
MediaPlayer mp = musicPlaying . get ( src ) ;
MediaPlayer mp = musicPlaying . get ( src ) ;
{
{
@ -253,16 +247,17 @@ public class AndroidAudioRenderer implements AudioRenderer, SoundPool.OnLoadComp
distanceVector . subtractLocal ( src . getLocalTranslation ( ) ) ;
distanceVector . subtractLocal ( src . getLocalTranslation ( ) ) ;
distance = FastMath . abs ( distanceVector . length ( ) ) ;
distance = FastMath . abs ( distanceVector . length ( ) ) ;
if ( distance < src . getRefDistance ( ) )
if ( distance < src . getRefDistance ( ) ) {
distance = src . getRefDistance ( ) ;
distance = src . getRefDistance ( ) ;
if ( distance > src . getMaxDistance ( ) )
}
if ( distance > src . getMaxDistance ( ) ) {
distance = src . getMaxDistance ( ) ;
distance = src . getMaxDistance ( ) ;
}
volume = src . getRefDistance ( ) / distance ;
volume = src . getRefDistance ( ) / distance ;
AndroidAudioData audioData = ( AndroidAudioData ) src . getAudioData ( ) ;
AndroidAudioData audioData = ( AndroidAudioData ) src . getAudioData ( ) ;
if ( FastMath . abs ( audioData . getCurrentVolume ( ) - volume ) > FastMath . FLT_EPSILON )
if ( FastMath . abs ( audioData . getCurrentVolume ( ) - volume ) > FastMath . FLT_EPSILON ) {
{
// Left / Right channel get the same volume by now, only positional
// Left / Right channel get the same volume by now, only positional
mp . setVolume ( volume , volume ) ;
mp . setVolume ( volume , volume ) ;
@ -274,13 +269,12 @@ public class AndroidAudioRenderer implements AudioRenderer, SoundPool.OnLoadComp
}
}
}
}
public void setListener ( Listener listener ) {
public void setListener ( Listener listener )
if ( audioDisabled ) {
{
if ( audioDisabled )
return ;
return ;
}
if ( this . listener ! = null ) {
if ( this . listener ! = null ) {
// previous listener no longer associated with current
// previous listener no longer associated with current
// renderer
// renderer
this . listener . setRenderer ( null ) ;
this . listener . setRenderer ( null ) ;
@ -292,54 +286,41 @@ public class AndroidAudioRenderer implements AudioRenderer, SoundPool.OnLoadComp
}
}
@Override
@Override
public void onLoadComplete ( SoundPool soundPool , int sampleId , int status )
public void onLoadComplete ( SoundPool soundPool , int sampleId , int status ) {
{
AudioNode src = mapLoadingAudioNodes . get ( sampleId ) ;
AudioNode src = mapLoadingAudioNodes . get ( sampleId ) ;
if ( src . getAudioData ( ) instanceof AndroidAudioData )
if ( src . getAudioData ( ) instanceof AndroidAudioData ) {
{
AndroidAudioData audioData = ( AndroidAudioData ) src . getAudioData ( ) ;
AndroidAudioData audioData = ( AndroidAudioData ) src . getAudioData ( ) ;
if ( status = = 0 ) // load was successfull
if ( status = = 0 ) // load was successfull
{
{
int channelIndex ;
int channelIndex ;
channelIndex = soundPool . play ( audioData . getSound Id ( ) , 1f , 1f , 1 , - 1 , 1f ) ;
channelIndex = soundPool . play ( audioData . getId ( ) , 1f , 1f , 1 , - 1 , 1f ) ;
src . setChannel ( channelIndex ) ;
src . setChannel ( channelIndex ) ;
// Playing started ?
// Playing started ?
if ( src . getChannel ( ) > 0 )
if ( src . getChannel ( ) > 0 ) {
{
src . setStatus ( Status . Playing ) ;
src . setStatus ( Status . Playing ) ;
}
}
}
} else {
else
{
src . setChannel ( - 1 ) ;
src . setChannel ( - 1 ) ;
}
}
}
} else {
else
{
throw new IllegalArgumentException ( "AudioData is not of type AndroidAudioData for AudioNode " + src . toString ( ) ) ;
throw new IllegalArgumentException ( "AudioData is not of type AndroidAudioData for AudioNode " + src . toString ( ) ) ;
}
}
}
}
@Override
@Override
public void cleanup ( )
public void cleanup ( ) {
{
// Cleanup sound pool
// Cleanup sound pool
if ( soundPool ! = null )
if ( soundPool ! = null ) {
{
for ( AudioNode src : mapLoadingAudioNodes . values ( ) ) {
for ( AudioNode src : mapLoadingAudioNodes . values ( ) )
if ( ( src . getStatus ( ) = = Status . Playing ) & & ( src . getChannel ( ) > 0 ) ) {
{
if ( ( src . getStatus ( ) = = Status . Playing ) & & ( src . getChannel ( ) > 0 ) )
{
soundPool . stop ( src . getChannel ( ) ) ;
soundPool . stop ( src . getChannel ( ) ) ;
}
}
if ( src . getAudioData ( ) instanceof AndroidAudioData )
if ( src . getAudioData ( ) instanceof AndroidAudioData ) {
{
AndroidAudioData audioData = ( AndroidAudioData ) src . getAudioData ( ) ;
AndroidAudioData audioData = ( AndroidAudioData ) src . getAudioData ( ) ;
if ( audioData . getId ( ) > 0 ) {
if ( audioData . getSoundId ( ) > 0 )
soundPool . unload ( audioData . getId ( ) ) ;
{
soundPool . unload ( audioData . getSoundId ( ) ) ;
}
}
}
}
}
}
@ -349,8 +330,7 @@ public class AndroidAudioRenderer implements AudioRenderer, SoundPool.OnLoadComp
}
}
// Cleanup media player
// Cleanup media player
for ( AudioNode src : musicPlaying . keySet ( ) )
for ( AudioNode src : musicPlaying . keySet ( ) ) {
{
MediaPlayer mp = musicPlaying . get ( src ) ;
MediaPlayer mp = musicPlaying . get ( src ) ;
{
{
mp . stop ( ) ;
mp . stop ( ) ;
@ -362,12 +342,9 @@ public class AndroidAudioRenderer implements AudioRenderer, SoundPool.OnLoadComp
}
}
@Override
@Override
public void onCompletion ( MediaPlayer mp )
public void onCompletion ( MediaPlayer mp ) {
{
for ( AudioNode src : musicPlaying . keySet ( ) ) {
for ( AudioNode src : musicPlaying . keySet ( ) )
if ( musicPlaying . get ( src ) = = mp ) {
{
if ( musicPlaying . get ( src ) = = mp )
{
mp . seekTo ( 0 ) ;
mp . seekTo ( 0 ) ;
mp . stop ( ) ;
mp . stop ( ) ;
src . setStatus ( Status . Stopped ) ;
src . setStatus ( Status . Stopped ) ;
@ -377,39 +354,32 @@ public class AndroidAudioRenderer implements AudioRenderer, SoundPool.OnLoadComp
}
}
public void playSourceInstance ( AudioNode src )
public void playSourceInstance ( AudioNode src ) {
{
if ( audioDisabled ) {
if ( audioDisabled )
return ;
return ;
}
AndroidAudioData audioData ;
AndroidAudioData audioData ;
int soundId = 0 ;
int soundId = 0 ;
if ( src . getAudioData ( ) instanceof AndroidAudioData )
if ( src . getAudioData ( ) instanceof AndroidAudioData ) {
{
audioData = ( AndroidAudioData ) src . getAudioData ( ) ;
audioData = ( AndroidAudioData ) src . getAudioData ( ) ;
if ( audioData . getAssetKey ( ) instanceof AudioKey )
if ( audioData . getAssetKey ( ) instanceof AudioKey ) {
{
AudioKey assetKey = ( AudioKey ) audioData . getAssetKey ( ) ;
AudioKey assetKey = ( AudioKey ) audioData . getAssetKey ( ) ;
// streaming audionodes get played using android mediaplayer, non streaming uses SoundPool
// streaming audionodes get played using android mediaplayer, non streaming uses SoundPool
if ( assetKey . isStream ( ) )
if ( assetKey . isStream ( ) ) {
{
MediaPlayer mp ;
MediaPlayer mp ;
if ( musicPlaying . containsKey ( src ) )
if ( musicPlaying . containsKey ( src ) ) {
{
mp = musicPlaying . get ( src ) ;
mp = musicPlaying . get ( src ) ;
}
} else {
else
{
mp = new MediaPlayer ( ) ;
mp = new MediaPlayer ( ) ;
mp . setOnCompletionListener ( this ) ;
mp . setOnCompletionListener ( this ) ;
//mp = MediaPlayer.create(context, new Ur );
//mp = MediaPlayer.create(context, new Ur );
musicPlaying . put ( src , mp ) ;
musicPlaying . put ( src , mp ) ;
}
}
if ( ! mp . isPlaying ( ) )
if ( ! mp . isPlaying ( ) ) {
{
try {
try {
AssetFileDescriptor afd = am . openFd ( assetKey . getName ( ) ) ;
AssetFileDescriptor afd = am . openFd ( assetKey . getName ( ) ) ;
mp . setDataSource ( afd . getFileDescriptor ( ) , afd . getStartOffset ( ) , afd . getLength ( ) ) ;
mp . setDataSource ( afd . getFileDescriptor ( ) , afd . getStartOffset ( ) , afd . getLength ( ) ) ;
@ -420,8 +390,7 @@ public class AndroidAudioRenderer implements AudioRenderer, SoundPool.OnLoadComp
mp . start ( ) ;
mp . start ( ) ;
src . setChannel ( 1 ) ;
src . setChannel ( 1 ) ;
src . setStatus ( Status . Playing ) ;
src . setStatus ( Status . Playing ) ;
} catch ( IllegalArgumentException e )
} catch ( IllegalArgumentException e ) {
{
logger . log ( Level . SEVERE , "Failed to play " + assetKey . getName ( ) , e ) ;
logger . log ( Level . SEVERE , "Failed to play " + assetKey . getName ( ) , e ) ;
} catch ( IllegalStateException e ) {
} catch ( IllegalStateException e ) {
// TODO Auto-generated catch block
// TODO Auto-generated catch block
@ -433,63 +402,48 @@ public class AndroidAudioRenderer implements AudioRenderer, SoundPool.OnLoadComp
}
}
}
} else {
else
{
// Low latency Sound effect using SoundPool
// Low latency Sound effect using SoundPool
if ( audioData . isUpdateNeeded ( ) | | ( audioData . getSoundId ( ) < = 0 ) )
if ( audioData . isUpdateNeeded ( ) | | ( audioData . getId ( ) < = 0 ) ) {
{
if ( audioData . getId ( ) > 0 ) {
if ( audioData . getSoundId ( ) > 0 )
if ( src . getChannel ( ) > 0 ) {
{
if ( src . getChannel ( ) > 0 )
{
soundPool . stop ( src . getChannel ( ) ) ;
soundPool . stop ( src . getChannel ( ) ) ;
src . setChannel ( - 1 ) ;
src . setChannel ( - 1 ) ;
}
}
soundPool . unload ( audioData . getSound Id ( ) ) ;
soundPool . unload ( audioData . getId ( ) ) ;
}
}
try
try {
{
soundId = soundPool . load ( am . openFd ( assetKey . getName ( ) ) , 1 ) ;
soundId = soundPool . load ( am . openFd ( assetKey . getName ( ) ) , 1 ) ;
}
} catch ( IOException e ) {
catch ( IOException e )
{
logger . log ( Level . SEVERE , "Failed to load sound " + assetKey . getName ( ) , e ) ;
logger . log ( Level . SEVERE , "Failed to load sound " + assetKey . getName ( ) , e ) ;
soundId = - 1 ;
soundId = - 1 ;
}
}
audioData . setSound Id ( soundId ) ;
audioData . setId ( soundId ) ;
}
}
// Sound failed to load ?
// Sound failed to load ?
if ( audioData . getSoundId ( ) < = 0 )
if ( audioData . getId ( ) < = 0 ) {
{
throw new IllegalArgumentException ( "Failed to load: " + assetKey . getName ( ) ) ;
throw new IllegalArgumentException ( "Failed to load: " + assetKey . getName ( ) ) ;
}
} else {
else
{
int channelIndex ;
int channelIndex ;
channelIndex = soundPool . play ( audioData . getSoundId ( ) , 1f , 1f , 1 , - 1 , 1f ) ;
channelIndex = soundPool . play ( audioData . getId ( ) , 1f , 1f , 1 , - 1 , 1f ) ;
if ( channelIndex = = 0 )
if ( channelIndex = = 0 ) {
{
// Loading is not finished
// Loading is not finished
// Store the soundId and the AudioNode for async loading and later play start
// Store the soundId and the AudioNode for async loading and later play start
mapLoadingAudioNodes . put ( audioData . getSound Id ( ) , src ) ;
mapLoadingAudioNodes . put ( audioData . getId ( ) , src ) ;
}
}
src . setChannel ( channelIndex ) ;
src . setChannel ( channelIndex ) ;
}
}
// Playing started ?
// Playing started ?
if ( src . getChannel ( ) > 0 )
if ( src . getChannel ( ) > 0 ) {
{
src . setStatus ( Status . Playing ) ;
src . setStatus ( Status . Playing ) ;
}
}
}
}
}
}
}
} else {
else
{
throw new IllegalArgumentException ( "AudioData is not of type AndroidAudioData for AudioNode " + src . toString ( ) ) ;
throw new IllegalArgumentException ( "AudioData is not of type AndroidAudioData for AudioNode " + src . toString ( ) ) ;
}
}
@ -497,57 +451,44 @@ public class AndroidAudioRenderer implements AudioRenderer, SoundPool.OnLoadComp
}
}
public void playSource ( AudioNode src ) {
public void playSource ( AudioNode src )
if ( audioDisabled ) {
{
if ( audioDisabled )
return ;
return ;
}
//assert src.getStatus() == Status.Stopped || src.getChannel() == -1;
//assert src.getStatus() == Status.Stopped || src.getChannel() == -1;
if ( src . getStatus ( ) = = Status . Playing )
if ( src . getStatus ( ) = = Status . Playing ) {
{
return ;
return ;
}
} else if ( src . getStatus ( ) = = Status . Stopped ) {
else if ( src . getStatus ( ) = = Status . Stopped )
{
playSourceInstance ( src ) ;
playSourceInstance ( src ) ;
}
}
}
}
public void pauseSource ( AudioNode src ) {
public void pauseSource ( AudioNode src )
if ( audioDisabled ) {
{
if ( audioDisabled )
return ;
return ;
}
if ( src . getStatus ( ) = = Status . Playing )
if ( src . getStatus ( ) = = Status . Playing ) {
{
if ( src . getAudioData ( ) instanceof AndroidAudioData ) {
if ( src . getAudioData ( ) instanceof AndroidAudioData )
AndroidAudioData audioData = ( AndroidAudioData ) src . getAudioData ( ) ;
{
if ( audioData . getAssetKey ( ) instanceof AudioKey ) {
AndroidAudioData audioData = ( AndroidAudioData ) src . getAudioData ( ) ;
if ( audioData . getAssetKey ( ) instanceof AudioKey )
{
AudioKey assetKey = ( AudioKey ) audioData . getAssetKey ( ) ;
AudioKey assetKey = ( AudioKey ) audioData . getAssetKey ( ) ;
if ( assetKey . isStream ( ) )
if ( assetKey . isStream ( ) ) {
{
MediaPlayer mp ;
MediaPlayer mp ;
if ( musicPlaying . containsKey ( src ) )
if ( musicPlaying . containsKey ( src ) ) {
{
mp = musicPlaying . get ( src ) ;
mp = musicPlaying . get ( src ) ;
mp . pause ( ) ;
mp . pause ( ) ;
src . setStatus ( Status . Paused ) ;
src . setStatus ( Status . Paused ) ;
}
}
}
} else {
else
{
assert src . getChannel ( ) ! = - 1 ;
assert src . getChannel ( ) ! = - 1 ;
if ( src . getChannel ( ) > 0 )
if ( src . getChannel ( ) > 0 ) {
{
soundPool . pause ( src . getChannel ( ) ) ;
soundPool . pause ( src . getChannel ( ) ) ;
src . setStatus ( Status . Paused ) ;
src . setStatus ( Status . Paused ) ;
}
}
@ -559,50 +500,40 @@ public class AndroidAudioRenderer implements AudioRenderer, SoundPool.OnLoadComp
}
}
public void stopSource ( AudioNode src ) {
public void stopSource ( AudioNode src )
if ( audioDisabled ) {
{
if ( audioDisabled )
return ;
return ;
}
if ( src . getStatus ( ) ! = Status . Stopped )
if ( src . getStatus ( ) ! = Status . Stopped ) {
{
if ( src . getAudioData ( ) instanceof AndroidAudioData ) {
if ( src . getAudioData ( ) instanceof AndroidAudioData )
AndroidAudioData audioData = ( AndroidAudioData ) src . getAudioData ( ) ;
{
if ( audioData . getAssetKey ( ) instanceof AudioKey ) {
AndroidAudioData audioData = ( AndroidAudioData ) src . getAudioData ( ) ;
if ( audioData . getAssetKey ( ) instanceof AudioKey )
{
AudioKey assetKey = ( AudioKey ) audioData . getAssetKey ( ) ;
AudioKey assetKey = ( AudioKey ) audioData . getAssetKey ( ) ;
if ( assetKey . isStream ( ) )
if ( assetKey . isStream ( ) ) {
{
MediaPlayer mp ;
MediaPlayer mp ;
if ( musicPlaying . containsKey ( src ) )
if ( musicPlaying . containsKey ( src ) ) {
{
mp = musicPlaying . get ( src ) ;
mp = musicPlaying . get ( src ) ;
mp . stop ( ) ;
mp . stop ( ) ;
src . setStatus ( Status . Stopped ) ;
src . setStatus ( Status . Stopped ) ;
src . setChannel ( - 1 ) ;
src . setChannel ( - 1 ) ;
}
}
}
} else {
else
{
int chan = src . getChannel ( ) ;
int chan = src . getChannel ( ) ;
assert chan ! = - 1 ; // if it's not stopped, must have id
assert chan ! = - 1 ; // if it's not stopped, must have id
if ( src . getChannel ( ) > 0 )
if ( src . getChannel ( ) > 0 ) {
{
soundPool . stop ( src . getChannel ( ) ) ;
soundPool . stop ( src . getChannel ( ) ) ;
src . setChannel ( - 1 ) ;
src . setChannel ( - 1 ) ;
}
}
src . setStatus ( Status . Stopped ) ;
src . setStatus ( Status . Stopped ) ;
if ( audioData . getSoundId ( ) > 0 )
if ( audioData . getId ( ) > 0 ) {
{
soundPool . unload ( audioData . getId ( ) ) ;
soundPool . unload ( audioData . getSoundId ( ) ) ;
}
}
audioData . setSound Id ( - 1 ) ;
audioData . setId ( - 1 ) ;
@ -614,27 +545,22 @@ public class AndroidAudioRenderer implements AudioRenderer, SoundPool.OnLoadComp
}
}
public void updateAudioData ( AndroidAudioData data ) {
public void updateAudioData ( AndroidAudioData data )
{
throw new UnsupportedOperationException ( "updateAudioData" ) ;
throw new UnsupportedOperationException ( "updateAudioData" ) ;
}
}
public void deleteFilter ( Filter filter ) {
}
@Override
@Override
public void deleteAudioData ( AudioData ad )
public void deleteAudioData ( AudioData ad ) {
{
if ( ad instanceof AndroidAudioData ) {
if ( ad instanceof AndroidAudioData )
AndroidAudioData audioData = ( AndroidAudioData ) ad ;
{
if ( audioData . getAssetKey ( ) instanceof AudioKey ) {
AndroidAudioData audioData = ( AndroidAudioData ) ad ;
if ( audioData . getAssetKey ( ) instanceof AudioKey )
{
AudioKey assetKey = ( AudioKey ) audioData . getAssetKey ( ) ;
AudioKey assetKey = ( AudioKey ) audioData . getAssetKey ( ) ;
if ( assetKey . isStream ( ) )
if ( assetKey . isStream ( ) ) {
{
for ( AudioNode src : musicPlaying . keySet ( ) ) {
for ( AudioNode src : musicPlaying . keySet ( ) )
if ( src . getAudioData ( ) = = ad ) {
{
if ( src . getAudioData ( ) = = ad )
{
MediaPlayer mp = musicPlaying . get ( src ) ;
MediaPlayer mp = musicPlaying . get ( src ) ;
mp . stop ( ) ;
mp . stop ( ) ;
mp . release ( ) ;
mp . release ( ) ;
@ -644,20 +570,15 @@ public class AndroidAudioRenderer implements AudioRenderer, SoundPool.OnLoadComp
break ;
break ;
}
}
}
}
} else {
if ( audioData . getId ( ) > 0 ) {
soundPool . unload ( audioData . getId ( ) ) ;
}
}
else
audioData . setId ( 0 ) ;
{
if ( audioData . getSoundId ( ) > 0 )
{
soundPool . unload ( audioData . getSoundId ( ) ) ;
}
audioData . setSoundId ( 0 ) ;
}
}
}
}
}
} else {
else
{
throw new IllegalArgumentException ( "AudioData is not of type AndroidAudioData in deleteAudioData" ) ;
throw new IllegalArgumentException ( "AudioData is not of type AndroidAudioData in deleteAudioData" ) ;
}
}
}
}
@ -665,8 +586,5 @@ public class AndroidAudioRenderer implements AudioRenderer, SoundPool.OnLoadComp
@Override
@Override
public void setEnvironment ( Environment env ) {
public void setEnvironment ( Environment env ) {
// TODO Auto-generated method stub
// TODO Auto-generated method stub
}
}
}
}