Skip to content

Commit

Permalink
Nokia: Sound: Realize player after creating it, and check loop val
Browse files Browse the repository at this point in the history
Some jars won't get the media on the required state for playback
otherwise. Fixes Banjo-Kazooie and Speed Devils.
  • Loading branch information
AShiningRay committed Dec 2, 2024
1 parent 5946959 commit 6eb05b8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/com/nokia/mid/sound/Sound.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ public int getState()

public void init(byte[] data, int type)
{
/* NOTE: Maybe we should realize() here? */
try
{
if (player != null) { player.close(); }
Expand All @@ -122,7 +121,8 @@ else if (type == FORMAT_WAV)
else if(data[0] == 'R' && data[1] == 'I' && data[2] == 'F' && data[3] == 'F') { format = "audio/wav"; }
else { Mobile.log(Mobile.LOG_WARNING, Sound.class.getPackage().getName() + "." + Sound.class.getSimpleName() + ": " + " couldn't find what format this is. Passing as FORMAT_WAV."); format = "audio/wav";}

player = Manager.createPlayer(new ByteArrayInputStream(data), format);
player = Manager.createPlayer(new ByteArrayInputStream(data), format);
player.realize();
}
else { throw new IllegalArgumentException("Nokia Sound: Invalid audio format: " + type); }
}
Expand All @@ -143,7 +143,8 @@ public void init(int freq, long duration)

public void play(int loop)
{
if(loop == 0) { loop = -1; }
if(loop < 0) { throw new IllegalArgumentException("Cannot play media, invalid loop value received"); }
else if(loop == 0) { loop = -1; }
player.setLoopCount(loop);
player.start();
}
Expand Down

0 comments on commit 6eb05b8

Please sign in to comment.