Java Code Examples for com.luck.picture.lib.config.PictureMimeType#isHasVideo()

The following examples show how to use com.luck.picture.lib.config.PictureMimeType#isHasVideo() . 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: PictureSelectorActivity.java    From PictureSelector with Apache License 2.0 6 votes vote down vote up
/**
 * Verify the validity of the video
 *
 * @param media
 * @return
 */
private boolean checkVideoLegitimacy(LocalMedia media) {
    boolean isEnterNext = true;
    if (PictureMimeType.isHasVideo(media.getMimeType())) {
        if (config.videoMinSecond > 0 && config.videoMaxSecond > 0) {
            // The user sets the minimum and maximum video length to determine whether the video is within the interval
            if (media.getDuration() < config.videoMinSecond || media.getDuration() > config.videoMaxSecond) {
                isEnterNext = false;
                showPromptDialog(getString(R.string.picture_choose_limit_seconds, config.videoMinSecond / 1000, config.videoMaxSecond / 1000));
            }
        } else if (config.videoMinSecond > 0) {
            // The user has only set a minimum video length limit
            if (media.getDuration() < config.videoMinSecond) {
                isEnterNext = false;
                showPromptDialog(getString(R.string.picture_choose_min_seconds, config.videoMinSecond / 1000));
            }
        } else if (config.videoMaxSecond > 0) {
            // Only the maximum length of video is set
            if (media.getDuration() > config.videoMaxSecond) {
                isEnterNext = false;
                showPromptDialog(getString(R.string.picture_choose_max_seconds, config.videoMaxSecond / 1000));
            }
        }
    }
    return isEnterNext;
}
 
Example 2
Source File: Luban.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
private List<File> get(Context context) throws IOException {
    List<File> results = new ArrayList<>();
    Iterator<InputStreamProvider> iterator = mStreamProviders.iterator();

    while (iterator.hasNext()) {
        InputStreamProvider provider = iterator.next();
        InputStream inputStream = provider.open();
        if (inputStream != null) {
            if (provider.getMedia().isCompressed()
                    && !TextUtils.isEmpty(provider.getMedia().getCompressPath())) {
                // 压缩过的图片不重复压缩  注意:如果是开启了裁剪 就算压缩过也要重新压缩
                boolean exists = !provider.getMedia().isCut() && new File(provider.getMedia().getCompressPath()).exists();
                File oldFile = exists ? new File(provider.getMedia().getCompressPath())
                        : compress(context, provider);
                results.add(oldFile);
            } else {
                boolean hasVideo = PictureMimeType.isHasVideo(provider.getMedia().getMimeType());
                results.add(hasVideo ? new File(provider.getMedia().getPath()) : compress(context, provider));
            }
        } else {
            // error
            results.add(new File(provider.getMedia().getPath()));
        }
        iterator.remove();
    }

    return results;
}
 
Example 3
Source File: PictureBaseActivity.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
/**
 * handleCompressCallBack
 *
 * @param images
 * @param files
 */
private void handleCompressCallBack(List<LocalMedia> images, List<File> files) {
    if (images == null || files == null) {
        closeActivity();
        return;
    }
    boolean isAndroidQ = SdkVersionUtils.checkedAndroid_Q();
    int size = images.size();
    if (files.size() == size) {
        for (int i = 0, j = size; i < j; i++) {
            File file = files.get(i);
            if (file == null) {
                continue;
            }
            String path = file.getAbsolutePath();
            LocalMedia image = images.get(i);
            boolean http = PictureMimeType.isHasHttp(path);
            boolean flag = !TextUtils.isEmpty(path) && http;
            boolean isHasVideo = PictureMimeType.isHasVideo(image.getMimeType());
            image.setCompressed(!isHasVideo && !flag);
            image.setCompressPath(isHasVideo || flag ? null : path);
            if (isAndroidQ) {
                image.setAndroidQToPath(image.getCompressPath());
            }
        }
    }
    onResult(images);
}
 
