Java Code Examples for com.luck.picture.lib.config.PictureConfig#TYPE_VIDEO

The following examples show how to use com.luck.picture.lib.config.PictureConfig#TYPE_VIDEO . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PictureSelectorUtils.java    From DevUtils with Apache License 2.0 6 votes vote down vote up
/**
 * 获取本地资源路径
 * @param localMedia {@link LocalMedia}
 * @param original   是否使用原图地址
 * @return 本地资源路径
 */
public static String getLocalMediaPath(final LocalMedia localMedia, final boolean original) {
    if (localMedia != null) {
        if (original) return localMedia.getPath();
        // 判断资源类型
        switch (localMedia.getMimeType()) {
            case PictureConfig.TYPE_IMAGE: // 图片
                if (localMedia.isCompressed()) { // 是否压缩图片
                    return localMedia.getCompressPath();
                } else if (localMedia.isCut()) { // 是否裁减图片
                    return localMedia.getCutPath();
                } else { // 获取原图
                    return localMedia.getPath();
                }
            case PictureConfig.TYPE_VIDEO: // 视频
            case PictureConfig.TYPE_AUDIO: // 音频
                return localMedia.getPath();
        }
    }
    return null;
}
 
Example 2
Source File: PictureSelectorCameraEmptyActivity.java    From PictureSelector with Apache License 2.0 6 votes vote down vote up
/**
 * Open the Camera by type
 */
private void startCamera() {
    switch (config.chooseMode) {
        case PictureConfig.TYPE_ALL:
        case PictureConfig.TYPE_IMAGE:
            startOpenCamera();
            break;
        case PictureConfig.TYPE_VIDEO:
            startOpenCameraVideo();
            break;
        case PictureConfig.TYPE_AUDIO:
            startOpenCameraAudio();
            break;
        default:
            break;
    }
}
 
Example 3
Source File: MainActivity.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
@Override
        public void onCameraClick(Context context, PictureSelectionConfig config, int type) {
            // TODO  必须使用context.startActivityForResult(activity.class,PictureConfig.REQUEST_CAMERA);
            // TODO  为防止拍照内存不足导致Activity被回收的情况,最好把config类通过bundle.putParcelable(PictureConfig.EXTRA_CONFIG,config);传入到用户自定义相机页面,拍照成功后在.setResult()带回来
            // TODO 注意:使用自定义相机时,需要设置PictureSelectionConfig ${config.cameraPath#config.cameraMimeType}
            //  1、config.cameraPath (文件输出路径)
            //  2、config.cameraMimeType (PictureMimeType.ofImage() or ofVideo)

            switch (type) {
                case PictureConfig.TYPE_IMAGE:
                    // 拍照
//                    if (context instanceof Activity) {
//                        Intent intent = new Intent(context, PictureCustomCameraActivity.class);
//                        ((Activity) context).startActivityForResult(intent, PictureConfig.REQUEST_CAMERA);
//                        PictureWindowAnimationStyle windowAnimationStyle = config.windowAnimationStyle;
//                        ((Activity) context).overridePendingTransition(windowAnimationStyle != null &&
//                                windowAnimationStyle.activityEnterAnimation != 0 ?
//                                windowAnimationStyle.activityEnterAnimation : R.anim.picture_anim_enter, R.anim.picture_anim_fade_in);
//                    }
                    ToastUtils.s(context, "Click Camera Image");
                    break;
                case PictureConfig.TYPE_VIDEO:
                    // 录视频
                    ToastUtils.s(context, "Click Camera Video");
                    break;
                case PictureConfig.TYPE_AUDIO:
                    // 录音
                    ToastUtils.s(context, "Click Camera Recording");
                    break;
                default:
                    break;
            }
        }
 
Example 4
Source File: PictureSelectorCameraEmptyActivity.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (config == null) {
        closeActivity();
        return;
    }
    if (!config.isUseCustomCamera) {
        if (savedInstanceState == null) {
            if (PermissionChecker
                    .checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) &&
                    PermissionChecker
                            .checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {

                if (PictureSelectionConfig.onCustomCameraInterfaceListener != null) {
                    if (config.chooseMode == PictureConfig.TYPE_VIDEO) {
                        PictureSelectionConfig.onCustomCameraInterfaceListener.onCameraClick(getContext(), config, PictureConfig.TYPE_VIDEO);
                    } else {
                        PictureSelectionConfig.onCustomCameraInterfaceListener.onCameraClick(getContext(), config, PictureConfig.TYPE_IMAGE);
                    }
                } else {
                    onTakePhoto();
                }
            } else {
                PermissionChecker.requestPermissions(this, new String[]{
                        Manifest.permission.READ_EXTERNAL_STORAGE,
                        Manifest.permission.WRITE_EXTERNAL_STORAGE}, PictureConfig.APPLY_STORAGE_PERMISSIONS_CODE);
            }
        }
        setTheme(R.style.Picture_Theme_Translucent);
    }
}
 
