- You must declare the permission in your manifest
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
- If you haven't included the dependencies from the previous screen now's a good time
dependencies {
def pickerVersion = "1.0.0" //look-up the latest one on jitpack
//the core package is a must
implementation "com.github.FunkyMuse.MediaPicker:core:$pickerVersion"
//videos
implementation "com.github.FunkyMuse.MediaPicker:videopicker:$pickerVersion"
}
- How to use single picker and check out how to customize single video picker
import java.awt.Color
//simple usage without customization
SingleVideoPicker.showPicker(context = this, onPickedVideo = ::loadVideo)
//customized
SingleVideoPicker.showPicker(this, extensions = arrayOf(),config = Config(showFileSize = true),{
setupBaseModifier(
loadingIndicatorColor = R.color.minusColor,
titleTextModifications = {
textAlignment = TextView.TEXT_ALIGNMENT_VIEW_START
textStyle = TitleTextModifier.TextStyle.ITALIC
textColor = Color.BLACK
marginBottom = 30 // use dp or sp this is only for demonstration purposes
textPadding = 5 // use dp or sp this is only for demonstration purposes
textSize = 30f // use sp this is only for demonstration purposes
textString = "Pick a video"
},
placeHolderModifications = {
resID = R.drawable.ic_image
}
)
}, ::loadVideo)
// You can filter files by passing extensions like extensions = arrayOf("mp4","avi")
- How to use multi picker and check out how to customize multi video picker
//simple usage without customization
MultiVideoPicker.showPicker(this) { loadVideos(it) }
//customized
MultiVideoPicker.showPicker(this, extensions = arrayOf(),config = Config(showFileSize = false),{
setupBaseMultiPicker(
tintForLoadingProgressBar = ContextCompat.getColor(this@MainActivity, R.color.colorPrimaryDark),
gravityForSelectAndUnSelectIndicators = BaseMultiPickerModifier.Gravity.TOP_RIGHT,
titleModifications = {
textAlignment = TextView.TEXT_ALIGNMENT_CENTER
textStyle = TitleTextModifier.TextStyle.ITALIC
textColor = Color.BLACK
marginBottom = 30 // use dp or sp this is only for demonstration purposes
textPadding = 5 // use dp or sp this is only for demonstration purposes
textSize = 30f // use sp this is only for demonstration purposes
textString = "Pick multiple videos"
},
selectIconModifications = {
resID = R.drawable.ic_checked
tint = Color.BLACK
},
unSelectIconModifications = {
resID = R.drawable.ic_unchecked
tint = Color.BLACK
},
viewHolderPlaceholderModifications = {
resID = R.drawable.ic_close
},
sizeTextModifications = {
textAlignment = TextView.TEXT_ALIGNMENT_VIEW_START
textStyle = SizeTextModifier.TextStyle.NORMAL
margin = 22 // use dp or sp this is only for demonstration purposes
textColor = Color.BLACK
textPadding = 5 // use dp or sp this is only for demonstration purposes
textSize = 12f // use sp this is only for demonstration purposes
backgroundDrawable = R.drawable.rounded_bg_abstract_dialog
}
)
}, ::doSomethingWithVideoList)
If you're using Fragments to call the pickers you can leverage set fragment result listener to get back the result and you don't have to restore the listener nor provide a lambda for the listener, it can be as simple as
SingleVideoPicker.showPicker(requireContext())
setFragmentResultListener(SingleVideoPicker.SINGLE_VIDEO_REQUEST_KEY) { _, bundle ->
val loadedModel = bundle.getParcelable<VideoModel>(SingleVideoPicker.ON_SINGLE_VIDEO_PICK_KEY)
loadedModel?.let { loadVideo(it) }
}
setFragmentResultListener(MultiVideoPicker.MULTI_VIDEO_REQUEST_KEY) { _, bundle ->
val loadedModel = bundle.getParcelableArrayList<VideoModel>(MultiVideoPicker.ON_MULTI_VIDEO_PICK_KEY)
loadedModel?.let { doSomethingWithVideoList(it) }
}
If you're still not sure how to use, take a look at the Sample app
If you're still not sure how to use fragment listener, take a look at the Sample app
Single picker
Multi pickers