ExoPlayer - 接连打10文件之一 [英] ExoPlayer - play 10 files one after another

查看:805
本文介绍了ExoPlayer - 接连打10文件之一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有10个视频,我需要踢球,当一个人完成,下一个开始播放。

I have 10 video i need to play, once one is done, the next one starts to play.

我使用谷歌的ExoPlayer ,我用这个例子在<一个href="https://github.com/google/ExoPlayer/tree/master/demo/src/main/java/com/google/android/exoplayer/demo"相对=nofollow>样本@ GitHub上。 我可以玩1个视频,但如果我尝试播放下一个,它不会启动。

I'm using Google's ExoPlayer, I use the example in the DEMO @ GitHub. I can play 1 video but if i try to play the next one, it wont start.

如果我尝试重新初始化播放器,并重新开始播放,它崩溃。

If i try to reInit the player, and the start playing again, it crashes.

private void loadvideo() {
    Uri uri = Uri.parse(VIDEO_LIBRARY_URL + currentVideo + ".mp4");
    sampleSource = new FrameworkSampleSource(this, uri, null, 2);

    // 1. Instantiate the player.
    // 2. Construct renderers.
    videoRenderer = new MediaCodecVideoTrackRenderer(sampleSource, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
    audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource);
    // 3. Inject the renderers through prepare.
    player.prepare(videoRenderer, audioRenderer);
    // 4. Pass the surface to the video renderer.
    surface = surfaceView.getHolder().getSurface();

    player.sendMessage(videoRenderer, MediaCodecVideoTrackRenderer.MSG_SET_SURFACE, surface);
    // 5. Start playback.
    player.setPlayWhenReady(true);
    player.addListener(new ExoPlayer.Listener() {
        @Override
        public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
            Log.d(TAG, "onPlayerStateChanged + " + playbackState);
            if (playbackState == ExoPlayer.STATE_ENDED) {
                currentVideo++;
                loadNextVideo();
            }
        }

        @Override
        public void onPlayWhenReadyCommitted() {

        }

        @Override
        public void onPlayerError(ExoPlaybackException error) {

        }
    });

}

我究竟做错了什么? 我怎么能播放视频的连续性?

What am i doing wrong? How can i play videos continuity?

感谢。

推荐答案

您可以重复使用ExoPlayer,直到你调用发布()的点,然后它不应再使用。

You can reuse the ExoPlayer up until the point that you call release(), and then it should no longer be used.

要改变媒体认为这是当前正在播放,您基本上需要执行以下步骤:

To change the media that it is currently playing, you essentially need to perform the following steps:

// ...enable autoplay...
player.stop();
player.seekTo(0L);
player.prepare(renderers);

创建渲染器是更复杂一点,但是这是你应该遵循的流程和玩家应该能够打背靠背的视频。

Creating the renderers is a little bit more involved, but that's the flow you should follow and the player should be able to play back to back videos.

这篇关于ExoPlayer - 接连打10文件之一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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