Matisse: How to check if file is a video or image

Created on 27 Jun 2018  ·  1Comment  ·  Source: zhihu/Matisse

Matisse.obtainResult() and Matisse.obtainPathResult() returns list of path and URI . So how can i check whether the path contains an image of a video . In case of Video i need to load the thumbnail from video and also play it . I am using code below .

Matisse.from(this) .choose(MimeType.of(MimeType.JPEG,MimeType.PNG,MimeType.MP4,MimeType.MPEG),false) .countable(true) .maxSelectable(10) .showSingleMediaType(false) .restrictOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) .thumbnailScale(0.85f) .imageEngine(new PicassoEngine()) .forResult(5);

Please let me know Is there a way with Matisse to get this type of result ? I am stuck here for 5 days now. Is it possible with Matisse or not ?

Most helpful comment

MimeType.java#checkType(ContentResolver resolver, Uri uri)

List<Uri> mSelected;

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_CODE_CHOOSE && resultCode == RESULT_OK) {
        mSelected = Matisse.obtainResult(data);
        Log.d("Matisse", "mSelected: " + mSelected);

        // 
        String type = "image";
        for (MimeType mt : MimeType.ofVideo()) {
            if (mt.checkType(resolver, mSelected.get(0))) {
                type = "video";
                break;
            }
        }
    }
}

>All comments

MimeType.java#checkType(ContentResolver resolver, Uri uri)

List<Uri> mSelected;

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_CODE_CHOOSE && resultCode == RESULT_OK) {
        mSelected = Matisse.obtainResult(data);
        Log.d("Matisse", "mSelected: " + mSelected);

        // 
        String type = "image";
        for (MimeType mt : MimeType.ofVideo()) {
            if (mt.checkType(resolver, mSelected.get(0))) {
                type = "video";
                break;
            }
        }
    }
}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hugoFather picture hugoFather  ·  5Comments

Alastor111 picture Alastor111  ·  6Comments

zzzhoukang picture zzzhoukang  ·  5Comments

lianmingran picture lianmingran  ·  6Comments

Vector-SMG picture Vector-SMG  ·  3Comments