先展示下效果图:
1.这个是调到系统录制视频界面

VideoActivity.java

package com.example.videodisplay;import android.content.Intent;import android.provider.MediaStore;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.Button;public class VideoActivity extends AppCompatActivity {    private Button bt_1;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_video);        bt_1 = (Button) findViewById(R.id.bt_1);        bt_1.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View view) {                Intent intent =  new Intent(MediaStore.ACTION_VIDEO_CAPTURE);                intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY,  1);                intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT,  61);                //这里1024 * 1024 * 100是指限制100M,当达到是会自动停止录制                intent.putExtra(MediaStore.EXTRA_SIZE_LIMIT,  1024 * 1024 * 100);                startActivityForResult(intent,  11);            }        });    }}

activity_video.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/activity_video"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    android:orientation="vertical"    tools:context="com.example.videodisplay.VideoActivity">    <Button        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="跳转至录制视频"        android:id="@+id/bt_1"        />LinearLayout>

2.这个是使用mediaRecorder实现的

Video2Activity .java

package com.example.videodisplay;import android.media.MediaPlayer;import android.media.MediaRecorder;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.SurfaceView;import android.view.View;import java.io.IOException;public class Video2Activity extends AppCompatActivity {    private SurfaceView sfv;    private MediaRecorder mediaRecorder;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_video2);        sfv = (SurfaceView) findViewById(R.id.sv_media_recoder_surface);        //实例化MediaRecorder        mediaRecorder = new MediaRecorder();    }    public void start(View view){        mediaRecorder.reset();        //设置来源        mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);        mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);        //设置格式        mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);        //设置编码格式        mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);        mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);        //设置保存的路径         mediaRecorder.setOutputFile("mnt/sdcard//360Video/Video_"+System.currentTimeMillis()+".mp4");         mediaRecorder.setPreviewDisplay(sfv.getHolder().getSurface());        try {            mediaRecorder.prepare();            mediaRecorder.start();        } catch (IOException e) {            e.printStackTrace();        }    }    public void stop(View view){        mediaRecorder.stop();    }}

activity_video2.xml

<?xml version="1.0" encoding="utf-8"?><RelativeLayout 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"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    android:orientation="vertical"    tools:context="com.example.videodisplay.Video2Activity">    <SurfaceView        android:layout_width="match_parent"        android:layout_height="match_parent"        android:id="@+id/sv_media_recoder_surface"        />    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        >        <Button            android:layout_width="0dp"            android:layout_height="wrap_content"            android:text="开始"            android:onClick="start"            android:layout_weight="1"            />        <Button            android:layout_width="0dp"            android:layout_height="wrap_content"            android:text="停止"            android:onClick="stop"            android:layout_weight="1"            />    LinearLayout>RelativeLayout>

权限:

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />    <uses-permission android:name="android.permission.RECORD_AUDIO" />    <uses-permission android:name="android.permission.CAMERA" />    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

更多相关文章

  1. Android(安卓)OpenGL之生成FloatBuffer
  2. 【Android】 dialog 设置maxHeight 最大高度
  3. Android(安卓)ImageSwithcher的使用
  4. android 设置progressbar的背景颜色
  5. Android(安卓)开发常用代码片段
  6. View的XML 属性大全(官方文档)
  7. Android全屏设置方法
  8. android让程序全屏显示
  9. Android(安卓)Dialog顶部显示+横向全屏+沉浸式效果

随机推荐

  1. Android中的IPC方式-Messenger --转载自肖
  2. 原创:Android的sqlite数据库需上传服务器,
  3. 用Fiddler查看 Android/iOS 网络请求
  4. Kotlin Android Studio 环境搭建
  5. Android(安卓)Mediarecorder录制的时候屏
  6. Android 退出应用程序的实现方法
  7. Android使用Kotlin初体验
  8. 【翻译】Android Support Library(一)
  9. Android Drawer(抽屜)的使用(二)常用的方法:
  10. A33 android4.4增加上层有线网络设置接口