Skip to content

Commit

Permalink
Rollback of 4ad4e3e
Browse files Browse the repository at this point in the history
*** Original commit ***

Rollback of 3b22db3

*** Original commit ***

add top-level playlist API to ExoPlayer

Public design doc:
https://docs.google.com/document/d/11h0S91KI5TB3NNZUtsCzg0S7r6nyTnF_tDZZAtmY93g

Issue: #6161

***

***

PiperOrigin-RevId: 275276158
  • Loading branch information
marcbaechinger authored and ojw28 committed Oct 18, 2019
1 parent 9ec2d2f commit 36f8bd7
Show file tree
Hide file tree
Showing 34 changed files with 4,324 additions and 783 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import com.google.android.exoplayer2.offline.DownloadHelper;
import com.google.android.exoplayer2.offline.DownloadRequest;
import com.google.android.exoplayer2.source.BehindLiveWindowException;
import com.google.android.exoplayer2.source.ConcatenatingMediaSource;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.MediaSourceFactory;
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
Expand Down Expand Up @@ -79,6 +78,8 @@
import java.net.CookieHandler;
import java.net.CookieManager;
import java.net.CookiePolicy;
import java.util.ArrayList;
import java.util.List;

/** An activity that plays media using {@link SimpleExoPlayer}. */
public class PlayerActivity extends AppCompatActivity
Expand Down Expand Up @@ -140,7 +141,7 @@ public class PlayerActivity extends AppCompatActivity