Example 5
Source File: LocalMediaLoader.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
private String getSelection() {
    switch (config.chooseMode) {
        case PictureConfig.TYPE_ALL:
            // Get all, not including audio
            return getSelectionArgsForAllMediaCondition(getDurationCondition(0, 0), config.isGif);
        case PictureConfig.TYPE_IMAGE:
            if (!TextUtils.isEmpty(config.specifiedFormat)) {
                // Gets the image of the specified type
                return SELECTION_SPECIFIED_FORMAT + "='" + config.specifiedFormat + "'";
            }
            return config.isGif ? SELECTION : SELECTION_NOT_GIF;
        case PictureConfig.TYPE_VIDEO:
            // Access to video
            if (!TextUtils.isEmpty(config.specifiedFormat)) {
                // Gets the image of the specified type
                return SELECTION_SPECIFIED_FORMAT + "='" + config.specifiedFormat + "'";
            }
            return getSelectionArgsForSingleMediaCondition();
        case PictureConfig.TYPE_AUDIO:
            // Access to the audio
            if (!TextUtils.isEmpty(config.specifiedFormat)) {
                // Gets the image of the specified type
                return SELECTION_SPECIFIED_FORMAT + "='" + config.specifiedFormat + "'";
            }
            return getSelectionArgsForSingleMediaCondition(getDurationCondition(0, AUDIO_DURATION));
    }
    return null;
}
 
Example 6
Source File: LocalMediaLoader.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
private String[] getSelectionArgs() {
    switch (config.chooseMode) {
        case PictureConfig.TYPE_ALL:
            return SELECTION_ALL_ARGS;
        case PictureConfig.TYPE_IMAGE:
            // Get Image
            return getSelectionArgsForSingleMediaType(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE);
        case PictureConfig.TYPE_VIDEO:
            // Get Video
            return getSelectionArgsForSingleMediaType(MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO);
        case PictureConfig.TYPE_AUDIO:
            return getSelectionArgsForSingleMediaType(MediaStore.Files.FileColumns.MEDIA_TYPE_AUDIO);
    }
    return null;
}
 
Example 7
Source File: LocalMediaPageLoader.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
private String[] getPageSelectionArgs(long bucketId) {
    switch (config.chooseMode) {
        case PictureConfig.TYPE_ALL:
            if (bucketId == -1) {
                // ofAll
                return new String[]{
                        String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE),
                        String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO),
                };
            }
            //  Gets the specified album directory
            return new String[]{
                    String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE),
                    String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO),
                    ValueOf.toString(bucketId)
            };
        case PictureConfig.TYPE_IMAGE:
            // Get photo
            return getSelectionArgsForPageSingleMediaType(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE, bucketId);
        case PictureConfig.TYPE_VIDEO:
            // Get video
            return getSelectionArgsForPageSingleMediaType(MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO, bucketId);
        case PictureConfig.TYPE_AUDIO:
            // Get audio
            return getSelectionArgsForPageSingleMediaType(MediaStore.Files.FileColumns.MEDIA_TYPE_AUDIO, bucketId);
    }
    return null;
}
 
Example 8
Source File: LocalMediaPageLoader.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
private String getSelection() {
    switch (config.chooseMode) {
        case PictureConfig.TYPE_ALL:
            // Get all, not including audio
            return getSelectionArgsForAllMediaCondition(getDurationCondition(0, 0), config.isGif);
        case PictureConfig.TYPE_IMAGE:
            if (!TextUtils.isEmpty(config.specifiedFormat)) {
                // 获取指定类型的图片
                if (SdkVersionUtils.checkedAndroid_Q()) {
                    return SELECTION_SPECIFIED_FORMAT_29 + "='" + config.specifiedFormat + "' AND " + MediaStore.MediaColumns.SIZE + ">0";
                }
                return SELECTION_SPECIFIED_FORMAT + "='" + config.specifiedFormat + "') AND " + MediaStore.MediaColumns.SIZE + ">0)" + GROUP_BY_BUCKET_Id;
            }
            if (SdkVersionUtils.checkedAndroid_Q()) {
                return config.isGif ? SELECTION_29 : SELECTION_NOT_GIF_29;
            }
            return config.isGif ? SELECTION : SELECTION_NOT_GIF;
        case PictureConfig.TYPE_VIDEO:
            // 获取视频
            if (!TextUtils.isEmpty(config.specifiedFormat)) {
                // Gets the specified album directory
                if (SdkVersionUtils.checkedAndroid_Q()) {
                    return SELECTION_SPECIFIED_FORMAT_29 + "='" + config.specifiedFormat + "' AND " + MediaStore.MediaColumns.SIZE + ">0";
                }
                return SELECTION_SPECIFIED_FORMAT + "='" + config.specifiedFormat + "') AND " + MediaStore.MediaColumns.SIZE + ">0)" + GROUP_BY_BUCKET_Id;
            }
            return getSelectionArgsForSingleMediaCondition(getDurationCondition(0, 0));
        case PictureConfig.TYPE_AUDIO:
            // Get Audio
            if (!TextUtils.isEmpty(config.specifiedFormat)) {
                // Gets the specified album directory
                if (SdkVersionUtils.checkedAndroid_Q()) {
                    return SELECTION_SPECIFIED_FORMAT_29 + "='" + config.specifiedFormat + "' AND " + MediaStore.MediaColumns.SIZE + ">0";
                }
                return SELECTION_SPECIFIED_FORMAT + "='" + config.specifiedFormat + "') AND " + MediaStore.MediaColumns.SIZE + ">0)" + GROUP_BY_BUCKET_Id;
            }
            return getSelectionArgsForSingleMediaCondition(getDurationCondition(0, AUDIO_DURATION));
    }
    return null;
}
 
