1

我有一个带有 videoview 的 xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
   android:background="@drawable/back"
    android:orientation="vertical" 
    android:screenOrientation="landscape">


<VideoView
            android:id="@+id/videoview_concept"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
</LinearLayout>

我的java部分是:

public class playvideos extends Activity implements OnCompletionListener{
    public Integer index_val=0;
    @Override
    public void onCompletion(MediaPlayer mediaPlayer) {
        index_val++;
        VideoView videoview= (VideoView)findViewById(R.id.videoview_concept);
        checkdbconn();
        videoview.setVideoURI(Uri.parse(prepare.txtLectureFileName[index_val]));
        videoview.setMediaController(new MediaController(this));
        videoview.requestFocus();
        videoview.start();


    }
    public void playvideo(View view){
            setContentView(R.layout.playvid);
            VideoView videoview= (VideoView)findViewById(R.id.videoview_concept);
            Log.i("Video URL",videourl_array[index_val]);
            checkdbconn();
            videoview.setVideoURI(Uri.parse(videourl_array[index_val]));
            videoview.setMediaController(new MediaController(this));
            videoview.requestFocus();
            checkdbconn();
            videoview.start();

        }

上面的代码是一个按钮点击事件。它真的很好用。如果第一个视频完成,它应该自动播放第二个视频。因此,我想连续播放该数组中的所有视频。如何做到这一点?请帮帮我:)

4

2 回答 2

2

最后我发现了如何播放所有 url 存储在数组中的视频。当我播放视频时,有时它会一个接一个地播放两个视频,有时只播放一个视频。这就是我解决这个问题的方法。感谢@Kirit。

public void playvideos_all(){
        videoview.setVideoURI(Uri.parse(prepare.txtLectureFileName[index_val]));
        videoview.setMediaController(new MediaController(this));
        videoview.requestFocus();
        videoview.start();
        videoview.setClickable(true);
        index_val++;
        if(index_val>=no_of_videos){
            Toast.makeText(getApplicationContext(), "Videos are finished index: "+index_val+"no of videos:"+no_of_videos, Toast.LENGTH_LONG).show();
        }
        else{
        videoview.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion (MediaPlayer mp) {
                mp.stop();
                videoview.stopPlayback();
                videoview.suspend();
                playvideos_all();
            }
        });
        }
    }
于 2013-08-12T08:16:06.507 回答
1
public class MainActivity extends Activity implements OnCompletionListener{

    @Override
    public void onCompletion(MediaPlayer mediaPlayer) {
         // play next video

    }
}
于 2013-07-31T12:18:07.093 回答