Example 4
Source File: MediaUtils.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
/**
 * 设置LocalMedia旋转信息
 *
 * @param context
 * @param media
 * @param isAndroidQChangeWH
 * @return
 */
public static void setOrientationSynchronous(Context context, LocalMedia media,
                                             boolean isAndroidQChangeWH,
                                             boolean isAndroidQChangeVideoWH) {
    if (PictureMimeType.isHasImage(media.getMimeType())) {
        if (!isAndroidQChangeWH) {
            return;
        }
    }
    if (PictureMimeType.isHasVideo(media.getMimeType())) {
        if (!isAndroidQChangeVideoWH) {
            return;
        }
    }
    // 如果有旋转信息图片宽高则是相反
    int orientation = 0;
    if (PictureMimeType.isHasImage(media.getMimeType())) {
        orientation = MediaUtils.getImageOrientationForUrl(context, media.getPath());
    } else if (PictureMimeType.isHasVideo(media.getMimeType())) {
        if (PictureMimeType.isContent(media.getPath())) {
            orientation = MediaUtils.getVideoOrientationForUri(context, Uri.parse(media.getPath()));
        } else {
            orientation = MediaUtils.getVideoOrientationForUrl(media.getPath());
        }
    }
    if (orientation == ExifInterface.ORIENTATION_ROTATE_90
            || orientation == ExifInterface.ORIENTATION_ROTATE_270) {
        int width = media.getWidth();
        int height = media.getHeight();
        media.setWidth(height);
        media.setHeight(width);
    }
    media.setOrientation(orientation);
}
 
Example 5
Source File: StringUtils.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
/**
 * 根据类型获取相应的Toast文案
 *
 * @param context
 * @param mimeType
 * @param maxSelectNum
 * @return
 */
@SuppressLint("StringFormatMatches")
public static String getMsg(Context context, String mimeType, int maxSelectNum) {
    if (PictureMimeType.isHasVideo(mimeType)) {
        return context.getString(R.string.picture_message_video_max_num, maxSelectNum);
    } else if (PictureMimeType.isHasAudio(mimeType)) {
        return context.getString(R.string.picture_message_audio_max_num, maxSelectNum);
    } else {
        return context.getString(R.string.picture_message_max_num, maxSelectNum);
    }
}
 
