<FrameLayout 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"
tools:context="com.example.videoview.MainActivity" >
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="416dp" />
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal" >
<Button
android:id="@+id/start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="开始" />
<Button
android:id="@+id/pause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="暂停" />
<Button
android:id="@+id/seekto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3秒处" />
</LinearLayout>
</FrameLayout>
activity_main.xml
测试主代码:
package com.example.videotest;
import java.io.File;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore.Video;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.VideoView;
public class MainActivity extends Activity implements OnClickListener {
private VideoView videoView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
videoView = (VideoView) findViewById(R.id.videoView);
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
File f = new File(path, "/Camera/test.mp4");
videoView.setVideoPath(f.getAbsolutePath());
Button start = (Button) findViewById(R.id.start);
start.setOnClickListener(this);
Button pause = (Button) findViewById(R.id.pause);
pause.setOnClickListener(this);
Button seekto = (Button) findViewById(R.id.seekto);
seekto.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.start:
videoView.start();
break;
case R.id.pause:
videoView.pause();
break;
case R.id.seekto:
videoView.seekTo(3*1000);
break;
}
}
}