Java Code Examples for com.luck.picture.lib.entity.LocalMedia#getPath()

The following examples show how to use com.luck.picture.lib.entity.LocalMedia#getPath() . 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: RNSyanImagePickerModule.java    From react-native-syan-image-picker with MIT License 5 votes vote down vote up
private void onGetVideoResult(Intent data) {
    List<LocalMedia> mVideoSelectList = PictureSelector.obtainMultipleResult(data);
    boolean isRecordSelected = cameraOptions.getBoolean("isRecordSelected");
    if (!mVideoSelectList.isEmpty() && isRecordSelected) {
        selectList = mVideoSelectList;
    }
    WritableArray videoList = new WritableNativeArray();

    for (LocalMedia media : mVideoSelectList) {
        if (TextUtils.isEmpty(media.getPath())) {
            continue;
        }

        WritableMap videoMap = new WritableNativeMap();

        Boolean isAndroidQ = SdkVersionUtils.checkedAndroid_Q();
        String filePath = isAndroidQ ? media.getAndroidQToPath() : media.getPath();

        videoMap.putString("uri", "file://" + filePath);
        videoMap.putString("coverUri", "file://" + this.getVideoCover(filePath));
        videoMap.putString("fileName", new File(media.getPath()).getName());
        videoMap.putDouble("size", new File(media.getPath()).length());
        videoMap.putDouble("duration", media.getDuration() / 1000.00);
        videoMap.putInt("width", media.getWidth());
        videoMap.putInt("height", media.getHeight());
        videoMap.putString("type", "video");
        videoMap.putString("mime", media.getMimeType());
        videoList.pushMap(videoMap);
    }

    invokeSuccessWithResult(videoList);
}
 
Example 3
Source File: RNSyanImagePickerModule.java    From react-native-syan-image-picker with MIT License 5 votes vote down vote up
private WritableMap getImageResult(LocalMedia media, Boolean enableBase64) {
    WritableMap imageMap = new WritableNativeMap();
    String path = media.getPath();

    if (media.isCompressed() || media.isCut()) {
        path = media.getCompressPath();
    }

    if (media.isCut()) {
        path = media.getCutPath();
    }

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(path, options);
    imageMap.putDouble("width", options.outWidth);
    imageMap.putDouble("height", options.outHeight);
    imageMap.putString("type", "image");
    imageMap.putString("uri", "file://" + path);
    imageMap.putString("original_uri", "file://" + media.getPath());
    imageMap.putInt("size", (int) new File(path).length());

    if (enableBase64) {
        String encodeString = getBase64StringFromFile(path);
        imageMap.putString("base64", encodeString);
    }

    return imageMap;
}
 
Example 4
Source File: PictureVideoPlayActivity.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
@Override
protected void initWidgets() {
    super.initWidgets();
    videoPath = getIntent().getStringExtra(PictureConfig.EXTRA_VIDEO_PATH);
    boolean isExternalPreview = getIntent().getBooleanExtra
            (PictureConfig.EXTRA_PREVIEW_VIDEO, false);
    if (TextUtils.isEmpty(videoPath)) {
        LocalMedia media = getIntent().getParcelableExtra(PictureConfig.EXTRA_MEDIA_KEY);
        if (media == null || TextUtils.isEmpty(media.getPath())) {
            finish();
            return;
        }
        videoPath = media.getPath();
    }
    if (TextUtils.isEmpty(videoPath)) {
        closeActivity();
        return;
    }
    ibLeftBack = findViewById(R.id.pictureLeftBack);
    mVideoView = findViewById(R.id.video_view);
    tvConfirm = findViewById(R.id.tv_confirm);
    mVideoView.setBackgroundColor(Color.BLACK);
    iv_play = findViewById(R.id.iv_play);
    mMediaController = new MediaController(this);
    mVideoView.setOnCompletionListener(this);
    mVideoView.setOnPreparedListener(this);
    mVideoView.setMediaController(mMediaController);
    ibLeftBack.setOnClickListener(this);
    iv_play.setOnClickListener(this);
    tvConfirm.setOnClickListener(this);

    tvConfirm.setVisibility(config.selectionMode
            == PictureConfig.SINGLE
            && config.enPreviewVideo && !isExternalPreview ? View.VISIBLE : View.GONE);
}
 
Example 5
Source File: PictureSelectorActivity.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
/**
 * Same type of image or video processing logic
 *
 * @param isHasImage
 * @param images
 */
