如何在ExoPlayer 2.11.8版本中进行加载控制。

huangapple go评论86阅读模式
英文:

how to pass load control in exoplayer 2.11.8 version

问题

我正在使用exoplayer 2.11.8版本。在这个版本中,他们改变了许多方法。通过查阅他们的文档,我构建了Exoplayer

以下是代码部分:

    DataSource.Factory dataSourceFactory =
                    new DefaultHttpDataSourceFactory(Util.getUserAgent(this
                            , getApplicationInfo().loadLabel(getPackageManager()).toString()));
           
    LoadControl loadControl = new DefaultLoadControl.Builder()
                    .setAllocator(new DefaultAllocator(true, 16))
                    .setBufferDurationsMs(MIN_BUFFER_DURATION,
                            MAX_BUFFER_DURATION,
                            MIN_PLAYBACK_START_BUFFER,
                            MIN_PLAYBACK_RESUME_BUFFER)
                    .setTargetBufferBytes(-1)
                    .setPrioritizeTimeOverSizeThresholds(true).createDefaultLoadControl();
    // 创建一个指向流媒体 URI 的渐进式媒体源。
    MediaSource mediaSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
                    .createMediaSource(Uri.parse(audio_url));
    // 创建播放器实例。
    simpleExoPlayer =  new SimpleExoPlayer.Builder(this).build();

我想将load control传递给exoplayer。在旧版本中,load control是这样传递的,

    TrackSelector trackSelector = new DefaultTrackSelector();
    
    DefaultLoadControl loadControl = new DefaultLoadControl.Builder().setBufferDurationsMs(32*1024, 64*1024, 1024, 1024).createDefaultLoadControl();
    player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl);

在较新的版本中,他们改变了创建exoplayer实例的代码,如下所示:

    simpleExoPlayer =  new SimpleExoPlayer.Builder(this).build();

在这里,我不知道在哪里传递load control。我在他们的exoplayer文档中搜索过。但是没有关于传递load control的示例。请帮忙提供一些关于如何将load control传递给exoplayer的解决方案。

英文:

I am using exoplayer 2.11.8 version. In this version, they have changed the lot of methods. By Searching their docs, I build the Exoplayer.

Here's the Code:

DataSource.Factory dataSourceFactory =
                new DefaultHttpDataSourceFactory(Util.getUserAgent(this
                        , getApplicationInfo().loadLabel(getPackageManager()).toString()));
       
LoadControl loadControl = new DefaultLoadControl.Builder()
                .setAllocator(new DefaultAllocator(true, 16))
                .setBufferDurationsMs(MIN_BUFFER_DURATION,
                        MAX_BUFFER_DURATION,
                        MIN_PLAYBACK_START_BUFFER,
                        MIN_PLAYBACK_RESUME_BUFFER)
                .setTargetBufferBytes(-1)
                .setPrioritizeTimeOverSizeThresholds(true).createDefaultLoadControl();
// Create a progressive media source pointing to a stream uri.
MediaSource mediaSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
                .createMediaSource(Uri.parse(audio_url));
// Create a player instance.
simpleExoPlayer =  new SimpleExoPlayer.Builder(this).build();

I want to pass the load control to exoplayer. In older versions, Load control was passed like below,

TrackSelector trackSelector = new DefaultTrackSelector();

DefaultLoadControl loadControl = new DefaultLoadControl.Builder().setBufferDurationsMs(32*1024, 64*1024, 1024, 1024).createDefaultLoadControl();
player = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl);

In newer version, they have changed the code for creating exoplayer instance which is shown below

simpleExoPlayer =  new SimpleExoPlayer.Builder(this).build();

In here, i don't know where to pass the load control. I searched their exoplayer docs. But there is no example for passing load control.
Please help me and provide some solution to pass load control to exoplayer

答案1

得分: 6

请检查以下代码。

DefaultRenderersFactory renderersFactory;

DefaultLoadControl loadControl = new DefaultLoadControl.Builder().setBufferDurationsMs(25000, 50000, 1500, 2000).build();

@DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode = DefaultRenderersFactory.EXTENSION_RENDERER_MODE_PREFER;

renderersFactory = new DefaultRenderersFactory(this).setExtensionRendererMode(extensionRendererMode);

player = new SimpleExoPlayer.Builder(context, renderersFactory)
                                    .setTrackSelector(trackSelector)
                                    .setLoadControl(loadControl)
                                    .build();
英文:

Check following code.

DefaultRenderersFactory renderersFactory;
    
DefaultLoadControl loadControl = new DefaultLoadControl.Builder().setBufferDurationsMs(25000, 50000, 1500, 2000).build();
                        
@DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode = DefaultRenderersFactory.EXTENSION_RENDERER_MODE_PREFER;

renderersFactory = new DefaultRenderersFactory(this) .setExtensionRendererMode(extensionRendererMode);          

player = new SimpleExoPlayer.Builder(context, renderersFactory)
                                    .setTrackSelector(trackSelector)
                                    .setLoadControl(loadControl)
                                    .build();

huangapple
  • 本文由 发表于 2020年8月28日 18:58:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/63632470.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定