Ниже приведена функция удаления, функция, используемая для получения видео и файла манифеста:
Код: Выделить всё
binding.deleteVideoButton.setOnClickListener {
//check this section there is something wrong with it
val file = File(currentVideoUri.path.toString())
if (file.exists() && !lock) {
Utilities.moveViewUpAndBack(binding.deleteVideoButton)
val confirmDeleteDialog = AlertDialog.Builder(this)
.setTitle(getString(R.string.delete_video))
.setMessage(getString(R.string.deletion_confirmation))
.setPositiveButton(getString(R.string.yes)) { _, _ ->
binding.progressBar.visibility = View.VISIBLE
CoroutineScope(Dispatchers.IO).launch {
val deleted = file.delete()
withContext(Dispatchers.Main) {
binding.progressBar.visibility = View.GONE
if (deleted) {
val tempoVideos = Utilities.listVideos(applicationContext)
val tempoThumbnails = Utilities.convertFilesToBitmaps(tempoVideos.take(5))
val tempoUris = tempoVideos.map { Uri.fromFile(it) }
if (tempoUris.isNotEmpty()) {
currentVideoUri = tempoUris[0]
preparePlayer(currentVideoUri)
}
adapter.updateThumbnails(tempoThumbnails, tempoUris)
loadRemainingBitmaps(tempoVideos.drop(5))
} else {
Toast.makeText(this@PreviewActivity,
getString(R.string.failed_to_delete_video),
Toast.LENGTH_SHORT).show()
}
//alertDialog.dismiss()
}
}
}
.setNegativeButton(getString(R.string.no), null)
.create()
confirmDeleteDialog.show()
} else {
Toast.makeText(this, getString(R.string.file_not_found), Toast.LENGTH_SHORT).show()
}
}
Код: Выделить всё
fun listVideos(context: Context): List {
val videos = mutableListOf()
val projection = arrayOf(MediaStore.Video.Media._ID,
MediaStore.Video.Media.DISPLAY_NAME,
MediaStore.Video.Media.DATE_ADDED,
MediaStore.Video.Media.DATA)
val selection =
"${MediaStore.Video.Media.DISPLAY_NAME} LIKE ? AND ${MediaStore.Video.Media.DISPLAY_NAME} NOT LIKE ? AND ${MediaStore.Video.Media.DISPLAY_NAME} LIKE ?"
val selectionArgs = arrayOf("%camerago_%", "%.pending%", "%.mp4")
val sortOrder = "${MediaStore.Video.Media.DATE_ADDED} DESC"
val query = context.contentResolver.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
projection,
selection,
selectionArgs,
sortOrder)
query?.use { cursor ->
val nameColumn = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DISPLAY_NAME)
val dataColumn = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA)
while (cursor.moveToNext()) {
val data = cursor.getString(dataColumn)
//Log.e("logo", "video name: $name")
videos.add(File(data))
}
}
return videos
}
Код: Выделить всё
android:name="androidx.core.content.FileProvider"
android:authorities="com.nerovero.camerago.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
Подробнее здесь: https://stackoverflow.com/questions/787 ... android-14
Мобильная версия