在ExoPlayer中选择默认的MP4曲目

时间:2018-07-16 14:26:33

标签: android mp4 exoplayer

我在两个不同的列表中具有多个mp4格式和多种语言字幕,我正在使用这些格式和字幕创建一个MergingMediaSource。在两种形式的再现中,ExoPlayer都会获得最高分辨率的再现(在我的情况下为1920x1080)并进行播放。但是我要对此进行控制,我想根据我在应用程序设置中选择的值播放演绎。

我使用以下代码将最大高度设置为360,但即使这样,ExoPlayer仍会播放1080p再现:

trackSelector.setParameters(trackSelector.getParameters().buildUpon()
    .setMaxVideoSize(Integer.MAX_VALUE, 360).build());

以下是我用来创建MergingMediaSource的代码:

private MediaSource createMediaSource() {
    List<MediaSource> mediaSourceList = new ArrayList<>();
    // Iterate the list of Mp4s and add the URLs to the list
    for (int i = 0; i < availableStreamingQualities.size(); i++) {
        ...
        // this buildMediaSource method create one of the MediaSource which can be HLS/DASH/SS/Extractor etc
        // for mp4s ExtractorMediaSource is used.
        mediaSourceList.add(buildMediaSource(Uri.parse(streamingQualityUrl), ""));
        ...
    }
    // Iterate the list of subtitles and add the URLs to the list
    for (int i = 0; i < closedCaptionsList.size(); i++) {
        ClosedCaptions closedCaptions = closedCaptionsList.get(i);
        if (closedCaptions.getFormat().equalsIgnoreCase("SRT")) {
            Format textFormat = Format.createTextSampleFormat(null,
                    MimeTypes.APPLICATION_SUBRIP,
                    C.SELECTION_FLAG_DEFAULT,
                    closedCaptions.getLanguage());

            String ccFileUrl = closedCaptions.getUrl();
            mediaSourceList.add(new SingleSampleMediaSource(
                    Uri.parse(ccFileUrl),
                    mediaDataSourceFactory,
                    textFormat,
                    C.TIME_UNSET));
        }
    }
    // convert the list to an array and pass it to new MergingMediaSource object
    MediaSource mediaSources[] = new MediaSource[mediaSourceList.size()];
    mediaSourceList.toArray(mediaSources);
    return new MergingMediaSource(mediaSources);
}

0 个答案:

没有答案