Example 6
Source File: PictureSimpleFragmentAdapter.java    From PictureSelector with Apache License 2.0 4 votes vote down vote up
@NotNull
@Override
public Object instantiateItem(@NotNull ViewGroup container, int position) {
    View contentView = mCacheView.get(position);
    if (contentView == null) {
        contentView = LayoutInflater.from(container.getContext())
                .inflate(R.layout.picture_image_preview, container, false);
        mCacheView.put(position, contentView);
    }
    PhotoView imageView = contentView.findViewById(R.id.preview_image);
    SubsamplingScaleImageView longImg = contentView.findViewById(R.id.longImg);
    ImageView ivPlay = contentView.findViewById(R.id.iv_play);
    LocalMedia media = getItem(position);
    if (media != null) {
        final String mimeType = media.getMimeType();
        final String path;
        if (media.isCut() && !media.isCompressed()) {
            path = media.getCutPath();
        } else if (media.isCompressed() || (media.isCut() && media.isCompressed())) {
            path = media.getCompressPath();
        } else {
            path = media.getPath();
        }
        boolean isGif = PictureMimeType.isGif(mimeType);
        boolean isHasVideo = PictureMimeType.isHasVideo(mimeType);
        ivPlay.setVisibility(isHasVideo ? View.VISIBLE : View.GONE);
        ivPlay.setOnClickListener(v -> {
            if (PictureSelectionConfig.customVideoPlayCallback != null) {
                PictureSelectionConfig.customVideoPlayCallback.startPlayVideo(media);
            } else {
                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                bundle.putBoolean(PictureConfig.EXTRA_PREVIEW_VIDEO, true);
                bundle.putString(PictureConfig.EXTRA_VIDEO_PATH, path);
                intent.putExtras(bundle);
                JumpUtils.startPictureVideoPlayActivity(container.getContext(), bundle, PictureConfig.PREVIEW_VIDEO_CODE);
            }
        });
        boolean eqLongImg = MediaUtils.isLongImg(media);
        imageView.setVisibility(eqLongImg && !isGif ? View.GONE : View.VISIBLE);
        imageView.setOnViewTapListener((view, x, y) -> {
            if (onBackPressed != null) {
                onBackPressed.onActivityBackPressed();
            }
        });
        longImg.setVisibility(eqLongImg && !isGif ? View.VISIBLE : View.GONE);
        longImg.setOnClickListener(v -> {
            if (onBackPressed != null) {
                onBackPressed.onActivityBackPressed();
            }
        });

        if (isGif && !media.isCompressed()) {
            if (config != null && PictureSelectionConfig.imageEngine != null) {
                PictureSelectionConfig.imageEngine.loadAsGifImage
                        (contentView.getContext(), path, imageView);
            }
        } else {
            if (config != null && PictureSelectionConfig.imageEngine != null) {
                if (eqLongImg) {
                    displayLongPic(PictureMimeType.isContent(path)
                            ? Uri.parse(path) : Uri.fromFile(new File(path)), longImg);
                } else {
                    PictureSelectionConfig.imageEngine.loadImage
                            (contentView.getContext(), path, imageView);
                }
            }
        }
    }

    (container).addView(contentView, 0);
    return contentView;
}
 
Example 7
Source File: PictureSelectorActivity.java    From PictureSelector with Apache License 2.0 4 votes vote down vote up
/**
 * preview image and video
 *
 * @param previewData
 * @param position
 */
public void startPreview(List<LocalMedia> previewData, int position) {
    LocalMedia media = previewData.get(position);
    String mimeType = media.getMimeType();
    Bundle bundle = new Bundle();
    List<LocalMedia> result = new ArrayList<>();
    if (PictureMimeType.isHasVideo(mimeType)) {
        // video
        if (config.selectionMode == PictureConfig.SINGLE && !config.enPreviewVideo) {
            result.add(media);
            onResult(result);
        } else {
            if (PictureSelectionConfig.customVideoPlayCallback != null) {
                PictureSelectionConfig.customVideoPlayCallback.startPlayVideo(media);
            } else {
                bundle.putParcelable(PictureConfig.EXTRA_MEDIA_KEY, media);
                JumpUtils.startPictureVideoPlayActivity(getContext(), bundle, PictureConfig.PREVIEW_VIDEO_CODE);
            }
        }
    } else if (PictureMimeType.isHasAudio(mimeType)) {
        // audio
        if (config.selectionMode == PictureConfig.SINGLE) {
            result.add(media);
            onResult(result);
        } else {
            AudioDialog(media.getPath());
        }
    } else {
        // image
        if (PictureSelectionConfig.onCustomImagePreviewCallback != null) {
            PictureSelectionConfig.onCustomImagePreviewCallback.onCustomPreviewCallback(getContext(), previewData, position);
            return;
        }
        List<LocalMedia> selectedData = mAdapter.getSelectedData();
        ImagesObservable.getInstance().savePreviewMediaData(new ArrayList<>(previewData));
        bundle.putParcelableArrayList(PictureConfig.EXTRA_SELECT_LIST, (ArrayList<? extends Parcelable>) selectedData);
        bundle.putInt(PictureConfig.EXTRA_POSITION, position);
        bundle.putBoolean(PictureConfig.EXTRA_CHANGE_ORIGINAL, config.isCheckOriginalImage);
        bundle.putBoolean(PictureConfig.EXTRA_SHOW_CAMERA, mAdapter.isShowCamera());
        bundle.putLong(PictureConfig.EXTRA_BUCKET_ID, ValueOf.toLong(mTvPictureTitle.getTag(R.id.view_tag)));
        bundle.putInt(PictureConfig.EXTRA_PAGE, mPage);
        bundle.putParcelable(PictureConfig.EXTRA_CONFIG, config);
        bundle.putInt(PictureConfig.EXTRA_DATA_COUNT, ValueOf.toInt(mTvPictureTitle.getTag(R.id.view_count_tag)));
        bundle.putString(PictureConfig.EXTRA_IS_CURRENT_DIRECTORY, mTvPictureTitle.getText().toString());
        JumpUtils.startPicturePreviewActivity(getContext(), config.isWeChatStyle, bundle,
                config.selectionMode == PictureConfig.SINGLE ? UCrop.REQUEST_CROP : UCrop.REQUEST_MULTI_CROP);
        overridePendingTransition(config.windowAnimationStyle != null
                && config.windowAnimationStyle.activityPreviewEnterAnimation != 0
                ? config.windowAnimationStyle.activityPreviewEnterAnimation : R.anim.picture_anim_enter, R.anim.picture_anim_fade_in);
    }
}
 
