v0.6.2a: fixed errors where music would be called without being prepared
This commit is contained in:
parent
25e840b427
commit
0ce6f14a73
|
@ -61,16 +61,15 @@ public enum Music implements MediaPlayer.OnPreparedListener, MediaPlayer.OnError
|
||||||
|
|
||||||
AssetFileDescriptor afd = Game.instance.getAssets().openFd( assetName );
|
AssetFileDescriptor afd = Game.instance.getAssets().openFd( assetName );
|
||||||
|
|
||||||
player = new MediaPlayer();
|
MediaPlayer mp = new MediaPlayer();
|
||||||
player.setAudioStreamType( AudioManager.STREAM_MUSIC );
|
mp.setAudioStreamType( AudioManager.STREAM_MUSIC );
|
||||||
player.setDataSource( afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength() );
|
mp.setDataSource( afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength() );
|
||||||
player.setOnPreparedListener( this );
|
mp.setOnPreparedListener( this );
|
||||||
player.setOnErrorListener( this );
|
mp.setOnErrorListener( this );
|
||||||
player.prepareAsync();
|
mp.prepareAsync();
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
||||||
player.release();
|
|
||||||
player = null;
|
player = null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -82,17 +81,16 @@ public enum Music implements MediaPlayer.OnPreparedListener, MediaPlayer.OnError
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPrepared( MediaPlayer player ) {
|
public void onPrepared( MediaPlayer mp ) {
|
||||||
|
player = mp;
|
||||||
player.start();
|
player.start();
|
||||||
player.setLooping(looping);
|
player.setLooping(looping);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onError( MediaPlayer mp, int what, int extra ) {
|
public boolean onError( MediaPlayer mp, int what, int extra ) {
|
||||||
if (player != null) {
|
mp.release();
|
||||||
player.release();
|
player = null;
|
||||||
player = null;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user