From f2d57c30c2dc2e8161cacd713e7cdfc454281157 Mon Sep 17 00:00:00 2001 From: forteri76 Date: Sun, 11 May 2014 14:41:33 +0000 Subject: [PATCH] Eliminated spurious try/catch block. --- .../andmodplug/PlayerThread.java | 118 +++++++++++------- 1 file changed, 71 insertions(+), 47 deletions(-) diff --git a/src/com/peculiargames/andmodplug/PlayerThread.java b/src/com/peculiargames/andmodplug/PlayerThread.java index c4b3f8c..9abf716 100644 --- a/src/com/peculiargames/andmodplug/PlayerThread.java +++ b/src/com/peculiargames/andmodplug/PlayerThread.java @@ -129,24 +129,24 @@ public class PlayerThread extends Thread { /* * Constant for setPatternLoopRange() calls - change to - * new pattern range immediately + * new pattern range immediately. */ public final static int PATTERN_CHANGE_IMMEDIATE = 1; /* * Constant for setPatternLoopRange() calls - change to - * new pattern range after currently playing pattern finishes + * new pattern range after currently playing pattern finishes. */ public final static int PATTERN_CHANGE_AFTER_CURRENT = 2; /* * Constant for setPatternLoopRange() calls - change to - * new pattern range after current range of patterns finishes playing + * new pattern range after current range of patterns finishes playing. */ public final static int PATTERN_CHANGE_AFTER_GROUP = 3; /* - * Constant for setLoopCount() calls - loop song forever + * Constant for setLoopCount() calls - loop song forever. */ public final static int LOOP_SONG_FOREVER = -1; @@ -231,8 +231,9 @@ public boolean TakeOwnership(Object newowner) { mOwner = newowner; return true; } - else + else { return false; + } } public boolean GiveUpOwnership(Object currowner) { @@ -240,8 +241,9 @@ public boolean GiveUpOwnership(Object currowner) { mOwner = null; return true; } - else + else { return false; + } } public Object GetOwner() { @@ -253,7 +255,7 @@ public Object GetOwner() { //******************************************************************** /* - * Event types enumeration. + * Event types enumeration. */ public static enum eventEnum { PLAYER_STARTED, @@ -306,20 +308,10 @@ public PlayerThread(byte[] modData, int desiredrate) { this(desiredrate); /* - * Load the mod file (data) into libmodplug. + * Load the module file (data) into libmodplug and initialize module + * information variables. */ - mLoad_ok = ModPlug_JLoad(modData, modData.length); - - if (mLoad_ok) { - /* - * Get info (name and number of tracks) for the loaded MOD file. - */ - mModname = ModPlug_JGetName(); - mNumChannels = ModPlug_JNumChannels(); - posWas = 0; - songFinished = false; - songFinishedWas = false; - } + LoadModuleInfo(modData); } /** @@ -337,15 +329,20 @@ public PlayerThread(byte[] modData, int desiredrate) { * default rate) for system audio data playback. */ public PlayerThread(int desiredrate) { - // no Activity owns this player yet + /* + * No Activity owns this player yet. + */ mMytrack = null; mOwner = null; mStart_paused = false; sPlayerStarted = false; - // try to get the audio track - if (!GetAndroidAudioTrack(desiredrate)) + /* + * Try to get the audio track. + */ + if (!GetAndroidAudioTrack(desiredrate)) { return; + } mPlayerValid = true; } @@ -422,10 +419,12 @@ private boolean GetAndroidAudioTrack(int desiredrate) { ModPlug_Init(desiredrate); } - if (desiredrate == 0) + if (desiredrate == 0) { mRate = try_rates[rateindex]; - else + } + else { mRate = desiredrate; + } if (mMytrack == null) { mPlayerValid = false; @@ -475,15 +474,12 @@ private boolean GetAndroidAudioTrack(int desiredrate) { */ public void LoadMODData(byte[] modData) { UnLoadMod(); - mLoad_ok = ModPlug_JLoad(modData, modData.length); - if (mLoad_ok) { - mModname = ModPlug_JGetName(); - mNumChannels = ModPlug_JNumChannels(); - posWas = 0; - songFinished = false; - songFinishedWas = false; - } + /* + * Load the module file (data) into libmodplug and initialize module + * information variables. + */ + LoadModuleInfo(modData); /* * Re-init this flag so that an event will be passed to the @@ -495,6 +491,23 @@ public void LoadMODData(byte[] modData) { } } + /** + * Load the module file (data) into libmodplug. + *

If the module loads successfully, initialize module info (name + * and number of tracks, track playback location, etc.). + */ + private void LoadModuleInfo(byte[] modData) { + mLoad_ok = ModPlug_JLoad(modData, modData.length); + + if (mLoad_ok) { + mModname = ModPlug_JGetName(); + mNumChannels = ModPlug_JNumChannels(); + posWas = 0; + songFinished = false; + songFinishedWas = false; + } + } + /** * This PlayerValid stuff is for multi-activity use, or also * Android's Pause/Resume. @@ -505,7 +518,9 @@ public void LoadMODData(byte[] modData) { *

Check if the player thread is still valid. */ public boolean PlayerValid() { - // return whether this player is valid + /* + * Return whether this player is valid. + */ synchronized(sPVlock) { return mPlayerValid; } @@ -539,18 +554,22 @@ public void run() { */ short[] mBuffer = new short[BUFFERSIZE]; - if (mStart_paused) + if (mStart_paused) { mPlaying = false; - else + } + else { mPlaying = true; + } /* * Main play loop. */ - if (mMytrack != null) + if (mMytrack != null) { mMytrack.play(); - else + } + else { mRunning = false; + } while (mRunning) { while (mPlaying) { @@ -558,15 +577,14 @@ public void run() { * Pre-load another packet. */ synchronized(sRDlock) { - if (mRunning && mPlaying && mLoad_ok) try { + if (mRunning && mPlaying && mLoad_ok) { ModPlug_JGetSoundData(mBuffer, BUFFERSIZE); - if (ModPlug_CheckPatternChange()) + if (ModPlug_CheckPatternChange()) { pattern_change = true; + } CheckSongCompleted(); - } catch (Exception e) { - e.getCause().printStackTrace(); } } @@ -589,13 +607,15 @@ public void run() { if (pattern_change) { pattern_change = false; - if (mPlayerListener != null) + if (mPlayerListener != null) { mPlayerListener.onPlayerEvent(eventEnum.PATTERN_CHANGE); + } } if (songFinished && !songFinishedWas) { - if (mPlayerListener != null) + if (mPlayerListener != null) { mPlayerListener.onPlayerEvent(eventEnum.SONG_COMPLETED); + } } songFinishedWas = songFinished; } @@ -685,8 +705,9 @@ public void PausePlay() { * track, but seem to get an uninitialized audio track here * occasionally, generating an IllegalStateException. */ - if (mMytrack.getState() == AudioTrack.STATE_INITIALIZED) + if (mMytrack.getState() == AudioTrack.STATE_INITIALIZED) { mMytrack.stop(); + } mWaitFlag = true; synchronized(this) { @@ -778,8 +799,9 @@ public void StopThread() { * occasionally, generating an IllegalStateException. */ if (mMytrack != null) try { - if (mMytrack.getState() == AudioTrack.STATE_INITIALIZED) + if (mMytrack.getState() == AudioTrack.STATE_INITIALIZED) { mMytrack.stop(); + } } catch (NullPointerException npe) { npe.printStackTrace(); } @@ -802,7 +824,9 @@ public void StopThread() { public void CloseLIBMODPLUG() { ModPlug_JUnload(); ModPlug_CloseDown(); - // Release the audio track resources. + /* + * Release the audio track resources. + */ if (mMytrack != null) { mMytrack.release();