mirror of
https://github.com/samsonjs/media.git
synced 2026-04-22 14:05:55 +00:00
Remove usage of deprecated method from the Demo app
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=209390036
This commit is contained in:
parent
b58f6940eb
commit
f64ec43acd
4 changed files with 72 additions and 32 deletions
|
|
@ -60,7 +60,7 @@ import com.google.android.exoplayer2.source.ads.AdsMediaSource;
|
|||
import com.google.android.exoplayer2.source.dash.DashMediaSource;
|
||||
import com.google.android.exoplayer2.source.dash.manifest.DashManifestParser;
|
||||
import com.google.android.exoplayer2.source.hls.HlsMediaSource;
|
||||
import com.google.android.exoplayer2.source.hls.playlist.HlsPlaylistParser;
|
||||
import com.google.android.exoplayer2.source.hls.playlist.DefaultHlsPlaylistParserFactory;
|
||||
import com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource;
|
||||
import com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifestParser;
|
||||
import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection;
|
||||
|
|
@ -490,8 +490,8 @@ public class PlayerActivity extends Activity
|
|||
.createMediaSource(uri);
|
||||
case C.TYPE_HLS:
|
||||
return new HlsMediaSource.Factory(dataSourceFactory)
|
||||
.setPlaylistParser(
|
||||
new FilteringManifestParser<>(new HlsPlaylistParser(), getOfflineStreamKeys(uri)))
|
||||
.setPlaylistParserFactory(
|
||||
new DefaultHlsPlaylistParserFactory(getOfflineStreamKeys(uri)))
|
||||
.createMediaSource(uri);
|
||||
case C.TYPE_OTHER:
|
||||
return new ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(uri);
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispat
|
|||
import com.google.android.exoplayer2.source.SequenceableLoader;
|
||||
import com.google.android.exoplayer2.source.SinglePeriodTimeline;
|
||||
import com.google.android.exoplayer2.source.ads.AdsMediaSource;
|
||||
import com.google.android.exoplayer2.source.hls.playlist.DefaultHlsPlaylistParserFactory;
|
||||
import com.google.android.exoplayer2.source.hls.playlist.DefaultHlsPlaylistTracker;
|
||||
import com.google.android.exoplayer2.source.hls.playlist.HlsMediaPlaylist;
|
||||
import com.google.android.exoplayer2.source.hls.playlist.HlsPlaylist;
|
||||
|
|
@ -62,7 +63,7 @@ public final class HlsMediaSource extends BaseMediaSource
|
|||
private final HlsDataSourceFactory hlsDataSourceFactory;
|
||||
|
||||
private HlsExtractorFactory extractorFactory;
|
||||
private @Nullable ParsingLoadable.Parser<HlsPlaylist> playlistParser;
|
||||
private @Nullable HlsPlaylistParserFactory playlistParserFactory;
|
||||
private @Nullable HlsPlaylistTracker playlistTracker;
|
||||
private CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory;
|
||||
private LoadErrorHandlingPolicy loadErrorHandlingPolicy;
|
||||
|
|
@ -164,23 +165,19 @@ public final class HlsMediaSource extends BaseMediaSource
|
|||
}
|
||||
|
||||
/**
|
||||
* Sets the parser to parse HLS playlists. The default is an instance of {@link
|
||||
* HlsPlaylistParser}.
|
||||
* Sets the factory from which playlist parsers will be obtained. The default value is created
|
||||
* by calling {@link DefaultHlsPlaylistParserFactory#DefaultHlsPlaylistParserFactory()}.
|
||||
*
|
||||
* <p>Must not be called after calling {@link #setPlaylistTracker} on the same builder.
|
||||
*
|
||||
* @param playlistParser A {@link ParsingLoadable.Parser} for HLS playlists.
|
||||
* @param playlistParserFactory An {@link HlsPlaylistParserFactory}.
|
||||
* @return This factory, for convenience.
|
||||
* @throws IllegalStateException If one of the {@code create} methods has already been called.
|
||||
* @deprecated Use {@link #setPlaylistTracker(HlsPlaylistTracker)} instead. Using this method
|
||||
* prevents support for attributes that are carried over from the master playlist to the
|
||||
* media playlists.
|
||||
*/
|
||||
@Deprecated
|
||||
public Factory setPlaylistParser(ParsingLoadable.Parser<HlsPlaylist> playlistParser) {
|
||||
public Factory setPlaylistParserFactory(HlsPlaylistParserFactory playlistParserFactory) {
|
||||
Assertions.checkState(!isCreateCalled);
|
||||
Assertions.checkState(playlistTracker == null, "A playlist tracker has already been set.");
|
||||
this.playlistParser = Assertions.checkNotNull(playlistParser);
|
||||
this.playlistParserFactory = Assertions.checkNotNull(playlistParserFactory);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
@ -189,7 +186,7 @@ public final class HlsMediaSource extends BaseMediaSource
|
|||
* DefaultHlsPlaylistTracker}. Playlist trackers must not be shared by {@link HlsMediaSource}
|
||||
* instances.
|
||||
*
|
||||
* <p>Must not be called after calling {@link #setPlaylistParser} on the same builder.
|
||||
* <p>Must not be called after calling {@link #setPlaylistParserFactory} on the same builder.
|
||||
*
|
||||
* @param playlistTracker A tracker for HLS playlists.
|
||||
* @return This factory, for convenience.
|
||||
|
|
@ -197,7 +194,8 @@ public final class HlsMediaSource extends BaseMediaSource
|
|||
*/
|
||||
public Factory setPlaylistTracker(HlsPlaylistTracker playlistTracker) {
|
||||
Assertions.checkState(!isCreateCalled);
|
||||
Assertions.checkState(playlistParser == null, "A playlist parser has already been set.");
|
||||
Assertions.checkState(
|
||||
playlistParserFactory == null, "A playlist parser factory has already been set.");
|
||||
this.playlistTracker = Assertions.checkNotNull(playlistTracker);
|
||||
return this;
|
||||
}
|
||||
|
|
@ -244,14 +242,16 @@ public final class HlsMediaSource extends BaseMediaSource
|
|||
public HlsMediaSource createMediaSource(Uri playlistUri) {
|
||||
isCreateCalled = true;
|
||||
if (playlistTracker == null) {
|
||||
if (playlistParser == null) {
|
||||
if (playlistParserFactory == null) {
|
||||
playlistTracker =
|
||||
new DefaultHlsPlaylistTracker(
|
||||
hlsDataSourceFactory, loadErrorHandlingPolicy, HlsPlaylistParserFactory.DEFAULT);
|
||||
hlsDataSourceFactory,
|
||||
loadErrorHandlingPolicy,
|
||||
new DefaultHlsPlaylistParserFactory());
|
||||
} else {
|
||||
playlistTracker =
|
||||
new DefaultHlsPlaylistTracker(
|
||||
hlsDataSourceFactory, loadErrorHandlingPolicy, playlistParser);
|
||||
hlsDataSourceFactory, loadErrorHandlingPolicy, playlistParserFactory);
|
||||
}
|
||||
}
|
||||
return new HlsMediaSource(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.google.android.exoplayer2.source.hls.playlist;
|
||||
|
||||
import com.google.android.exoplayer2.offline.FilteringManifestParser;
|
||||
import com.google.android.exoplayer2.offline.StreamKey;
|
||||
import com.google.android.exoplayer2.upstream.ParsingLoadable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/** Default implementation for {@link HlsPlaylistParserFactory}. */
|
||||
public final class DefaultHlsPlaylistParserFactory implements HlsPlaylistParserFactory {
|
||||
|
||||
private final List<StreamKey> streamKeys;
|
||||
|
||||
/** Creates an instance that does not filter any parsing results. */
|
||||
public DefaultHlsPlaylistParserFactory() {
|
||||
this(Collections.emptyList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance that filters the parsing results using the given {@code streamKeys}.
|
||||
*
|
||||
* @param streamKeys See {@link
|
||||
* FilteringManifestParser#FilteringManifestParser(ParsingLoadable.Parser, List)}.
|
||||
*/
|
||||
public DefaultHlsPlaylistParserFactory(List<StreamKey> streamKeys) {
|
||||
this.streamKeys = streamKeys;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParsingLoadable.Parser<HlsPlaylist> createPlaylistParser() {
|
||||
return new FilteringManifestParser<>(new HlsPlaylistParser(), streamKeys);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParsingLoadable.Parser<HlsPlaylist> createPlaylistParser(
|
||||
HlsMasterPlaylist masterPlaylist) {
|
||||
return new FilteringManifestParser<>(new HlsPlaylistParser(masterPlaylist), streamKeys);
|
||||
}
|
||||
}
|
||||
|
|
@ -20,20 +20,6 @@ import com.google.android.exoplayer2.upstream.ParsingLoadable;
|
|||
/** Factory for {@link HlsPlaylist} parsers. */
|
||||
public interface HlsPlaylistParserFactory {
|
||||
|
||||
HlsPlaylistParserFactory DEFAULT =
|
||||
new HlsPlaylistParserFactory() {
|
||||
@Override
|
||||
public ParsingLoadable.Parser<HlsPlaylist> createPlaylistParser() {
|
||||
return new HlsPlaylistParser();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParsingLoadable.Parser<HlsPlaylist> createPlaylistParser(
|
||||
HlsMasterPlaylist masterPlaylist) {
|
||||
return new HlsPlaylistParser(masterPlaylist);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a stand-alone playlist parser. Playlists parsed by the returned parser do not inherit
|
||||
* any attributes from other playlists.
|
||||
|
|
|
|||
Loading…
Reference in a new issue