ExoPlayer - play 10 files one after another

后端 未结 5 1431
天命终不由人
天命终不由人 2021-02-03 12:30

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

I\'m using Google\'s ExoPlayer, I use the example in the DEMO @ GitHub. I can play 1 video

相关标签:
5条回答
  • 2021-02-03 13:08

    I'm using Exoplayer change mp4 video success. I use the example in the DEMO. 1.DEMO project in DemoPlayer.java:

     private final RendererBuilder rendererBuilder;
     //remove final,then modify that:
    
     private RendererBuilder rendererBuilder;
    
     //and add the set method:
     public void setRendererBuilder(RendererBuilder rendererBuilder){
          this.rendererBuilder = rendererBuilder;
      }
    
     //finally,add stop method
     public void stop(){
          player.stop();
      }
    

    2.DEMO project in PlayerActivity.java: add method:

    private void changeVideo(){
            player.stop();
            player.seekTo(0L);
            //you must change your contentUri before invoke getRendererBuilder();
            player.setRendererBuilder(getRendererBuilder());
            player.prepare();
            playerNeedsPrepare = false;
        }
    

    remember change param contentUri before invoke changeVideo method.

    0 讨论(0)
  • 2021-02-03 13:11

    There is another solution, you could refer to ConcatenatingMediaSource to achieve auto play next media.

    In Demo App example : 1. Launch ExoPlayer 2. Select Playlists 3. Choose Cats->Dogs

    0 讨论(0)
  • 2021-02-03 13:15

    OK, Answering my own question. on the example, google init the ExoPlayer at OnResume(). i had to re-init for every video like that:

    player = ExoPlayer.Factory.newInstance(2, 1000, 5000);
    

    if someone has a better idea, please let me know.

    0 讨论(0)
  • 2021-02-03 13:15

    Use ConcatenatingMediaSource to play files in sequence. For example, for playing 2 media Uris (firstVideoUri and secondVideoUri), use this code:

    MediaSource firstSource =
        new ExtractorMediaSource.Factory(...).createMediaSource(firstVideoUri);
    MediaSource secondSource =
        new ExtractorMediaSource.Factory(...).createMediaSource(secondVideoUri);
    
    ConcatenatingMediaSource concatenatedSource =
        new ConcatenatingMediaSource(firstSourceTwice, secondSource);
    

    And then use concatenatedSource to play media files sequentially.

    0 讨论(0)
  • 2021-02-03 13:34

    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.

    0 讨论(0)
提交回复
热议问题