2011-04-06 11 views
31

Tengo un cuadro de diálogo simple con un VideoView y quiero reproducir el video en un bucle.Android: Vista de video: cómo reproducir un video en un bucle

Actualmente estoy usando una solución rápida

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

pero me gustaría saber si hay una manera mejor?


Editar

estoy añadiendo más código, porque no sé cómo puedo conseguir el acceso al objeto MediaPlayer forman el 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(); 

estoy actualmente buscando en usar directamente MediaPlayer y SurfaceView BU Me gustaría saber si hay una manera con VideoView directamente

+0

Por favor, intente esto, es trabajo para mí claramente [http://stackoverflow.com/a/27606389/3414469][1] – ylmzekrm1223

Respuesta

74

Use setLooping(true) en su instancia de MediaPlayer.

--Edit--

Cómo sobre el uso setOnPrepareListener en lugar de setOnCompletionListener? Esto le da acceso al objeto MediaPlayer.

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

El problema que tengo es lo uso VideoView y no hacer ver cómo obtener acceso al reproductor multimedia. (Actualizaré mi código) –

+0

Consulte la respuesta editada, hágame saber si eso le funciona. –

+0

Bueno, en realidad cambio a una vista de superficie y un reproductor multimedia y resolvió mi problema –

Cuestiones relacionadas