2014-12-08 59 views

回答

16

Exoplayer提供媒體播放器不提前實施。

Exoplayer由Android高級例如

,在FullPlayerActivity.java他們已經實施onStateChanged,提供STATE_ENDED

您可以從this page右手部分下學期相關樣本下載例子

+1

的聯繫被破壞 – 2015-09-16 15:05:27

+0

他們已經更新了SDK和樣品,一點點搜索將產生結果。順便說一句,我已經更新了斷開的鏈接。 – 2015-09-17 06:25:29

+0

小細節它是onPlayerStateChanged。可能他們更新了它。 – 2017-04-06 12:41:24

16

我知道這是舊的,但只是爲了擴大公認的答案:

exoPlayer.addListener(this); 

..... 

@Override 
public void onPlayerStateChanged(boolean playWhenReady, int state) { 

    if (state == ExoPlayer.STATE_ENDED){ 
     //player back ended 
    } 
} 
+0

'onPositionDiscontinuity()'在我的情況下被調用如何處理呢? – Gattsu 2017-05-16 13:23:24

3

你可以這樣做:

playerExo.addListener(new ExoPlayer.Listener() { 

      @Override 
      public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { 

       switch(playbackState) { 
        case ExoPlayer.STATE_BUFFERING: 
         break; 
        case ExoPlayer.STATE_ENDED: 
         //do what you want 
         break; 
        case ExoPlayer.STATE_IDLE: 
         break; 
        case ExoPlayer.STATE_PREPARING: 
         break; 
        case ExoPlayer.STATE_READY: 
         break; 
        default: 
         break; 
       } 
      } 

      @Override 
      public void onPlayWhenReadyCommitted() { 

      } 

      @Override 
      public void onPlayerError(ExoPlaybackException error) { 

      } 
     }); 
     playerExo.seekTo(0); 
     playerExo.setPlayWhenReady(true); 

但@Murtaza胡爾希德·侯賽因的答案是正確的!有一個很好的代碼一天!讓我知道如果你需要別的東西!

+0

STATE_ENDED被叫兩次 – Erum 2017-11-16 12:26:30

+0

檢查播放視頻或不使用player.getPlayWhenReady() – Suresh 2018-02-27 10:49:29

0

ExoPlayer.STATE_ENDED已折舊。改用Player.STATE_ENDED。 例子:

@Override 
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { 
    if(playbackState == Player.STATE_ENDED){ 
     // your brain put here 
    } 
}