//android播放视频,使用方法:在androidManifest.xml中添加activity, // <activity android:name=".PlayVideo" // android:label="@string/app_name"> // // </activity> //注意资源路径 //调用时: //Intent intent = new Intent(MainActivity.this, PlayVideo.class); //从mainActivity跳转到playvideo中 //this.startActivity(intent); //白白原创 package com.homer; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.MediaController; import android.widget.VideoView; public class PlayVideo 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); videoView.setVideoPath("android.resource://com.homer/"+R.raw.test); videoView.setMediaController(new MediaController(PlayVideo.this)); videoView.requestFocus(); videoView.start(); Button stopButton = (Button) this.findViewById(R.id.stopButton); stopButton.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { videoView.stopPlayback(); } }); } }
android利用videoView播放视频(已封装)
时间: 2024-09-29 18:12:13