android4.2錄制視頻的關鍵代碼

權限:

<manifest … >
    <uses-feature android:name="android.hardware.camera" />
    …
</manifest … >

錄像:

private void dispatchTakeVideoIntent() {
    Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    startActivityForResult(takeVideoIntent, ACTION_TAKE_VIDEO);
}

檢查能否對視頻進行處理:

public static boolean isIntentAvailable(Context context, String action) {
    final PackageManager packageManager = context.getPackageManager();
    final Intent intent = new Intent(action);
    List<ResolveInfo> list =
        packageManager.queryIntentActivities(intent,
            PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
}

播放視頻:

private void handleCameraVideo(Intent intent) {
    mVideoUri = intent.getData();
    mVideoView.setVideoURI(mVideoUri);
}

 

 

 

You May Also Like