mp4视频的Exoplayer Video Quality选项 [英] Exoplayer Video Quality options for an mp4 video

查看:373
本文介绍了mp4视频的Exoplayer Video Quality选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Exoplayer播放HLS视频轨道,并且以下代码可以正常工作以获取可能的不同视频质量,并将其显示为选项,以供用户从多种分辨率中进行选择.

I used Exoplayer to play an HLS video track and following code works fine to fetch the different possible video qualities and to show them as options for the user to select from multiple resolutions.

for (int i = 0; i < player.getTrackCount(0); i++) {
            MediaFormat format = player.getTrackFormat(0, i);
            if (MimeTypes.isVideo(format.mimeType)) {
                if (format.adaptive) {
                    menu.add(1, (i + 1), (i + 1), "Auto");
                } else {
                    menu.add(1, (i + 1), (i + 1), format.width + "p");
                }
            }
        }

现在,我对mp4视频轨道使用相同的代码,但没有提供可供选择的选项.默认情况下,仅选择一种格式,不能再选择多种分辨率.

Now i use the same code for an mp4 video track and it does not give me an options to select from. By default only a single format gets selected and multiple resolutions cant be selected anymore.

有什么帮助我可以解决这个问题吗?

Any help how i can resolve this issue?

推荐答案

我希望

I hope this helps you.

如果这不是答案,请忽略此答案.

if this is not the answer,please ignore this answer.

我建议检查ExoPlayer的官方演示.

I will suggest to check the official demo of ExoPlayer.

您要研究的核心点是围绕音轨选择(通过TrackSelector)和TrackSelectionHelper.我将在下面包含重要的代码示例,希望这些示例足以使您继续前进.但是最终,只要在演示应用程序中遵循类似的操作,就可以将您带到需要的地方.

The core points you'll want to look into are around track selection (via the TrackSelector) as well as the TrackSelectionHelper. I'll include the important code samples below which will hopefully be enough to get you going. But ultimately just following something similar in the demo app will get you where you need to be.

您将保留使用其启动播放器的音轨选择器,并将其用于几乎所有内容.

You'll hold onto the track selector you init the player with and use that for just about everything.

下面只是一段代码,理想地涵盖了您要执行的操作的要点,因为该演示确实使头发变得过于复杂.另外我还没有运行代码,但是已经足够接近了.

Below is just a block of code to ideally cover the gist of what you're trying to do since the demo does appear to over-complicate things a hair. Also I haven't run the code, but it's close enough.

这里有更多描述.

我在此处检查了解决方案,我相信它将为您提供帮助.

I checked for solution here,and I m sure it will help you.

    // These two could be fields OR passed around
    int videoRendererIndex;
    TrackGroupArray trackGroups;

    // This is the body of the logic for see if there are even video tracks
    // It also does some field setting
    MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo();
    for (int i = 0; i < mappedTrackInfo.length; i++) {
      TrackGroupArray trackGroups = mappedTrackInfo.getTrackGroups(i);
      if (trackGroups.length != 0) {
        switch (player.getRendererType(i)) {
          case C.TRACK_TYPE_VIDEO:
            videoRendererIndex = i;
            return true;
        }
      }
    }

    // This next part is actually about getting the list. It doesn't include
    // some additional logic they put in for adaptive tracks (DASH/HLS/SS),
    // but you can look at the sample for that (TrackSelectionHelper#buildView())
    // Below you'd be building up items in a list. This just does
    // views directly, but you could just have a list of track names (with indexes)
    for (int groupIndex = 0; groupIndex < trackGroups.length; groupIndex++) {
      TrackGroup group = trackGroups.get(groupIndex);
      for (int trackIndex = 0; trackIndex < group.length; trackIndex++) {
        if (trackIndex == 0) {
          // Beginning of a new set, the demo app adds a divider
        }
        CheckedTextView trackView = ...; // The TextView to show in the list
        // The below points to a util which extracts the quality from the TrackGroup
        trackView.setText(DemoUtil.buildTrackName(group.getFormat(trackIndex)));
    }

    // Assuming you tagged the view with the groupIndex and trackIndex, you
    // can build your override with that info.
    Pair<Integer, Integer> tag = (Pair<Integer, Integer>) view.getTag();
    int groupIndex = tag.first;
    int trackIndex = tag.second;
    // This is the override you'd use for something that isn't adaptive.
    override = new SelectionOverride(FIXED_FACTORY, groupIndex, trackIndex);
    // Otherwise they call their helper for adaptives, which roughly does:
    int[] tracks = getTracksAdding(override, trackIndex);
    TrackSelection.Factory factory = tracks.length == 1 ? FIXED_FACTORY : adaptiveTrackSelectionFactory;
    override = new SelectionOverride(factory, groupIndex, tracks);

    // Then we actually set our override on the selector to switch the quality/track
    selector.setSelectionOverride(rendererIndex, trackGroups, override);

正如我上面提到的,这是对过程的稍微简化,但是核心部分是您要弄乱TrackSelectorSelectionOverrideTrack/TrackGroups来达到目的工作.

As I mentioned above, this is a slight oversimplification of the process, but the core part is that you're messing around with the TrackSelector, SelectionOverride, and Track/TrackGroups to get this to work.

您可以想像地按原样复制演示代码,它应该可以工作,但是我强烈建议您花时间了解每一部分的工作,并针对您的用例量身定制解决方案.

You could conceivably copy the demo code verbatim and it should work, but I'd highly recommend taking the time to understand what each piece is doing and tailor your solution to your use case.

这篇关于mp4视频的Exoplayer Video Quality选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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