-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-content resolver for local filels
- Loading branch information
Showing
2 changed files
with
16 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 15 additions & 3 deletions
18
gif_loader/src/main/java/com/rrpvm/gif_loader/common/data_source/LocalFileDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,27 @@ | ||
package com.rrpvm.gif_loader.common.data_source | ||
|
||
import android.content.Context | ||
import androidx.core.net.toUri | ||
import com.rrpvm.gif_loader.domain.entity.GifLoaderRequestCacheStrategy | ||
import com.rrpvm.gif_loader.domain.entity.IGifDataSource | ||
import java.io.File | ||
import java.io.FileNotFoundException | ||
import java.io.IOException | ||
|
||
class LocalFileDataSource(private val path: String) : IGifDataSource { | ||
class LocalFileDataSource( | ||
private val path: String, | ||
private val context: Context | ||
) : IGifDataSource { | ||
/* @kotlin.jvm.Throws(IOException::class, NullPointerException::class) | ||
override fun getVideoSource(cacheStrategy: GifLoaderRequestCacheStrategy): ByteArray { | ||
return File(path).inputStream().use { input -> | ||
return@use input.readBytes() | ||
} | ||
}*/ | ||
@kotlin.jvm.Throws(IOException::class, NullPointerException::class) | ||
override fun getVideoSource(cacheStrategy: GifLoaderRequestCacheStrategy): ByteArray { | ||
return File(path).inputStream().use { input -> | ||
return@use input.readBytes() | ||
return context.contentResolver.openInputStream(path.toUri()).use { input -> | ||
return@use input?.readBytes() ?: throw FileNotFoundException() | ||
} | ||
} | ||
} |