如何在Exo-player v2.x中添加自适应音轨选择器? [英] How to add Adaptive Track Selector in Exo-player v2.x?

查看:444
本文介绍了如何在Exo-player v2.x中添加自适应音轨选择器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的应用程序中设置Exo Player,并且已经在播放器中实现了DASH自适应流,并希望添加该功能来播放用户选择的特定质量的曲目.

I'm setting up Exo Player in my app and I have implemented DASH adaptive streaming in my player, and want to add the functionality to play the track of specific quality selected by the user.

我的Exo播放器版本是2.9.3,我尝试通过遵循以下 Stackoverflow Post 来实现a>,中型帖子,但有点令人困惑代码的某些部分已弃用,说的是我是初学者.

My Exo player version is 2.9.3, I tried implementing by following these Stackoverflow Post,Medium Post, but it's bit confusing and some part of the code is deprecated, and saying the truth is that I am a beginner.

这是我初始化播放器的代码:-

Here's my code for initializing the player:-

private void initializePlayer() {
     if (player == null) {
        bandwidthMeter = new DefaultBandwidthMeter();
        TrackSelection.Factory factory = new PlayerTrackSelector(bandwidthMeter);
        trackSelector = new DefaultTrackSelector(factory);
        player = ExoPlayerFactory.newSimpleInstance(this, trackSelector);
        player.addVideoListener(this);
        playerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_ZOOM);
        player.setVideoScalingMode(C.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
        player.addListener(this);
        playerView.setPlayer(player);
    }
    MediaSource mediaSource = buildMediaSource(Uri.parse("http://192.168.43.238:3000/storage/video-dash/9e351142a4eb1664643bf93ba13959e8.mpd"));
    player.prepare(mediaSource, true, false);
    player.setPlayWhenReady(playWhenReady);
    player.seekTo(currentWindow, playbackPosition);
}

TrackSelector类:-

public class PlayerTrackSelector implements TrackSelection.Factory {
    private BandwidthMeter bandwidthMeter;

  public PlayerTrackSelector(BandwidthMeter bandwidthMeter) {
    this.bandwidthMeter = bandwidthMeter;
  }

@Override
public TrackSelection createTrackSelection(TrackGroup group, BandwidthMeter bandwidthMeter, int... tracks) {

    return new AdaptiveTrackSelection(group,tracks,bandwidthMeter,
            AdaptiveTrackSelection.DEFAULT_MIN_DURATION_FOR_QUALITY_INCREASE_MS,
            AdaptiveTrackSelection.DEFAULT_MAX_DURATION_FOR_QUALITY_DECREASE_MS,
            AdaptiveTrackSelection.DEFAULT_MIN_DURATION_TO_RETAIN_AFTER_DISCARD_MS,
            AdaptiveTrackSelection.DEFAULT_BANDWIDTH_FRACTION,
            AdaptiveTrackSelection.DEFAULT_BUFFERED_FRACTION_TO_LIVE_EDGE_FOR_QUALITY_INCREASE,
            AdaptiveTrackSelection.DEFAULT_MIN_TIME_BETWEEN_BUFFER_REEVALUTATION_MS,
            Clock.DEFAULT);
  }
}

我希望获得可用质量类型的列表,并让用户选择其中一种,然后使用所选类型播放其余内容,这个问题可能很笼统,但请给我一些指导.

I expect to get a list of available quality types and let the user select one of them and play the rest of the content with the selected type, this question is maybe broad but please guide me a little.

推荐答案

尝试以下代码.需要显示列表时,请调用以下代码. rendererIndex->​​您可以手动尝试. TRACK_TYPE_AUDIO = 1,TRACK_TYPE_VIDEO =2.

Try following code. Call following code when you need to show list. rendererIndex -> You can try manually. TRACK_TYPE_AUDIO = 1, TRACK_TYPE_VIDEO = 2.

已更新:

MappingTrackSelector.MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo();
                    if (mappedTrackInfo != null) {
                        int rendererIndex = 2;
                        int rendererType = mappedTrackInfo.getRendererType(rendererIndex);
                        boolean allowAdaptiveSelections =
                                rendererType == C.TRACK_TYPE_VIDEO
                                        || (rendererType == C.TRACK_TYPE_AUDIO
                                        && mappedTrackInfo.getTypeSupport(C.TRACK_TYPE_VIDEO)
                                        == MappingTrackSelector.MappedTrackInfo.RENDERER_SUPPORT_NO_TRACKS);
                        Pair<AlertDialog, TrackSelectionView> dialogPair =
                                TrackSelectionView.getDialog(xxxxxxxxxxxxxx.this, "Track Selector", trackSelector, rendererIndex);
                        dialogPair.second.setShowDisableOption(true);
                        dialogPair.second.setAllowAdaptiveSelections(allowAdaptiveSelections);
                        dialogPair.first.show();
                    }

这篇关于如何在Exo-player v2.x中添加自适应音轨选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