gpt4 book ai didi

java - 如何使用 ExtractorMediaSource.Factory 在 ExoPlayer 中设置自定义 header ?

转载 作者:行者123 更新时间:2023-11-29 23:49:57 25 4
gpt4 key购买 nike

我努力将 header 发送到服务器以获得观看视频的权限。我已经编写的重要代码如下所示:

Handler mainHandler = new Handler();
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory =
new AdaptiveTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector =
new DefaultTrackSelector(videoTrackSelectionFactory);

SimpleExoPlayer player =
ExoPlayerFactory.newSimpleInstance(getApplicationContext(), trackSelector);

PlayerView playerView = new PlayerView(this);
playerView.setLayoutParams(new FrameLayout.LayoutParams(contentWidth, contentWidth / 16 * 9));
playerView.setPlayer(player);
DefaultBandwidthMeter bandwidthmeter = new DefaultBandwidthMeter();
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(getApplicationContext(),
Util.getUserAgent(getApplicationContext(), "yourApplicationName"), bandwidthmeter);
MediaSource videoSource = new ExtractorMediaSource.Factory(dataSourceFactory)
.createMediaSource(streamUrl)
;
player.prepare(videoSource);

如果有人有答案,请帮我解决这个问题!

最佳答案

你可以点这个

HlsMediaSource hlsMediaSource = null;
// 1. Create a default TrackSelector
Handler mainHandler = new Handler();
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory = new
AdaptiveTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector = new
DefaultTrackSelector(videoTrackSelectionFactory);

// 2. Create a default LoadControl
LoadControl loadControl = new DefaultLoadControl();

// 3. Create the player
player = ExoPlayerFactory.newSimpleInstance(MainActivityMob.getContext(), trackSelector, loadControl);

// Measures bandwidth during playback. Can be null if not required.
DefaultBandwidthMeter defaultBandwidthMeter = new DefaultBandwidthMeter();
// Produces DataSource instances through which media data is loaded.
DefaultHttpDataSource.Factory MGSource = new DefaultHttpDataSourceFactory(Util.getUserAgent( MainActivityMob.getContext(), "myExoplayer"), null);
MGSource.getDefaultRequestProperties().set("YOUR KEY", "YOUR VALUE");

// This is the MediaSource representing the media to be played. new AdaptiveMediaSourceEventListener()
hlsMediaSource = new HlsMediaSource(Uri.parse(urlCH), MGSource, mainHandler, new AdaptiveMediaSourceEventListener() {


@Override
public void onLoadStarted(DataSpec dataSpec, int dataType, int trackType, Format trackFormat, int trackSelectionReason, Object trackSelectionData, long mediaStartTimeMs, long mediaEndTimeMs, long elapsedRealtimeMs) {

}

@Override
public void onLoadCompleted(DataSpec dataSpec, int dataType, int trackType, Format trackFormat, int trackSelectionReason, Object trackSelectionData, long mediaStartTimeMs, long mediaEndTimeMs, long elapsedRealtimeMs, long loadDurationMs, long bytesLoaded) {
progressBar.setVisibility(View.INVISIBLE);

}

@Override
public void onLoadCanceled(DataSpec dataSpec, int dataType, int trackType, Format trackFormat, int trackSelectionReason, Object trackSelectionData, long mediaStartTimeMs, long mediaEndTimeMs, long elapsedRealtimeMs, long loadDurationMs, long bytesLoaded) {

}

@Override
public void onLoadError(DataSpec dataSpec, int dataType, int trackType, Format trackFormat, int trackSelectionReason, Object trackSelectionData, long mediaStartTimeMs, long mediaEndTimeMs, long elapsedRealtimeMs, long loadDurationMs, long bytesLoaded, IOException error, boolean wasCanceled) {

}

@Override
public void onUpstreamDiscarded(int trackType, long mediaStartTimeMs, long mediaEndTimeMs) {

}

@Override
public void onDownstreamFormatChanged(int trackType, Format trackFormat, int trackSelectionReason, Object trackSelectionData, long mediaTimeMs) {

}

});

关于java - 如何使用 ExtractorMediaSource.Factory 在 ExoPlayer 中设置自定义 header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50970856/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com