From 1b28ae0ff6d85bcb8198924d3562d049270cf139 Mon Sep 17 00:00:00 2001 From: AShiningRay Date: Thu, 14 Nov 2024 09:38:41 -0300 Subject: [PATCH] sprintpcs Player: Check if there's a valid playerListener to update Some jars might very well play media without assigning a playerListener, so account for that on all relevant methods to avoid any possible NullPointerExceptions. --- src/com/sprintpcs/media/Player.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/com/sprintpcs/media/Player.java b/src/com/sprintpcs/media/Player.java index a9cec150..68a31678 100644 --- a/src/com/sprintpcs/media/Player.java +++ b/src/com/sprintpcs/media/Player.java @@ -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()); } } @@ -86,7 +86,7 @@ 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) { @@ -94,7 +94,11 @@ public static void play(DualTone dTone, int repeat) // I assume the second argum } } - 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; } @@ -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()); } } } } \ No newline at end of file