diff --git a/tvplayer/build.gradle b/tvplayer/build.gradle index d8ab978b..bec93533 100644 --- a/tvplayer/build.gradle +++ b/tvplayer/build.gradle @@ -57,4 +57,5 @@ dependencies { repositories { google() jcenter() + maven { url 'https://jitpack.io' } } diff --git a/tvplayer/src/main/java/com/kaltura/tvplayer/KalturaPlayer.java b/tvplayer/src/main/java/com/kaltura/tvplayer/KalturaPlayer.java index 5ff3a168..86b7cb96 100644 --- a/tvplayer/src/main/java/com/kaltura/tvplayer/KalturaPlayer.java +++ b/tvplayer/src/main/java/com/kaltura/tvplayer/KalturaPlayer.java @@ -2,6 +2,7 @@ import android.content.Context; import android.net.Uri; +import android.os.Build; import android.os.Handler; import android.os.HandlerThread; import android.os.Looper; @@ -703,7 +704,7 @@ public void loadPlaylistById(@NonNull OVPPlaylistIdOptions playlistOptions, @Non if (!isValidOVPPlayer()) return; - runAfterRetrieve( + runAfterLoadConfig( () -> loadPlaylistHelper(playlistOptions, controllerListener, PKPlaylistType.OVP_ID), () -> controllerListener.onPlaylistControllerComplete(null, KalturaPlaylistInitializedError) ); @@ -721,7 +722,7 @@ public void loadPlaylist(@NonNull OVPPlaylistOptions playlistOptions, @NonNull f return; } - runAfterRetrieve( + runAfterLoadConfig( () -> loadPlaylistHelper(playlistOptions, controllerListener, PKPlaylistType.OVP_LIST), () -> controllerListener.onPlaylistControllerComplete(null, KalturaPlaylistInitializedError) ); @@ -739,7 +740,7 @@ public void loadPlaylist(@NonNull OTTPlaylistOptions playlistOptions, @NonNull f return; } - runAfterRetrieve( + runAfterLoadConfig( () -> loadPlaylistHelper(playlistOptions, controllerListener, PKPlaylistType.OTT_LIST), () -> controllerListener.onPlaylistControllerComplete(null, KalturaPlaylistInitializedError) ); @@ -807,7 +808,8 @@ public void loadMedia(@NonNull OTTMediaOptions mediaOptions, @NonNull final OnEn prepareLoadMedia(mediaOptions); - runAfterRetrieve( + runAfterLoadConfig( + "OTT loadMedia", () -> loadMediaHelper(mediaOptions, listener), () -> listener.onEntryLoadComplete(null, KalturaPlayerNotInitializedError)); } @@ -819,7 +821,7 @@ public void loadMedia(@NonNull OVPMediaOptions mediaOptions, @NonNull final OnEn prepareLoadMedia(mediaOptions); - runAfterRetrieve( + runAfterLoadConfig( () -> loadMediaHelper(mediaOptions, listener), () -> listener.onEntryLoadComplete(null, KalturaPlayerNotInitializedError) ); @@ -933,22 +935,22 @@ private PhoenixAnalyticsConfig getPhoenixAnalyticsConfig() { return new PhoenixAnalyticsConfig(getPartnerId(), getServerUrl(), getKS(), Consts.DEFAULT_ANALYTICS_TIMER_INTERVAL_HIGH_SEC); } - private boolean runIfReady(Runnable onReady) { + private boolean runIfReady(String logActionName, Runnable onReady) { if (playerConfigRetrieved || (initOptions != null && initOptions.tvPlayerParams != null)) { - log.d("READY!"); if (playerConfigRetrieved) { initOptions.setTVPlayerParams(PlayerConfigManager.retrieve(getTvPlayerType(), initOptions.partnerId)); } populatePartnersValues(); onReady.run(); + log.d(logActionName + ": success after player config was ready"); return true; } return false; } - private void runAfterRetrieve(Runnable onReady, Runnable onTimeout) { + private void runAfterLoadConfig(String logActionName, Runnable onReady, Runnable onTimeout) { - if (runIfReady(onReady)) { + if (runIfReady(logActionName, onReady)) { return; } @@ -958,10 +960,8 @@ private void runAfterRetrieve(Runnable onReady, Runnable onTimeout) { @Override public void run() { - if (runIfReady(onReady)) { - retrieveWaitThread.quit(); - retrieveWaitThread = null; - retrieveWaitHandler = null; + if (runIfReady(logActionName, onReady)) { + quitConfigWaitThread(); } else { log.d("Not ready yet " + (SystemClock.elapsedRealtime() - startTime)); @@ -972,15 +972,23 @@ public void run() { } else { log.e("Timed out waiting for retrieve"); onTimeout.run(); - retrieveWaitThread.quit(); - retrieveWaitThread = null; - retrieveWaitHandler = null; + quitConfigWaitThread(); } } } }); } + private void quitConfigWaitThread() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { + retrieveWaitThread.quitSafely(); + } else { + retrieveWaitThread.quit(); // Less safe, but we have a very small percentage of + } + retrieveWaitThread = null; + retrieveWaitHandler = null; + } + public interface OnEntryLoadListener { void onEntryLoadComplete(PKMediaEntry entry, ErrorElement error); } diff --git a/tvplayer/src/main/java/com/kaltura/tvplayer/KnownPlugin.java b/tvplayer/src/main/java/com/kaltura/tvplayer/KnownPlugin.java index 0feb3b0b..52c0f55c 100644 --- a/tvplayer/src/main/java/com/kaltura/tvplayer/KnownPlugin.java +++ b/tvplayer/src/main/java/com/kaltura/tvplayer/KnownPlugin.java @@ -32,6 +32,8 @@ enum KnownPlugin { public final String className; public final PKPlugin.Factory factory; + private boolean registered; + KnownPlugin(String className, PKPlugin.Factory factory) { this.className = className; this.factory = factory; @@ -41,7 +43,7 @@ enum KnownPlugin { this(className, null); } - protected static void registerPluginByName(Context context, String pluginClassName) { + void registerPluginByName(Context context, String pluginClassName) { try { Class pluginClass = Class.forName(pluginClassName); final Field factoryField = pluginClass.getField("factory");