android VideoView实现视频的播放

来源:互联网 时间:1970-01-01

在VideoView进行播放mp4视频。


main.xml  加入一个VideoView组件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".main"> <VideoView android:id="@+id/VideoView1" android:layout_height="200dip" android:layout_width="200dip" /></RelativeLayout>


main.java

package com.example.miki.multimedia;import android.app.Activity;import android.media.MediaPlayer;import android.net.Uri;import android.os.Bundle;import android.widget.MediaController;import android.widget.VideoView;public class main extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); VideoView videoView=(VideoView) findViewById(R.id.VideoView1); String rui="android.resource://"+getPackageName()+"/"+R.raw.raw4; videoView.setVideoURI(Uri.parse(rui)); //指定要播放的位置 videoView.requestFocus(); // videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { mp.setLooping(true); //重复播放 } }); videoView.start(); /*************创建多媒体控制器进行控制进度条和开始暂停**********************/ MediaController mediaController=new MediaController(this); videoView.setMediaController(mediaController); mediaController.setMediaPlayer(videoView); mediaController.show(); } }

运行时结果截图:



相关阅读:
Top