close inputstream and datasource to prevent leaks

This commit is contained in:
gmasil 2023-08-25 13:27:19 +02:00
parent c3778e36c6
commit a5292aa669
No known key found for this signature in database
GPG key ID: 135FC0B941F3ECC7
2 changed files with 11 additions and 8 deletions

View file

@ -741,17 +741,17 @@ class PhotoFragment : ViewPagerFragment() {
private fun checkIfPanorama() {
mIsPanorama = try {
val inputStream = if (mMedium.path.startsWith("content:/")) {
if (mMedium.path.startsWith("content:/")) {
requireContext().contentResolver.openInputStream(Uri.parse(mMedium.path))
} else {
File(mMedium.path).inputStream()
}
val imageParser = JpegImageParser().getXmpXml(ByteSourceInputStream(inputStream, mMedium.name), HashMap<String, Any>())
}.use {
val imageParser = JpegImageParser().getXmpXml(ByteSourceInputStream(it, mMedium.name), HashMap<String, Any>())
imageParser.contains("GPano:UsePanoramaViewer=\"True\"", true) ||
imageParser.contains("<GPano:UsePanoramaViewer>True</GPano:UsePanoramaViewer>", true) ||
imageParser.contains("GPano:FullPanoWidthPixels=") ||
imageParser.contains("GPano:ProjectionType>Equirectangular")
}
} catch (e: Exception) {
false
} catch (e: OutOfMemoryError) {

View file

@ -362,6 +362,7 @@ import java.io.FileInputStream
try {
fileDataSource.open(dataSpec)
} catch (e: Exception) {
fileDataSource.close()
activity?.showErrorToast(e)
return
}
@ -370,6 +371,8 @@ import java.io.FileInputStream
val mediaSource: MediaSource = ProgressiveMediaSource.Factory(factory)
.createMediaSource(MediaItem.fromUri(fileDataSource.uri!!))
fileDataSource.close()
mPlayOnPrepared = true
mExoPlayer = ExoPlayer.Builder(requireContext())