private void separateMimeTypeWith(boolean isHasImage, List<LocalMedia> images) {
    LocalMedia image = images.size() > 0 ? images.get(0) : null;
    if (image == null) {
        return;
    }
    if (config.enableCrop && isHasImage) {
        if (config.selectionMode == PictureConfig.SINGLE) {
            config.originalPath = image.getPath();
            startCrop(config.originalPath, image.getMimeType());
        } else {
            ArrayList<CutInfo> cuts = new ArrayList<>();
            int count = images.size();
            for (int i = 0; i < count; i++) {
                LocalMedia media = images.get(i);
                if (media == null
                        || TextUtils.isEmpty(media.getPath())) {
                    continue;
                }
                CutInfo cutInfo = new CutInfo();
                cutInfo.setId(media.getId());
                cutInfo.setPath(media.getPath());
                cutInfo.setImageWidth(media.getWidth());
                cutInfo.setImageHeight(media.getHeight());
                cutInfo.setMimeType(media.getMimeType());
                cutInfo.setDuration(media.getDuration());
                cutInfo.setRealPath(media.getRealPath());
                cuts.add(cutInfo);
            }
            startCrop(cuts);
        }
    } else if (config.isCompress
            && isHasImage) {
        compressImage(images);
    } else {
        onResult(images);
    }
}
 
Example 6
Source File: PicturePreviewActivity.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
/**
 * 同一类型的图片或视频处理逻辑
 *
 * @param mimeType
 * @param image
 */
private void separateMimeTypeWith(String mimeType, LocalMedia image) {
    if (config.enableCrop && PictureMimeType.isHasImage(mimeType)) {
        isCompleteOrSelected = false;
        if (config.selectionMode == PictureConfig.SINGLE) {
            config.originalPath = image.getPath();
            startCrop(config.originalPath, image.getMimeType());
        } else {
            // 是图片和选择压缩并且是多张,调用批量压缩
            ArrayList<CutInfo> cuts = new ArrayList<>();
            int count = selectData.size();
            for (int i = 0; i < count; i++) {
                LocalMedia media = selectData.get(i);
                if (media == null
                        || TextUtils.isEmpty(media.getPath())) {
                    continue;
                }
                CutInfo cutInfo = new CutInfo();
                cutInfo.setId(media.getId());
                cutInfo.setPath(media.getPath());
                cutInfo.setImageWidth(media.getWidth());
                cutInfo.setImageHeight(media.getHeight());
                cutInfo.setMimeType(media.getMimeType());
                cutInfo.setAndroidQToPath(media.getAndroidQToPath());
                cutInfo.setId(media.getId());
                cutInfo.setDuration(media.getDuration());
                cutInfo.setRealPath(media.getRealPath());
                cuts.add(cutInfo);
            }
            startCrop(cuts);
        }
    } else {
        onBackPressed();
    }
}
 
Example 7
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 8
Source File: PicturePreviewActivity.java    From PictureSelector with Apache License 2.0 4 votes vote down vote up
/**
 * 两者不同类型的处理方式
 *
 * @param mimeType
 * @param image
 */
private void bothMimeTypeWith(String mimeType, LocalMedia image) {
    if (config.enableCrop) {
        isCompleteOrSelected = false;
        boolean isHasImage = PictureMimeType.isHasImage(mimeType);
        if (config.selectionMode == PictureConfig.SINGLE && isHasImage) {
            config.originalPath = image.getPath();
            startCrop(config.originalPath, image.getMimeType());
        } else {
            // 是图片和选择压缩并且是多张,调用批量压缩
            ArrayList<CutInfo> cuts = new ArrayList<>();
            int count = selectData.size();
            int imageNum = 0;
            for (int i = 0; i < count; i++) {
                LocalMedia media = selectData.get(i);
                if (media == null
                        || TextUtils.isEmpty(media.getPath())) {
                    continue;
                }
                if (PictureMimeType.isHasImage(media.getMimeType())) {
                    imageNum++;
                }
                CutInfo cutInfo = new CutInfo();
                cutInfo.setId(media.getId());
                cutInfo.setPath(media.getPath());
                cutInfo.setImageWidth(media.getWidth());
                cutInfo.setImageHeight(media.getHeight());
                cutInfo.setMimeType(media.getMimeType());
                cutInfo.setAndroidQToPath(media.getAndroidQToPath());
                cutInfo.setId(media.getId());
                cutInfo.setDuration(media.getDuration());
                cutInfo.setRealPath(media.getRealPath());
                cuts.add(cutInfo);
            }
            if (imageNum <= 0) {
                // 全是视频
                isCompleteOrSelected = true;
                onBackPressed();
            } else {
                // 图片和视频共存
                startCrop(cuts);
            }
        }
    } else {
        onBackPressed();
    }
}