Example 8
Source File: PictureSelectorActivity.java    From PictureSelector with Apache License 2.0 4 votes vote down vote up
/**
 * After using Camera, MultiSelect mode handles the logic
 *
 * @param media
 */
private void dispatchHandleMultiple(LocalMedia media) {
    List<LocalMedia> selectedData = mAdapter.getSelectedData();
    int count = selectedData.size();
    String oldMimeType = count > 0 ? selectedData.get(0).getMimeType() : "";
    boolean mimeTypeSame = PictureMimeType.isMimeTypeSame(oldMimeType, media.getMimeType());
    if (config.isWithVideoImage) {
        int videoSize = 0;
        for (int i = 0; i < count; i++) {
            LocalMedia item = selectedData.get(i);
            if (PictureMimeType.isHasVideo(item.getMimeType())) {
                videoSize++;
            }
        }
        if (PictureMimeType.isHasVideo(media.getMimeType())) {
            if (config.maxVideoSelectNum <= 0) {
                showPromptDialog(getString(R.string.picture_rule));
            } else {
                if (selectedData.size() >= config.maxSelectNum) {
                    showPromptDialog(getString(R.string.picture_message_max_num, config.maxSelectNum));
                } else {
                    if (videoSize < config.maxVideoSelectNum) {
                        selectedData.add(0, media);
                        mAdapter.bindSelectData(selectedData);
                    } else {
                        showPromptDialog(StringUtils.getMsg(getContext(), media.getMimeType(),
                                config.maxVideoSelectNum));
                    }
                }
            }
        } else {
            if (selectedData.size() < config.maxSelectNum) {
                selectedData.add(0, media);
                mAdapter.bindSelectData(selectedData);
            } else {
                showPromptDialog(StringUtils.getMsg(getContext(), media.getMimeType(),
                        config.maxSelectNum));
            }
        }

    } else {
        if (PictureMimeType.isHasVideo(oldMimeType) && config.maxVideoSelectNum > 0) {
            if (count < config.maxVideoSelectNum) {
                if (mimeTypeSame || count == 0) {
                    if (selectedData.size() < config.maxVideoSelectNum) {
                        selectedData.add(0, media);
                        mAdapter.bindSelectData(selectedData);
                    }
                }
            } else {
                showPromptDialog(StringUtils.getMsg(getContext(), oldMimeType,
                        config.maxVideoSelectNum));
            }
        } else {
            if (count < config.maxSelectNum) {
                if (mimeTypeSame || count == 0) {
                    selectedData.add(0, media);
                    mAdapter.bindSelectData(selectedData);
                }
            } else {
                showPromptDialog(StringUtils.getMsg(getContext(), oldMimeType,
                        config.maxSelectNum));
            }
        }
    }
}