Skip to content

Commit

Permalink
sprintpcs Player: Check if there's a valid playerListener to update
Browse files Browse the repository at this point in the history
Some jars might very well play media without assigning a playerListener,
so account for that on all relevant methods to avoid any possible
NullPointerExceptions.
  • Loading branch information
AShiningRay committed Nov 14, 2024
1 parent b0f431b commit 1b28ae0
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/com/sprintpcs/media/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static void play(Clip clip, int repeat)
try
{
player.start();
listener.playerUpdate(PlayerListener.STARTED, player.getMediaTime());
if(listener != null) { listener.playerUpdate(PlayerListener.STARTED, player.getMediaTime()); }
}
catch (Exception e) { Mobile.log(Mobile.LOG_WARNING, Player.class.getPackage().getName() + "." + Player.class.getSimpleName() + ": " + "failed to play Clip media: " + e.getMessage()); }
}
Expand Down Expand Up @@ -86,15 +86,19 @@ public static void play(DualTone dTone, int repeat) // I assume the second argum
try
{
player.start();
listener.playerUpdate(PlayerListener.STARTED, player.getMediaTime());
if(listener != null) { listener.playerUpdate(PlayerListener.STARTED, player.getMediaTime()); }
}
catch (Exception e)
{
Mobile.log(Mobile.LOG_WARNING, Player.class.getPackage().getName() + "." + Player.class.getSimpleName() + ": " + "failed to play DualTone media: " + e.getMessage());
}
}

public static void resume() { player.start(); }
public static void resume()
{
player.start();
if(listener != null) { listener.playerUpdate(PlayerListener.STARTED, player.getMediaTime()); }
}

public static void addPlayerListener(PlayerListener playerListener) { listener = playerListener; }

Expand All @@ -105,7 +109,7 @@ public static void stop()
if (player != null)
{
player.stop();
listener.playerUpdate(PlayerListener.STOPPED, player.getMediaTime());
if(listener != null) { listener.playerUpdate(PlayerListener.STOPPED, player.getMediaTime()); }
}
}
}

0 comments on commit 1b28ae0

Please sign in to comment.