手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >android使用videoview播放视频
android使用videoview播放视频
摘要:复制代码代码如下:publicclassActivity01extendsActivity{/**Calledwhentheactivity...

复制代码 代码如下:

public class Activity01 extends Activity

{

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState)

{

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

final VideoView videoView = (VideoView) findViewById(R.id.VideoView01);

Button PauseButton = (Button) this.findViewById(R.id.PauseButton);

Button LoadButton = (Button) this.findViewById(R.id.LoadButton);

Button PlayButton = (Button) this.findViewById(R.id.PlayButton);

// load

LoadButton.setOnClickListener(new OnClickListener() {

public void onClick(View arg0)

{

//videoView.setVideoPath("/sdcard/test.mp4");

videoView.setVideoPath("android.resource://com.homer/"+R.raw.china);

videoView.setMediaController(new MediaController(Activity01.this));

videoView.requestFocus();

}

});

// play

PlayButton.setOnClickListener(new OnClickListener() {

public void onClick(View arg0)

{

videoView.start();

}

});

// pause

PauseButton.setOnClickListener(new OnClickListener() {

public void onClick(View arg0)

{

videoView.pause();

}

});

}

}

main.xml

复制代码 代码如下:

<?xml version="1.0" encoding="utf-8"?>

<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical" >

<TextView

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/hello" />

<VideoView

android:id="@+id/VideoView01"

android:layout_width="320px"

android:layout_height="240px" />

<Button

android:id="@+id/LoadButton"

android:layout_width="80px"

android:layout_height="wrap_content"

android:layout_x="30px"

android:layout_y="300px"

android:text="装载" />

<Button

android:id="@+id/PlayButton"

android:layout_width="80px"

android:layout_height="wrap_content"

android:layout_x="120px"

android:layout_y="300px"

android:text="播放" />

<Button

android:id="@+id/PauseButton"

android:layout_width="80px"

android:layout_height="wrap_content"

android:layout_x="210px"

android:layout_y="300px"

android:text="暂停" />

</AbsoluteLayout>

【android使用videoview播放视频】相关文章:

android viewpaper实例探讨

android WebView组件使用总结

android开发之调用手机的摄像头使用MediaRecorder录像并播放

Android Studio使用教程图文详解

Android-使用AIDL进程间通信

android使用Messenger绑定Service的多种实现方法

android ListView深入理解

Android GridView的使用

android控件之WebView控件缩小

android textview 显示html方法解析

精品推荐
分类导航