Skip to content

Commit

Permalink
Extract method loadMediaHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
noamtamim committed May 7, 2020
1 parent 331d8b3 commit 3b13a86
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions tvplayer/src/main/java/com/kaltura/tvplayer/KalturaPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -745,23 +745,6 @@ public void loadPlaylist(@NonNull OTTPlaylistOptions playlistOptions, @NonNull f
);
}

private void loadPlaylistHelper(@NonNull ProviderPlaylistOptions playlistOptions, @NonNull OnPlaylistControllerListener controllerListener, PKPlaylistType playlistType) {
final PlaylistProvider provider = playlistOptions.buildPlaylistProvider(getServerUrl(), getPartnerId(), playlistOptions.ks);
provider.load(response -> playlistLoadCompleted(response, (playlist, error) -> {
if (error != null) {
return;
}
PlaylistController playlistController = new PKPlaylistController(KalturaPlayer.this, playlist, playlistType);
playlistController.setPlaylistOptions(playlistOptions);
controllerListener.onPlaylistControllerComplete(playlistController, null);
setPlaylistController(playlistController);
if (messageBus != null) {
messageBus.post(new PlaylistEvent.PlaylistStarted(playlist));
}
playlistController.playItem(playlistOptions.startIndex, autoPlay);
}));
}

public void loadPlaylist(@NonNull BasicPlaylistOptions playlistOptions, @NonNull final OnPlaylistControllerListener controllerListener) {

if (!isValidBasicPlayer())
Expand Down Expand Up @@ -800,6 +783,23 @@ public void loadPlaylist(@NonNull BasicPlaylistOptions playlistOptions, @NonNull
playlistController.playItem(playlistOptions.startIndex, autoPlay);
}

private void loadPlaylistHelper(@NonNull ProviderPlaylistOptions playlistOptions, @NonNull OnPlaylistControllerListener controllerListener, PKPlaylistType playlistType) {
final PlaylistProvider provider = playlistOptions.buildPlaylistProvider(getServerUrl(), getPartnerId(), playlistOptions.ks);
provider.load(response -> playlistLoadCompleted(response, (playlist, error) -> {
if (error != null) {
return;
}
PlaylistController playlistController = new PKPlaylistController(KalturaPlayer.this, playlist, playlistType);
playlistController.setPlaylistOptions(playlistOptions);
controllerListener.onPlaylistControllerComplete(playlistController, null);
setPlaylistController(playlistController);
if (messageBus != null) {
messageBus.post(new PlaylistEvent.PlaylistStarted(playlist));
}
playlistController.playItem(playlistOptions.startIndex, autoPlay);
}));
}

public void loadMedia(@NonNull OTTMediaOptions mediaOptions, @NonNull final OnEntryLoadListener listener) {

if (!isValidOTTPlayer())
Expand All @@ -808,10 +808,7 @@ public void loadMedia(@NonNull OTTMediaOptions mediaOptions, @NonNull final OnEn
prepareLoadMedia(mediaOptions);

runAfterRetrieve(
() -> {
final MediaEntryProvider provider = mediaOptions.buildMediaProvider(getServerUrl(), getPartnerId());
provider.load(response -> mediaLoadCompleted(response, listener));
},
() -> loadMediaHelper(mediaOptions, listener),
() -> listener.onEntryLoadComplete(null, KalturaPlayerNotInitializedError));
}

Expand All @@ -823,14 +820,16 @@ public void loadMedia(@NonNull OVPMediaOptions mediaOptions, @NonNull final OnEn
prepareLoadMedia(mediaOptions);

runAfterRetrieve(
() -> {
final MediaEntryProvider provider = mediaOptions.buildMediaProvider(getServerUrl(), getPartnerId());
provider.load(response -> mediaLoadCompleted(response, listener));
},
() -> loadMediaHelper(mediaOptions, listener),
() -> listener.onEntryLoadComplete(null, KalturaPlayerNotInitializedError)
);
}

private void loadMediaHelper(@NonNull MediaOptions mediaOptions, @NonNull OnEntryLoadListener listener) {
final MediaEntryProvider provider = mediaOptions.buildMediaProvider(getServerUrl(), getPartnerId());
provider.load(response -> mediaLoadCompleted(response, listener));
}

private boolean isValidOVPPlayer() {
if (Type.basic.equals(tvPlayerType)) {
return false;
Expand Down

0 comments on commit 3b13a86

Please sign in to comment.