1

我正在我的应用程序中播放资产中的视频。我正在为平板电脑开发应用程序。我有 mp4 视频。我在 xml 中的视频视图如下。

我的问题是我要在左右两侧对齐视频和间隙。视频需要全屏播放。

  <VideoView
    android:id="@+id/videoview1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true" />

这里是我用来播放视频的代码。

videoPaths.add("android.resource://" + getPackageName() + "/"
            + R.raw.intro);
    videoPaths.add("android.resource://" + getPackageName() + "/"
            + R.raw.show_buttons);
    videoPaths.add("android.resource://" + getPackageName() + "/"
            + R.raw.loop);

    videoView = (VideoView) findViewById(R.id.videoview1);
    playVideos();

}

private Runnable playerRunnable = new Runnable() {

    @Override
    public void run() {
        // TODO Auto-generated method stub
        int videoDuration = videoView.getCurrentPosition();
        Log.e(this.getClass().getSimpleName(),
                "videoDuration == " + videoDuration + " total time == "
                        + videoView.getDuration());
        if (isFirstVideo == 0) {

            if (videoDuration > 8500) {
                Log.e(this.getClass().getSimpleName(),
                        "video duration is above 8500");

                isFirstVideo = 1;

                videoView.setVideoURI(Uri.parse(videoPaths
                        .get(isFirstVideo)));


            }

        }

    }
};

private void playVideos() {
    isFirstVideo = 0;
    videoView.setVideoURI(Uri.parse(videoPaths.get(isFirstVideo)));
    videoView.start();
    // handler.post(playerRunnable);
    handler.postDelayed(playerRunnable, 500);
}
4

0 回答 0