1. 程式人生 > >安卓視訊播放和拍照

安卓視訊播放和拍照

09_視訊播放器videoview(重點)

程式碼:

    //得到視訊播放器
	vv = (VideoView) findViewById(R.id.vv);
	//指定播放的視訊資源
	vv.setVideoPath("http://192.168.1.254:8080/11.mp4");
	//開始播放
	vv.start();

照相機拍照(重點)

程式碼:

	package com.itheima.camera;

	import java.io.File;
	
	import android.app.Activity;
	import android.content.Intent;
	import android.net.Uri;
	import android.os.Bundle;
	import android.os.Environment;
	import android.provider.MediaStore;
	import android.view.View;
	import android.widget.Toast;
	
	public class MainActivity extends Activity {
	
		@Override
		protected void onCreate(Bundle savedInstanceState) {
			super.onCreate(savedInstanceState);
			setContentView(R.layout.activity_main);
		}
	
		public void takePhoto(View view){
			
			//建立拍照的意圖物件
			Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
			//指定照片的儲存位置
			Uri uri = Uri.fromFile(new File(Environment.getExternalStorageDirectory()+"/123456.jpg"));
			intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
			//開啟手機自帶的拍照功能
			startActivityForResult(intent, 0);
		}
		
		@Override
		protected void onActivityResult(int requestCode, int resultCode, Intent data) {
			super.onActivityResult(requestCode, resultCode, data);
			
			Toast.makeText(this, "拍照成功", 0).show();
		}
		
	}