2011-04-06 204 views
31

我收到了一個簡單的對話框,其中包含VideoView,我想在循環中播放視頻。Android:視頻視圖:如何在循環中播放視頻

我目前使用速戰速決

//Video Loop 
     vv.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { 
      public void onCompletion(MediaPlayer mp) { 
       vv.start(); 
      } 
     }); 

,但我想知道是否有更好的辦法?


編輯

我添加更多的代碼,因爲我不知道我怎樣才能訪問MediaPlayer對象形成VideoView

String path = defaultPath+currentVideoRessource; 


    if (path == null || path.length() == 0) { 
     Log.e("extra","File URL/path is empty"); 
    } else { 
     // If the path has not changed, just start the media player 
     if (!path.equals(current) && mVideoView != null) { 
       Uri pathURI = Uri.parse(defaultPath+currentVideoRessource); 
       mVideoView.setVideoURI(pathURI); 
    } 
    current = path; 
    mVideoView.setOnCompletionListener(new MyOnCompletionListener(this)); 
    //Video Loop 
    //    mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { 
    //     public void onCompletion(MediaPlayer mp) { 
    //      mVideoView.start(); //need to make transition seamless. 
    //     } 
    //    }); 

    mVideoView.start(); 
    mVideoView.requestFocus(); 

我目前調查直接使用MediaPlayerSurfaceView埠我想知道是否有方式VideoView直接

+0

請試試這個,這是爲我工作明確 [http://stackoverflow.com/a/27606389/3414469][1] – ylmzekrm1223 2014-12-22 16:24:02

回答

74

在MediaPlayer實例上使用setLooping(true)

- 編輯 -

如何使用setOnPrepareListener代替setOnCompletionListener?這使您可以訪問MediaPlayer對象。

vv.setOnPreparedListener (new OnPreparedListener() {      
    @Override 
    public void onPrepared(MediaPlayer mp) { 
     mp.setLooping(true); 
    } 
}); 
+0

我的問題是,我使用VideoView,我不瞭解如何訪問媒體播放器。 (我會更新我的代碼) – 2011-04-07 10:41:04

+0

請參閱編輯答案,讓我知道如果這對你有用。 – 2011-04-07 16:54:38

+0

以及我實際上切換到表面視圖和媒體播放器,它解決了我的問題 – 2011-04-07 17:00:50