关闭

Android开发短视频录制

标签: Android短视频短视频录制android短视频android短视频录制
3788人阅读 评论(31) 收藏 举报
分类:

使用方法:

参考demo使用简单,直接可以录制,可以设置录制时间长短。

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setContentView(com.taobao.taorecorder.R.layout.aliwx_sv_recorder_activity_recorder);

    this.mContext = this;

    try {
        this._quality = 0;
        //录制时间20秒,自由设置,建议设置15秒最佳
        this._maxDuration = 20000;

返回的参数有:

Intent intent1 = new Intent(YWRecordVideoActivity.this, EditVideoActivity.class);
//视频路径
intent1.putExtra("videoPath", targetVideoPath);
//图片路径
intent1.putExtra("framePicPath", targetJpgPath);
//录制时间
intent1.putExtra("videoDuration", stime);
//录制大小
intent1.putExtra("videoSize", size1);
startActivity(intent1);

具体效果:





差点忘记给6.0添加权限了


修改MAinActivity.java,添加动态申请权限


public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
                    Log.d("SDK_INT", Build.VERSION.SDK_INT + "+" + Build.VERSION_CODES.M);
                    Intent intent = new Intent(MainActivity.this, YWRecordVideoActivity.class);
                    startActivity(intent);
                } else {
                    if (!(checkSelfPermission(Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED)) {
                        if (shouldShowRequestPermissionRationale(Manifest.permission.CAMERA)) {

                        }
                        requestCameraPermission();
                    } else {
                        Intent intent = new Intent(MainActivity.this, YWRecordVideoActivity.class);
                        startActivity(intent);
                    }
                }
            }
        });
    }

    private static final int REQUEST_PERMISSION_CAMERA_CODE = 1;

    @TargetApi(Build.VERSION_CODES.M)
    private void requestCameraPermission() {
        requestPermissions(new String[]{Manifest.permission.CAMERA}, REQUEST_PERMISSION_CAMERA_CODE);
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (requestCode == REQUEST_PERMISSION_CAMERA_CODE) {
            int grantResult = grantResults[0];
            boolean granted = grantResult == PackageManager.PERMISSION_GRANTED;
        }
    }
}

最后有注意在你app的AndroidManifest.xml配置一下

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    tools:replace="android:label,android:icon,android:allowBackup,android:supportsRtl,android:theme">
>

application使用了多少属性,replace就设置多少个


最后,如果.so冲突

请在项目里的build.gradle里面加上

    buildTypes {
        debug {
            ndk {
                abiFilters "x86", "armeabi-v7a", "armeabi"
                //abiFilters ABI_FILTERS
            }
        }


        release {
            debuggable false
            ndk {
                abiFilters "x86", "armeabi-v7a", "armeabi"
                //abiFilters ABI_FILTERS
            }
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }




视频demo下载链接:

http://download.csdn.net/detail/longsh_/9616966


4
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:7600次
    • 积分:115
    • 等级:
    • 排名:千里之外
    • 原创:1篇
    • 转载:1篇
    • 译文:0篇
    • 评论:31条
    文章分类
    文章存档
    最新评论