Example 9
Source File: LocalMediaPageLoader.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
private String[] getSelectionArgs() {
    switch (config.chooseMode) {
        case PictureConfig.TYPE_ALL:
            return SELECTION_ALL_ARGS;
        case PictureConfig.TYPE_IMAGE:
            // Get photo
            return getSelectionArgsForSingleMediaType(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE);
        case PictureConfig.TYPE_VIDEO:
            // Get video
            return getSelectionArgsForSingleMediaType(MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO);
        case PictureConfig.TYPE_AUDIO:
            return getSelectionArgsForSingleMediaType(MediaStore.Files.FileColumns.MEDIA_TYPE_AUDIO);
    }
    return null;
}
 
Example 10
Source File: PictureFileUtils.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
/**
 * 文件根目录
 *
 * @param context
 * @param type
 * @return
 */
@Nullable
private static File getRootDirFile(Context context, int type) {
    switch (type) {
        case PictureConfig.TYPE_VIDEO:
            return context.getExternalFilesDir(Environment.DIRECTORY_MOVIES);
        case PictureConfig.TYPE_AUDIO:
            return context.getExternalFilesDir(Environment.DIRECTORY_MUSIC);
        default:
            return context.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
    }
}
 
Example 11
Source File: PictureBaseActivity.java    From PictureSelector with Apache License 2.0 4 votes vote down vote up
/**
 * start to camera、video
 */
protected void startOpenCameraVideo() {
    Intent cameraIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    if (cameraIntent.resolveActivity(getPackageManager()) != null) {
        Uri videoUri;
        if (SdkVersionUtils.checkedAndroid_Q()) {
            videoUri = MediaUtils.createVideoUri(getApplicationContext(), config.suffixType);
            if (videoUri != null) {
                config.cameraPath = videoUri.toString();
            } else {
                ToastUtils.s(getContext(), "open is camera error,the uri is empty ");
                if (config.camera) {
                    closeActivity();
                }
                return;
            }
        } else {
            int chooseMode = config.chooseMode ==
                    PictureConfig.TYPE_ALL ? PictureConfig.TYPE_VIDEO : config.chooseMode;
            String cameraFileName = "";
            if (!TextUtils.isEmpty(config.cameraFileName)) {
                boolean isSuffixOfImage = PictureMimeType.isSuffixOfImage(config.cameraFileName);
                config.cameraFileName = isSuffixOfImage ? StringUtils.renameSuffix(config.cameraFileName, PictureMimeType.MP4) : config.cameraFileName;
                cameraFileName = config.camera ? config.cameraFileName : StringUtils.rename(config.cameraFileName);
            }
            File cameraFile = PictureFileUtils.createCameraFile(getApplicationContext(),
                    chooseMode, cameraFileName, config.suffixType, config.outPutCameraPath);
            if (cameraFile != null) {
                config.cameraPath = cameraFile.getAbsolutePath();
                videoUri = PictureFileUtils.parUri(this, cameraFile);
            } else {
                ToastUtils.s(getContext(), "open is camera error,the uri is empty ");
                if (config.camera) {
                    closeActivity();
                }
                return;
            }
        }
        config.cameraMimeType = PictureMimeType.ofVideo();
        cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, videoUri);
        if (config.isCameraAroundState) {
            cameraIntent.putExtra(PictureConfig.CAMERA_FACING, PictureConfig.CAMERA_BEFORE);
        }
        cameraIntent.putExtra(PictureConfig.EXTRA_QUICK_CAPTURE, config.isQuickCapture);
        cameraIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, config.recordVideoSecond);
        cameraIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, config.videoQuality);
        startActivityForResult(cameraIntent, PictureConfig.REQUEST_CAMERA);
    }
}
 
