一个接一个地播放在线视频

时间:2013-07-31 12:03:11

标签: java android android-videoview

我有一个带有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();

        }

上面的代码是一个按钮点击事件。它工作得很好。如果第一个视频完成,则应自动播放第二个视频。因此,我想连续播放该阵列中的所有视频。怎么做到这一点?请帮帮我:))

2 个答案:

答案 0 :(得分:2)

最后我发现了如何播放所有存储在数组中的网址的视频。当我播放视频时,它有时会逐个播放两个视频,有时只播放一个视频。 这就是我解决这个问题的方法。感谢@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();
            }
        });
        }
    }

答案 1 :(得分:1)

public class MainActivity extends Activity implements OnCompletionListener{

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

    }
}