Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
noamtamim committed Jul 29, 2020
1 parent 3b13a86 commit c7dd0bd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
1 change: 1 addition & 0 deletions tvplayer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ dependencies {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
40 changes: 24 additions & 16 deletions tvplayer/src/main/java/com/kaltura/tvplayer/KalturaPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
);
Expand All @@ -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)
);
Expand All @@ -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)
);
Expand Down Expand Up @@ -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));
}
Expand All @@ -819,7 +821,7 @@ public void loadMedia(@NonNull OVPMediaOptions mediaOptions, @NonNull final OnEn

prepareLoadMedia(mediaOptions);

runAfterRetrieve(
runAfterLoadConfig(
() -> loadMediaHelper(mediaOptions, listener),
() -> listener.onEntryLoadComplete(null, KalturaPlayerNotInitializedError)
);
Expand Down Expand Up @@ -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;
}

Expand All @@ -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));
Expand All @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion tvplayer/src/main/java/com/kaltura/tvplayer/KnownPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand Down

0 comments on commit c7dd0bd

Please sign in to comment.