mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2026-05-16 04:52:39 +02:00
Possible crash fix
This commit is contained in:
@@ -7,6 +7,7 @@ import android.net.Uri
|
|||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import android.provider.MediaStore.Audio.Artists
|
import android.provider.MediaStore.Audio.Artists
|
||||||
import android.webkit.MimeTypeMap
|
import android.webkit.MimeTypeMap
|
||||||
|
import androidx.core.database.getStringOrNull
|
||||||
import androidx.core.net.toFile
|
import androidx.core.net.toFile
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import androidx.documentfile.provider.DocumentFile
|
import androidx.documentfile.provider.DocumentFile
|
||||||
@@ -185,29 +186,39 @@ class StateLibrary {
|
|||||||
fun getVideoBucketNames(): List<Bucket> {
|
fun getVideoBucketNames(): List<Bucket> {
|
||||||
if(_cacheBucketNames != null)
|
if(_cacheBucketNames != null)
|
||||||
return _cacheBucketNames ?: listOf();
|
return _cacheBucketNames ?: listOf();
|
||||||
val cur: Cursor = StateApp.instance.contextOrNull?.contentResolver?.query(
|
try {
|
||||||
MediaStore.Video.Media.EXTERNAL_CONTENT_URI, arrayOf(
|
val cur: Cursor = StateApp.instance.contextOrNull?.contentResolver?.query(
|
||||||
MediaStore.Video.Media.BUCKET_ID,
|
MediaStore.Video.Media.EXTERNAL_CONTENT_URI, arrayOf(
|
||||||
MediaStore.Video.Media.BUCKET_DISPLAY_NAME,
|
MediaStore.Video.Media.BUCKET_ID,
|
||||||
), null, null, null
|
MediaStore.Video.Media.BUCKET_DISPLAY_NAME,
|
||||||
) ?: return listOf();
|
), null, null, null
|
||||||
|
) ?: return listOf();
|
||||||
|
|
||||||
val buckets = mutableListOf<Bucket>();
|
val buckets = mutableListOf<Bucket>();
|
||||||
val list = HashSet<Long>();
|
val list = HashSet<Long>();
|
||||||
if (cur.moveToFirst()) {
|
if (cur.moveToFirst()) {
|
||||||
var id: Long;
|
var id: Long;
|
||||||
var bucket: String
|
var bucket: String
|
||||||
do {
|
do {
|
||||||
id = cur.getLong(0);
|
try {
|
||||||
bucket = cur.getString(1)
|
id = cur.getLong(0);
|
||||||
if(!list.contains(id)) {
|
bucket = cur.getStringOrNull(1) ?: continue;
|
||||||
list.add(id);
|
if (!list.contains(id)) {
|
||||||
buckets.add(Bucket(id, bucket));
|
list.add(id);
|
||||||
}
|
buckets.add(Bucket(id, bucket));
|
||||||
} while (cur.moveToNext())
|
}
|
||||||
|
} catch (ex: Throwable) {
|
||||||
|
Logger.e(TAG, "Failed to parse bucket due to ${ex.message}", ex);
|
||||||
|
}
|
||||||
|
} while (cur.moveToNext())
|
||||||
|
}
|
||||||
|
_cacheBucketNames = buckets.toList()
|
||||||
|
return _cacheBucketNames ?: listOf();
|
||||||
|
}
|
||||||
|
catch(ex: Throwable) {
|
||||||
|
Logger.e(TAG, "Buckets loading failed, returning empty");
|
||||||
|
return listOf();
|
||||||
}
|
}
|
||||||
_cacheBucketNames = buckets.toList()
|
|
||||||
return _cacheBucketNames ?: listOf();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user