转载自:http://blog.csdn.net/yudajun/article/details/7752226
1、调用系统音乐播放器
- private void playAudio(String audioPath){
- Intent intent = new Intent();
- intent.setAction(android.content.Intent.ACTION_VIEW);
- intent.setDataAndType(Uri.parse(audioPath), "audio/mp3");
- intent.setComponent(new ComponentName("com.android.music","com.android.music.MediaPlaybackActivity"));
- startActivity(intent);
- }
或者
- Intent it = new Intent(Intent.ACTION_VIEW);
- it.setDataAndType(Uri.parse("/sdcard/111.mp3"), "audio/mp3");
- startActivity(it);
2、调用系统视频播放器
- private void playVideo(String videoPath){
- Intent intent = new Intent(Intent.ACTION_VIEW);
- String strend="";
- if(videoPath.toLowerCase().endsWith(".mp4")){
- strend="mp4";
- }
- else if(videoPath.toLowerCase().endsWith(".3gp")){
- strend="3gp";
- }
- else if(videoPath.toLowerCase().endsWith(".mov")){
- strend="mov";
- }
- else if(videoPath.toLowerCase().endsWith(".wmv")){
- strend="wmv";
- }
- intent.setDataAndType(Uri.parse(videoPath), "video/"+strend);
- startActivity(intent);
- }
或者
- Intent it = new Intent(Intent.ACTION_VIEW);
- it.setDataAndType(Uri.parse("/sdcard/1122.mp4"), "video/mp4");
- startActivity(it);
播放来自网络多媒体文件
- String extension = MimeTypeMap.getFileExtensionFromUrl(url);
- String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
- Intent mediaIntent = new Intent(Intent.ACTION_VIEW);
- mediaIntent.setDataAndType(Uri.parse(url), mimeType);
- startActivity(mediaIntent);
调用系统Camera
- public class SysCamera extends Activity {
- public static final int MEDIA_TYPE_IMAGE = 1;
- public static final int MEDIA_TYPE_VIDEO = 2;
- private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;
- private static final int CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE = 200;
- private Uri fileUri;
- Button btvideo,btphoto;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.syscamera);
- btphoto=(Button)findViewById(R.id.sysPhoto);
- btvideo=(Button)findViewById(R.id.sysVideo);
- btphoto.setOnClickListener(new Monitor());
- btvideo.setOnClickListener(new Monitor());
- }
- private void PhotoIntent(){
- // create Intent to take a picture
- Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
- fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to save the image
- intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
- // start the image capture Intent
- startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
- }
- private void VideoIntent(){
- //create new Intent
- Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
- fileUri = getOutputMediaFileUri(MEDIA_TYPE_VIDEO); // create a file to save the video
- intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
- intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); // set the video image quality to high
- // start the Video Capture Intent
- startActivityForResult(intent, CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE);
- }
- /** Create a file Uri for saving an image or video */
- private static Uri getOutputMediaFileUri(int type){
- return Uri.fromFile(getOutputMediaFile(type));
- }
- /** Create a File for saving an image or video */
- private static File getOutputMediaFile(int type){
- if (Environment.getExternalStorageState() == null){
- return null;
- }
- File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
- Environment.DIRECTORY_PICTURES), "MyCameraApp");
- // Create the storage directory if it does not exist
- if (! mediaStorageDir.exists()){
- if (! mediaStorageDir.mkdirs()){
- Log.d("MyCameraApp", "failed to create directory");
- return null;
- }
- }
- // Create a media file name
- String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
- File mediaFile;
- if (type == MEDIA_TYPE_IMAGE){
- mediaFile = new File(mediaStorageDir.getPath() + File.separator +
- "IMG_"+ timeStamp + ".jpg");
- } else if(type == MEDIA_TYPE_VIDEO) {
- mediaFile = new File(mediaStorageDir.getPath() + File.separator +
- "VID_"+ timeStamp + ".mp4");
- } else {
- return null;
- }
- return mediaFile;
- }
- @Override
- public void onBackPressed() {
- Intent in=new Intent(this, MyRecorderActivity.class);
- startActivity(in);
- super.onBackPressed();
- }
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
- if (resultCode == RESULT_OK) {
- // Image captured and saved to fileUri specified in the Intent
- Toast.makeText(this, "Image saved to:\n" +
- data.getData(), Toast.LENGTH_LONG).show();
- } else if (resultCode == RESULT_CANCELED) {
- // User cancelled the image capture
- } else {
- // Image capture failed, advise user
- }
- }
- if (requestCode == CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE) {
- if (resultCode == RESULT_OK) {
- // Video captured and saved to fileUri specified in the Intent
- Toast.makeText(this, "Video saved to:\n" +
- data.getData(), Toast.LENGTH_LONG).show();
- } else if (resultCode == RESULT_CANCELED) {
- // User cancelled the video capture
- } else {
- // Video capture failed, advise user
- }
- }
- }
- class Monitor implements OnClickListener{
- @Override
- public void onClick(View v) {
- switch(v.getId()){
- case R.id.sysPhoto:
- PhotoIntent();
- break;
- case R.id.sysVideo:
- VideoIntent();
- break;
- }
- }
- }
- }
相关推荐
使用Qt for android调用原生系统的摄像头来录取设备,稳定高效,使用于安卓7.0版本及以上,测试在魅族5.0会后台死掉,但是录像会成功
Android调用系统摄像头(不是自定义摄像头的设计,而是调用手机中自带的摄像头) IDE版本:Android Studio 3.5.1
Android 调用系统相机/相册 获取照片 在照片上添加文字水印
这是github的项目源码地址。Android Studio2.3.3调用系统的Camera实现拍照功能,并将照片保存到本地内存卡中
Android调用系统相机和自定义相机实例圆形取景框。Camera工具类
MainActivity类是调用系统摄像头 MyCameroActivity类是通过surfaceholder的方式调用camera拍照的,只用拍照功能。适合初学者的。
简单的Android opencv 摄像头调用的demo 适合新手学习。行如逆水行舟,不进则退。
调用系统相机进行拍照demo,代码是自己跟着慕课网课程《Android摄像头基础》(https://www.imooc.com/u/2950649/courses)中手动敲的,如果大家不想下载可以直接去看视频讲解,很短而且讲的不错。需要注意的是在真机...
android通过USB外接摄像头这是一个例子,通过C调用底层驱动。在网上找过了例子总出现select timeout异常,改造解决了。有问题可以发邮件505738005.
本文实例讲述了Android调用摄像头功能的方法。分享给大家供大家参考,具体如下: 我们要调用摄像头的拍照功能,显然 第一步必须加入调用摄像头硬件的权限,拍完照后我们要将图片保存在SD卡中,必须加入SD卡读写权限...
android 调用照相机拍照,其中对对焦进行了一定的优化
android 实现调用系统的照相机照相,并简单的显示显示
首先,我们知道调用系统的裁切是通过Intent intent = new Intent(“com.android.camera.action.CROP”); 但是intent到底能够携带哪些数据呢,都有什么含义呢,我们可以看到如下: 上面包含了所有可选的操作,...
android studio 调用摄像头拍照或选择相册照片,拿到图片并存储图片
资源中的打开相机和相册均是原生Java代码实现,在我自己手机和安卓7.0版本上面稳定可靠,测试在魅族5.0版本左右打开相机会死掉,由Qt调用,demo可学习Qt如何与原生Java的交互通信,代码均有注释,里面还有微信等接口...
利用MediaRecorder+Camera2框架实现基本的录像功能,当APP启动时自动打开摄像头,点击按钮开始录像,点击按钮停止录像并将录制的视频文件保存在sdcard/my_video/中
Android调用系统裁剪,这个已经使用的很熟悉了。但是近期项目里使用的时候遇到了一些小问题,所以在此整理一下,以作记录。 首先看代码: Intent intent1 = new Intent(com.android.camera.action.CROP); intent1....
delphi xe5 android 调用照相机摄像头拍照片camera,简单非常实用的原代码,无特定组件!
在Android开发过程中,有时需要调用手机自身设备的功能,本演示项目侧重摄像头拍照功能的调用。
安卓开发调用系统拍照和摄像功能并保存到自定义文件夹中