在ExoPlayer中播放的预缓冲视频

问题描述 投票:1回答:1

我想在播放多个视频之前先对其进行缓冲。我为每个视频URL创建了一个exoplayer实例列表,并将该实例传递给处于不同活动中的playerView。我没有收到任何错误,但视频根本没有播放。我不确定这是否是实现预缓冲的正确方法。下面是我创建播放器实例的arrayList的方法。

private void setExoPlayer(String videoName, String folderName) {
        SimpleExoPlayer tutorial_player;
        String separator = "/";
        String user_lang = manager.getString("getSelectedLanguage");
        String videoUrl = Constant.appVideosURL + folderName + separator + user_lang + separator + videoName + separator + "hls" + separator + videoName + ".m3u8";
        Uri videoUri = Uri.parse(videoUrl);
        DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();

        TrackSelection.Factory videoTrackSelectionFactory =
                new AdaptiveTrackSelection.Factory(bandwidthMeter);

        TrackSelector trackSelector =
                new DefaultTrackSelector(videoTrackSelectionFactory);
        DefaultAllocator allocator = new DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE);
                /*
            parameters to define buffer
            DEFAULT_MIN_BUFFER_MS = 360000
            DEFAULT_MAX_BUFFER_MS = 700000
            Valores default do ExoPlayer2
            DEFAULT_BUFFER_FOR_PLAYBACK_MS = 2500
            DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS = 5000
        */
        DefaultLoadControl.Builder loadControl = new DefaultLoadControl.Builder();
        loadControl.setBufferDurationsMs(360000, 700000, 2500, 5000);
        //Initialize the player
        tutorial_player = ExoPlayerFactory.newSimpleInstance(mctx, trackSelector);
        tutorial_player.setVideoScalingMode(C.VIDEO_SCALING_MODE_SCALE_TO_FIT);

        // Produces DataSource instances through which media data is loaded.
        DataSource.Factory dataSourceFactory =
                new DefaultDataSourceFactory(mctx, Util.getUserAgent(mctx, "SmartMirror"), bandwidthMeter);

        // This is the MediaSource representing the media to be played.
            MediaSource mediaSource = new HlsMediaSource(videoUri, dataSourceFactory, 1, null, null);
        tutorial_player.prepare(mediaSource);
        tutorial_player.setPlayWhenReady(true);
        tutorial_player.addListener(new Player.EventListener() {
            @Override
            public void onPlayerError(ExoPlaybackException error) {
                String errorString = null;
                if (error.type == ExoPlaybackException.TYPE_RENDERER) {
                    Exception cause = error.getRendererException();
                    if (cause instanceof MediaCodecRenderer.DecoderInitializationException) {
                        // Special case for decoder initialization failures.
                        MediaCodecRenderer.DecoderInitializationException decoderInitializationException =
                                (MediaCodecRenderer.DecoderInitializationException) cause;
                        if (decoderInitializationException.decoderName == null) {
                            if (decoderInitializationException.getCause() instanceof MediaCodecUtil.DecoderQueryException) {
                                errorString = "error querying decoder";
                            } else if (decoderInitializationException.secureDecoderRequired) {
                                errorString = "error_no_secure_decoder";
                            } else {
                                errorString = "error_no_decoder";
                            }
                        } else {
                            errorString = "error_instantiating_decoder";
                        }
                    }

                }

            }
        });
        player.add(tutorial_player);

    }

在此方法中,我仅从arrayList中获取一个实例并在播放器中进行设置。

 public void setVideoPlayerAndMirrorPosition(SimpleExoPlayer simpleExoPlayer) {
            playerView.setPlayer(simpleExoPlayer);
            simpleExoPlayer.setPlayWhenReady(true);

        }

我想知道我们如何实现对多个视频的这种预缓冲。

android exoplayer exoplayer2.x
1个回答
0
投票

您可以检查此链接。androidwave.com

他们解释得很简单。

© www.soinside.com 2019 - 2024. All rights reserved.