视频播放一次后SetcontentView

时间:2012-05-02 13:20:23

标签: android android-videoview

public void playvideo()
{
    setContentView(R.layout.testvideo);  

    VideoView video = (VideoView)findViewById(R.id.videoView1);    
    String videoName = "testvideo" ;
    // You build the URI to your video here 
    StringBuilder uriPathBuilder = new StringBuilder (); 
    uriPathBuilder.append ("android.resource://"); 
    uriPathBuilder.append (this.getPackageName ()); 
    uriPathBuilder.append (File.separator); 
    uriPathBuilder.append ("raw"); 
    uriPathBuilder.append (File.separator); 
    uriPathBuilder.append (videoName); 
    Uri uri = Uri.parse (uriPathBuilder.toString ()); 

    video.setVideoURI (uri); 
    video.start ();    
}

这是播放testvideo的功能。单击按钮时将调用此函数。我希望在视频播放完毕后再调用另一个功能。

2 个答案:

答案 0 :(得分:1)

你可能正在寻找setOnCompletionListener

video.setOnCompletionListener( new MediaPlayer.OnCompletionListener()
{
   public void onCompletion(MediaPlayer mp) 
        {
            // call some function
        }  
});

答案 1 :(得分:0)

如果您想调用其他功能,则可以覆盖

video.setOnCompletionListener(new MediaPlayer.OnCompletionListener(){});

只要您的视频完成,它就会调用上面的回调函数,您可以执行任何您想要的功能。