private DataSource.Factory dataSourceFactory;
private SimpleExoPlayer player;
private MediaSource mediaSource;
private List<MediaSource> mediaSources;
private DefaultTrackSelector trackSelector;
private DefaultTrackSelector.Parameters trackSelectorParameters;
private DebugTextViewHelper debugViewHelper;
Expand Down Expand Up @@ -342,12 +343,10 @@ public void onVisibilityChange(int visibility) {
private void initializePlayer() {
if (player == null) {
Intent intent = getIntent();

mediaSource = createTopLevelMediaSource(intent);
if (mediaSource == null) {
mediaSources = createTopLevelMediaSources(intent);
if (mediaSources.isEmpty()) {
return;
}

TrackSelection.Factory trackSelectionFactory;
String abrAlgorithm = intent.getStringExtra(ABR_ALGORITHM_EXTRA);
if (abrAlgorithm == null || ABR_ALGORITHM_DEFAULT.equals(abrAlgorithm)) {
Expand Down Expand Up @@ -388,12 +387,12 @@ private void initializePlayer() {
if (haveStartPosition) {
player.seekTo(startWindow, startPosition);
}
player.prepare(mediaSource, !haveStartPosition, false);
player.setMediaItems(mediaSources, /* resetPosition= */ !haveStartPosition);
player.prepare();
updateButtonVisibility();
}

@Nullable
private MediaSource createTopLevelMediaSource(Intent intent) {
private List<MediaSource> createTopLevelMediaSources(Intent intent) {
String action = intent.getAction();
boolean actionIsListView = ACTION_VIEW_LIST.equals(action);
if (!actionIsListView && !ACTION_VIEW.equals(action)) {
Expand Down Expand Up @@ -421,34 +420,30 @@ private MediaSource createTopLevelMediaSource(Intent intent) {
}
}

MediaSource[] mediaSources = new MediaSource[samples.length];
for (int i = 0; i < samples.length; i++) {
mediaSources[i] = createLeafMediaSource(samples[i]);
List<MediaSource> mediaSources = new ArrayList<>();
for (UriSample sample : samples) {
mediaSources.add(createLeafMediaSource(sample));
}
MediaSource mediaSource =
mediaSources.length == 1 ? mediaSources[0] : new ConcatenatingMediaSource(mediaSources);

if (seenAdsTagUri) {
if (seenAdsTagUri && mediaSources.size() == 1) {
Uri adTagUri = samples[0].adTagUri;
if (actionIsListView) {
showToast(R.string.unsupported_ads_in_concatenation);
if (!adTagUri.equals(loadedAdTagUri)) {
releaseAdsLoader();
loadedAdTagUri = adTagUri;
}
MediaSource adsMediaSource = createAdsMediaSource(mediaSources.get(0), adTagUri);
if (adsMediaSource != null) {
mediaSources.set(0, adsMediaSource);
} else {
if (!adTagUri.equals(loadedAdTagUri)) {
releaseAdsLoader();
loadedAdTagUri = adTagUri;
}
MediaSource adsMediaSource = createAdsMediaSource(mediaSource, adTagUri);
if (adsMediaSource != null) {
mediaSource = adsMediaSource;
} else {
showToast(R.string.ima_not_loaded);
}
showToast(R.string.ima_not_loaded);
}
} else if (seenAdsTagUri && mediaSources.size() > 1) {
showToast(R.string.unsupported_ads_in_concatenation);
releaseAdsLoader();
} else {
releaseAdsLoader();
}

return mediaSource;
return mediaSources;
}

private MediaSource createLeafMediaSource(UriSample parameters) {
Expand Down Expand Up @@ -535,7 +530,7 @@ private void releasePlayer() {
debugViewHelper = null;
player.release();
player = null;
mediaSource = null;
mediaSources = null;
trackSelector = null;
}
if (adsLoader != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ public final class CastPlayer extends BasePlayer {
private int pendingSeekCount;
private int pendingSeekWindowIndex;
private long pendingSeekPositionMs;
private boolean waitingForInitialTimeline;

/**
* @param castContext The context from which the cast session is obtained.
Expand Down Expand Up @@ -174,7 +173,6 @@ public PendingResult<MediaChannelResult> loadItems(
MediaQueueItem[] items, int startIndex, long positionMs, @RepeatMode int repeatMode) {
if (remoteMediaClient != null) {
positionMs = positionMs != C.TIME_UNSET ? positionMs : 0;
waitingForInitialTimeline = true;
return remoteMediaClient.queueLoad(items, startIndex, getCastRepeatMode(repeatMode),
positionMs, null);
}
Expand Down Expand Up @@ -619,15 +617,13 @@ private void updateRepeatModeAndNotifyIfChanged() {

private void updateTimelineAndNotifyIfChanged() {
if (updateTimeline()) {
@Player.TimelineChangeReason
int reason =
waitingForInitialTimeline
? Player.TIMELINE_CHANGE_REASON_PREPARED
: Player.TIMELINE_CHANGE_REASON_DYNAMIC;
waitingForInitialTimeline = false;
// TODO: Differentiate TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED and
// TIMELINE_CHANGE_REASON_SOURCE_UPDATE [see internal: b/65152553].
notificationsBatch.add(
new ListenerNotificationTask(
listener -> listener.onTimelineChanged(currentTimeline, reason)));
listener ->
listener.onTimelineChanged(
currentTimeline, Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
private final Timeline.Period period;
private final Timeline timeline;

private boolean prepared;
@Player.State private int state;
private boolean playWhenReady;
private long position;
Expand All @@ -47,13 +46,17 @@ public FakePlayer() {
timeline = Timeline.EMPTY;
}

/** Sets the timeline on this fake player, which notifies listeners with the changed timeline. */
public void updateTimeline(Timeline timeline) {
/**
* Sets the timeline on this fake player, which notifies listeners with the changed timeline and
* the given timeline change reason.
*
* @param timeline The new timeline.
* @param timelineChangeReason The reason for the timeline change.
*/
public void updateTimeline(Timeline timeline, @TimelineChangeReason int timelineChangeReason) {
for (Player.EventListener listener : listeners) {
listener.onTimelineChanged(
timeline, prepared ? TIMELINE_CHANGE_REASON_DYNAMIC : TIMELINE_CHANGE_REASON_PREPARED);
listener.onTimelineChanged(timeline, timelineChangeReason);
}
prepared = true;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,9 @@ public TestAdsLoaderListener(
public void onAdPlaybackState(AdPlaybackState adPlaybackState) {
adPlaybackState = adPlaybackState.withAdDurationsUs(adDurationsUs);
this.adPlaybackState = adPlaybackState;
fakeExoPlayer.updateTimeline(new SinglePeriodAdTimeline(contentTimeline, adPlaybackState));
fakeExoPlayer.updateTimeline(
new SinglePeriodAdTimeline(contentTimeline, adPlaybackState),
Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2.source;
package com.google.android.exoplayer2;

import android.util.Pair;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.source.ShuffleOrder;
import com.google.android.exoplayer2.util.Assertions;

/** Abstract base class for the concatenation of one or more {@link Timeline}s. */
/* package */ abstract class AbstractConcatenatedTimeline extends Timeline {
public abstract class AbstractConcatenatedTimeline extends Timeline {

private final int childCount;
private final ShuffleOrder shuffleOrder;
Expand Down
Loading

0 comments on commit 36f8bd7

Please sign in to comment.