Example 12
Source File: LocalMediaPageLoader.java    From PictureSelector with Apache License 2.0 4 votes vote down vote up
private String getPageSelection(long bucketId) {
    String durationCondition = getDurationCondition(0, 0);
    boolean isSpecifiedFormat = !TextUtils.isEmpty(config.specifiedFormat);
    switch (config.chooseMode) {
        case PictureConfig.TYPE_ALL:
            if (bucketId == -1) {
                // ofAll
                return "(" + MediaStore.Files.FileColumns.MEDIA_TYPE + "=?"
                        + (config.isGif ? "" : " AND " + MediaStore.MediaColumns.MIME_TYPE + NOT_GIF)
                        + " OR " + MediaStore.Files.FileColumns.MEDIA_TYPE + "=? AND " + durationCondition + ") AND " + MediaStore.MediaColumns.SIZE + ">0";
            }
            // Gets the specified album directory
            return "(" + MediaStore.Files.FileColumns.MEDIA_TYPE + "=?"
                    + (config.isGif ? "" : " AND " + MediaStore.MediaColumns.MIME_TYPE + NOT_GIF)
                    + " OR " + MediaStore.Files.FileColumns.MEDIA_TYPE + "=? AND " + durationCondition + ") AND " + COLUMN_BUCKET_ID + "=? AND " + MediaStore.MediaColumns.SIZE + ">0";

        case PictureConfig.TYPE_IMAGE:
            // Gets the image of the specified type
            if (bucketId == -1) {
                // ofAll
                if (isSpecifiedFormat) {
                    return "(" + MediaStore.Files.FileColumns.MEDIA_TYPE + "=?"
                            + (config.isGif ? "" : " AND " + MediaStore.MediaColumns.MIME_TYPE + NOT_GIF + " AND " + MediaStore.MediaColumns.MIME_TYPE + "='" + config.specifiedFormat + "'")
                            + ") AND " + MediaStore.MediaColumns.SIZE + ">0";
                }
                return "(" + MediaStore.Files.FileColumns.MEDIA_TYPE + "=?"
                        + (config.isGif ? "" : " AND " + MediaStore.MediaColumns.MIME_TYPE + NOT_GIF)
                        + ") AND " + MediaStore.MediaColumns.SIZE + ">0";
            }
            // Gets the specified album directory
            if (isSpecifiedFormat) {
                return "(" + MediaStore.Files.FileColumns.MEDIA_TYPE + "=?"
                        + (config.isGif ? "" : " AND " + MediaStore.MediaColumns.MIME_TYPE + NOT_GIF + " AND " + MediaStore.MediaColumns.MIME_TYPE + "='" + config.specifiedFormat + "'")
                        + ") AND " + COLUMN_BUCKET_ID + "=? AND " + MediaStore.MediaColumns.SIZE + ">0";
            }
            return "(" + MediaStore.Files.FileColumns.MEDIA_TYPE + "=?"
                    + (config.isGif ? "" : " AND " + MediaStore.MediaColumns.MIME_TYPE + NOT_GIF)
                    + ") AND " + COLUMN_BUCKET_ID + "=? AND " + MediaStore.MediaColumns.SIZE + ">0";
        case PictureConfig.TYPE_VIDEO:
        case PictureConfig.TYPE_AUDIO:
            if (bucketId == -1) {
                // ofAll
                if (isSpecifiedFormat) {
                    return "(" + MediaStore.Files.FileColumns.MEDIA_TYPE + "=? AND " + MediaStore.MediaColumns.MIME_TYPE + "='" + config.specifiedFormat + "'" + " AND " + durationCondition + ") AND " + MediaStore.MediaColumns.SIZE + ">0";
                }
                return "(" + MediaStore.Files.FileColumns.MEDIA_TYPE + "=? AND " + durationCondition + ") AND " + MediaStore.MediaColumns.SIZE + ">0";
            }
            // Gets the specified album directory
            if (isSpecifiedFormat) {
                return "(" + MediaStore.Files.FileColumns.MEDIA_TYPE + "=? AND " + MediaStore.MediaColumns.MIME_TYPE + "='" + config.specifiedFormat + "'" + " AND " + durationCondition + ") AND " + COLUMN_BUCKET_ID + "=? AND " + MediaStore.MediaColumns.SIZE + ">0";
            }
            return "(" + MediaStore.Files.FileColumns.MEDIA_TYPE + "=? AND " + durationCondition + ") AND " + COLUMN_BUCKET_ID + "=? AND " + MediaStore.MediaColumns.SIZE + ">0";
    }
    return null;
}