本文整理匯總了Java中com.google.android.exoplayer2.source.MediaSource類的典型用法代碼示例。如果您正苦於以下問題:Java MediaSource類的具體用法?Java MediaSource怎麽用?Java MediaSource使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MediaSource類屬於com.google.android.exoplayer2.source包,在下文中一共展示了MediaSource類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: buildMediaSource
import com.google.android.exoplayer2.source.MediaSource; //導入依賴的package包/類
private MediaSource buildMediaSource(Uri uri, String overrideExtension) {
int type = Util.inferContentType(!TextUtils.isEmpty(overrideExtension) ? "." + overrideExtension
: uri.getLastPathSegment());
switch (type) {
case C.TYPE_SS:
return new SsMediaSource(uri, buildDataSourceFactory(false),
new DefaultSsChunkSource.Factory(mediaDataSourceFactory), mainHandler, null);
case C.TYPE_DASH:
return new DashMediaSource(uri, buildDataSourceFactory(false),
new DefaultDashChunkSource.Factory(mediaDataSourceFactory), mainHandler, null);
case C.TYPE_HLS:
return new HlsMediaSource(uri, mediaDataSourceFactory, mainHandler, null);
case C.TYPE_OTHER:
return new ExtractorMediaSource(uri, mediaDataSourceFactory, new DefaultExtractorsFactory(),
mainHandler, null);
default: {
throw new IllegalStateException("Unsupported type: " + type);
}
}
}
示例2: onCreate
import com.google.android.exoplayer2.source.MediaSource; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_coutom3);
ImaSdkSettings sdkSettings= ImaSdkFactory.getInstance().createImaSdkSettings();
sdkSettings.setLanguage("zh");
adsLoader = new ImaAdsLoader( this, Uri.parse(getString(R.string.ad_tag_url)),sdkSettings);
mediaSourceBuilder=new MediaSourceBuilder(this,new DataSource(this.getApplication()));
videoPlayerView = (VideoPlayerView) findViewById(R.id.exo_play_context_id);
exoPlayerManager = new GestureVideoPlayer(this,mediaSourceBuilder,videoPlayerView );
exoPlayerManager.setTitle("視頻標題");
exoPlayerManager.setExoPlayWatermarkImg(R.mipmap.watermark_big);
MediaSource contentMediaSource =mediaSourceBuilder.initMediaSource( Uri.parse(getString(R.string.uri_test_6)));
// Compose the content media source into a new AdsMediaSource with both ads and content.
MediaSource mediaSourceWithAds = new AdsMediaSource(contentMediaSource, mediaSourceBuilder.getDataSource(),
adsLoader, videoPlayerView.getPlayerView().getOverlayFrameLayout());
mediaSourceBuilder.setMediaSource(mediaSourceWithAds);
Glide.with(this)
.load(getString(R.string.uri_test_image))
.fitCenter()
.placeholder(R.mipmap.test)
.into(videoPlayerView.getPreviewImage());
}
示例3: preparePlayer
import com.google.android.exoplayer2.source.MediaSource; //導入依賴的package包/類
public void preparePlayer() {
MediaSource videoSource = new ExtractorMediaSource(syncplayuri,
dataSourceFactory, extractorsFactory, null, null);
mMediaPlayer.prepare(videoSource);
mSyncPlayClient.setPlayerState(new syncPlayClientInterface.playerDetails() {
@Override
public long getPosition() {
return mMediaPlayer.getCurrentPosition() / 1000L;
}
@Override
public Boolean isPaused() {
return !mMediaPlayer.getPlayWhenReady();
}
});
}
示例4: buildMediaSource
import com.google.android.exoplayer2.source.MediaSource; //導入依賴的package包/類
private MediaSource buildMediaSource(Uri uri, String overrideExtension) {
int type = Util.inferContentType(!TextUtils.isEmpty(overrideExtension) ? "." + overrideExtension
: uri.getLastPathSegment());
switch (type) {
case C.TYPE_SS:
return new SsMediaSource(uri, buildDataSourceFactory(false),
new DefaultSsChunkSource.Factory(mediaDataSourceFactory), mainHandler, eventLogger);
case C.TYPE_DASH:
return new DashMediaSource(uri, buildDataSourceFactory(false),
new DefaultDashChunkSource.Factory(mediaDataSourceFactory), mainHandler, eventLogger);
case C.TYPE_HLS:
return new HlsMediaSource(uri, mediaDataSourceFactory, mainHandler, eventLogger);
case C.TYPE_OTHER:
return new ExtractorMediaSource(uri, mediaDataSourceFactory, new DefaultExtractorsFactory(),
mainHandler, eventLogger);
default: {
throw new IllegalStateException("Unsupported type: " + type);
}
}
}
示例5: buildMediaSource
import com.google.android.exoplayer2.source.MediaSource; //導入依賴的package包/類
private MediaSource buildMediaSource(Context context, Uri uri) {
int type = getUrlType(uri.toString());
switch (type) {
case C.TYPE_SS:
return new SsMediaSource(uri, new DefaultDataSourceFactory(context, null,
new DefaultHttpDataSourceFactory(USER_AGENT, null)),
new DefaultSsChunkSource.Factory(new DefaultDataSourceFactory(context, BANDWIDTH_METER,
new DefaultHttpDataSourceFactory(USER_AGENT, BANDWIDTH_METER))), mainThreadHandler, null);
case C.TYPE_DASH:
return new DashMediaSource(uri, new DefaultDataSourceFactory(context, null,
new DefaultHttpDataSourceFactory(USER_AGENT, null)),
new DefaultDashChunkSource.Factory(new DefaultDataSourceFactory(context, BANDWIDTH_METER,
new DefaultHttpDataSourceFactory(USER_AGENT, BANDWIDTH_METER))), mainThreadHandler, null);
case C.TYPE_HLS:
return new HlsMediaSource(uri, new DefaultDataSourceFactory(context, BANDWIDTH_METER,
new DefaultHttpDataSourceFactory(USER_AGENT, BANDWIDTH_METER)), mainThreadHandler, null);
case C.TYPE_OTHER:
return new ExtractorMediaSource(uri, new DefaultDataSourceFactory(context, BANDWIDTH_METER,
new DefaultHttpDataSourceFactory(USER_AGENT, BANDWIDTH_METER)), new DefaultExtractorsFactory(),
mainThreadHandler, null);
default: {
throw new IllegalStateException("Unsupported type: " + type);
}
}
}
示例6: prepareExoPlayerForUri
import com.google.android.exoplayer2.source.MediaSource; //導入依賴的package包/類
public SimpleExoPlayer prepareExoPlayerForUri(
int playerKey,
@NonNull Context context,
@NonNull Uri uri,
@NonNull SimpleExoPlayerView simpleExoPlayerView,
int currentWindow,
boolean playWhenReady,
long playbackPosition) {
SimpleExoPlayer simpleExoPlayer = playersInUse.get(playerKey);
if (simpleExoPlayer == null) {
simpleExoPlayer = setUpMediaPlayer(context);
simpleExoPlayerView.setPlayer(simpleExoPlayer);
simpleExoPlayer.setPlayWhenReady(playWhenReady);
simpleExoPlayer.seekTo(currentWindow, playbackPosition);
MediaSource mediaSource = setUpMediaSource(context, uri);
simpleExoPlayer.prepare(mediaSource, true, false);
playersInUse.put(playerKey, simpleExoPlayer);
} else {
simpleExoPlayer.seekTo(currentWindow, playbackPosition);
simpleExoPlayer.setPlayWhenReady(playWhenReady);
}
return simpleExoPlayer;
}
示例7: buildMediaSource
import com.google.android.exoplayer2.source.MediaSource; //導入依賴的package包/類
private MediaSource buildMediaSource(Uri uri, String overrideExtension) {
DataSource.Factory mediaDataSourceFactory = buildDataSourceFactory(true);
int type = TextUtils.isEmpty(overrideExtension) ? Util.inferContentType(uri)
: Util.inferContentType("." + overrideExtension);
switch (type) {
case C.TYPE_SS:
return new SsMediaSource(uri, buildDataSourceFactory(false),
new DefaultSsChunkSource.Factory(mediaDataSourceFactory), mainHandler, null);
case C.TYPE_DASH:
return new DashMediaSource(uri, buildDataSourceFactory(false),
new DefaultDashChunkSource.Factory(mediaDataSourceFactory), mainHandler, null);
case C.TYPE_HLS:
return new HlsMediaSource(uri, mediaDataSourceFactory, mainHandler, null);
case C.TYPE_OTHER:
return new ExtractorMediaSource(uri, mediaDataSourceFactory, new DefaultExtractorsFactory(),
mainHandler, null);
default: {
throw new IllegalStateException("Unsupported type: " + type);
}
}
}
示例8: initializePlayer
import com.google.android.exoplayer2.source.MediaSource; //導入依賴的package包/類
private void initializePlayer() {
if (player == null) {
// a factory to create an AdaptiveVideoTrackSelection
TrackSelection.Factory adaptiveTrackSelectionFactory =
new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
// using a DefaultTrackSelector with an adaptive video selection factory
player = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(this),
new DefaultTrackSelector(adaptiveTrackSelectionFactory), new DefaultLoadControl());
player.addListener(componentListener);
player.addVideoDebugListener(componentListener);
player.addAudioDebugListener(componentListener);
playerView.setPlayer(player);
player.setPlayWhenReady(playWhenReady);
player.seekTo(currentWindow, playbackPosition);
}
MediaSource mediaSource = buildMediaSource(Uri.parse(getString(R.string.media_url_dash)));
player.prepare(mediaSource, true, false);
}
示例9: initializePlayer
import com.google.android.exoplayer2.source.MediaSource; //導入依賴的package包/類
private void initializePlayer(Uri videoUri){
if (mExoPlayer == null){
TrackSelector trackSelector = new DefaultTrackSelector();
LoadControl loadControl = new DefaultLoadControl();
mExoPlayer = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, loadControl);
mExoPlayer.addListener(this);
mExoPlayer.seekTo(currentPosition);
mPlayerView.setPlayer(mExoPlayer);
String userAgent = Util.getUserAgent(getContext(), "Tasty");
MediaSource mediaSource = new ExtractorMediaSource(videoUri, new DefaultDataSourceFactory(
getContext(), userAgent), new DefaultExtractorsFactory(), null, null);
mExoPlayer.prepare(mediaSource);
if (playWhenReady) mExoPlayer.setPlayWhenReady(true);
else mExoPlayer.setPlayWhenReady(false);
}
}
示例10: getMediaSource
import com.google.android.exoplayer2.source.MediaSource; //導入依賴的package包/類
public MediaSource getMediaSource(boolean preview) {
switch (streamType) {
case C.TYPE_SS:
return new SsMediaSource(uri, new DefaultDataSourceFactory(context, null,
getHttpDataSourceFactory(preview)),
new DefaultSsChunkSource.Factory(getDataSourceFactory(preview)),
mainHandler, null);
case C.TYPE_DASH:
return new DashMediaSource(uri,
new DefaultDataSourceFactory(context, null,
getHttpDataSourceFactory(preview)),
new DefaultDashChunkSource.Factory(getDataSourceFactory(preview)),
mainHandler, null);
case C.TYPE_HLS:
return new HlsMediaSource(uri, getDataSourceFactory(preview), mainHandler, null);
case C.TYPE_OTHER:
return new ExtractorMediaSource(uri, getDataSourceFactory(preview),
new DefaultExtractorsFactory(), mainHandler, null);
default: {
throw new IllegalStateException("Unsupported type: " + streamType);
}
}
}
示例11: prepareAsync
import com.google.android.exoplayer2.source.MediaSource; //導入依賴的package包/類
@Override
public void prepareAsync() throws IllegalStateException {
TrackSelection.Factory videoTrackSelectionFactory =
new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
DefaultTrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
mInternalMediaPlayer = InternalExoPlayer.newInstance(mAppContext, trackSelector);
mEventListener = new ExoEventListener();
mInternalMediaPlayer.addListener(mEventListener);
mVideoListener = new ExoVideoListener();
mInternalMediaPlayer.addVideoListener(mVideoListener);
MediaSource mediaSource = buildMediaSource(mUri, mHeaders);
mInternalMediaPlayer.setVideoSurface(mSurface);
mInternalMediaPlayer.prepare(mediaSource);
notifyOnPrepared();
}
示例12: startPlayer
import com.google.android.exoplayer2.source.MediaSource; //導入依賴的package包/類
@Override
public void startPlayer() {
if(exoPlayer==null){
exoPlayer =
ExoPlayerFactory.newSimpleInstance(
context, new DefaultTrackSelector(), new DefaultLoadControl());
exoPlayer.addListener(this);
}
exoPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(
context, Util.getUserAgent(context, "uamp"), null);
ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
MediaSource mediaSource = new ExtractorMediaSource(
Uri.parse(currentUrl), dataSourceFactory, extractorsFactory, null, null);
exoPlayer.prepare(mediaSource);
configPlayer();
}
示例13: setExoViewSource
import com.google.android.exoplayer2.source.MediaSource; //導入依賴的package包/類
private void setExoViewSource(@NonNull MasterSecret masterSecret, @NonNull VideoSlide videoSource)
throws IOException
{
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
LoadControl loadControl = new DefaultLoadControl();
exoPlayer = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, loadControl);
exoView.setPlayer(exoPlayer);
DefaultDataSourceFactory defaultDataSourceFactory = new DefaultDataSourceFactory(getContext(), "GenericUserAgent", null);
AttachmentDataSourceFactory attachmentDataSourceFactory = new AttachmentDataSourceFactory(getContext(), masterSecret, defaultDataSourceFactory, null);
ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory();
MediaSource mediaSource = new ExtractorMediaSource(videoSource.getUri(), attachmentDataSourceFactory, extractorsFactory, null, null);
exoPlayer.prepare(mediaSource);
exoPlayer.setPlayWhenReady(true);
}
示例14: MediaPeriodHolder
import com.google.android.exoplayer2.source.MediaSource; //導入依賴的package包/類
public MediaPeriodHolder(Renderer[] renderers, RendererCapabilities[] rendererCapabilities,
long rendererPositionOffsetUs, TrackSelector trackSelector, LoadControl loadControl,
MediaSource mediaSource, Object periodUid, int periodIndex, boolean isLastPeriod,
long startPositionUs) {
this.renderers = renderers;
this.rendererCapabilities = rendererCapabilities;
this.rendererPositionOffsetUs = rendererPositionOffsetUs;
this.trackSelector = trackSelector;
this.loadControl = loadControl;
this.mediaSource = mediaSource;
this.uid = Assertions.checkNotNull(periodUid);
this.index = periodIndex;
this.isLast = isLastPeriod;
this.startPositionUs = startPositionUs;
sampleStreams = new SampleStream[renderers.length];
mayRetainStreamFlags = new boolean[renderers.length];
mediaPeriod = mediaSource.createPeriod(periodIndex, loadControl.getAllocator(),
startPositionUs);
}
示例15: setupExoPlayer
import com.google.android.exoplayer2.source.MediaSource; //導入依賴的package包/類
private void setupExoPlayer() {
TrackSelection.Factory adaptiveTrackSelectionFactory =
new AdaptiveTrackSelection.Factory(new DefaultBandwidthMeter());
exoPlayer = ExoPlayerFactory.newSimpleInstance(
new DefaultRenderersFactory(this),
new DefaultTrackSelector(adaptiveTrackSelectionFactory),
new DefaultLoadControl());
pvVideoPreview.setPlayer(exoPlayer);
exoPlayer.setPlayWhenReady(true);
Uri uri = Uri.parse("asset:///sample_video.mp4");
MediaSource mediaSource = createMediaSource(this, uri);
LoopingMediaSource loopingMediaSource = new LoopingMediaSource(mediaSource);
exoPlayer.prepare(loopingMediaSource, true, false);
}