Android picture video picture encapsulation, Android picture and video selection framework

1. Function introduction

MediaPicke, Android image/video picker, currently has the following functions:

Supports setting to select only pictures or videos, or both pictures and videos

Support setting the maximum number of selected pictures/videos

Support preview pictures/videos

Preload support

The effect diagram is as follows:

7714aeea3682

MediaPick renderings 1.png

7714aeea3682

MediaPick renderings 2.png

7714aeea3682

MediaPick renderings 3.png

2. Introduction of specific methods

1. Call up the picture/video selection interface

// select video only

MediaPicker.create(this)

.setMediaType(MediaPickConstants.MEDIA_TYPE_VIDEO) // Display video type

.forResult(REQUEST_CODE); // the requestCode of the callback

// select only images

MediaPicker.create(this)

.setMediaType(MediaPickConstants.MEDIA_TYPE_IMAGE) // Display image type

.forResult(REQUEST_CODE); // the requestCode of the callback

// select image and video at the same time

MediaPicker.create(this)

.setMediaType(MediaPickConstants.MEDIA_TYPE_IMAGE) // Display pictures and videos

.forResult(REQUEST_CODE); // the requestCode of the callback

2. Set the maximum number of selected pictures/videos (default is 9)

MediaPicker.create(this)

.setMediaType(MediaPickConstants.MEDIA_TYPE_IMAGE)

.setMaxPickNum(12) // Set the maximum number of choices

.forResult(REQUEST_CODE);

MediaPicker.create(this)

.setMediaType(MediaPickConstants.MEDIA_TYPE_IMAGE)

.setMaxPickNum(0) // Setting less than or equal to 0 means unlimited number

.forResult(REQUEST_CODE);

3. Preload

// Called before starting the image picker

MediaPicker.preload(this);

// Clear the cache on exit

MediaPicker.clearCache(this);

3. Follow-up content supplement

Add photo and video recording functions

Rely on third-party libraries as little as possible, remove the internal permission framework, and use Android native libraries instead

upload repository

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325673829&siteId=291194637