Skip to content

Commit

Permalink
Use http datasource for local urls (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
janwiebe-jump authored Mar 5, 2024
1 parent 551ae15 commit b09b5c0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import com.doublesymmetry.kotlinaudio.models.PositionChangedReason
import com.doublesymmetry.kotlinaudio.notification.NotificationManager
import com.doublesymmetry.kotlinaudio.players.components.PlayerCache
import com.doublesymmetry.kotlinaudio.players.components.getAudioItemHolder
import com.doublesymmetry.kotlinaudio.utils.isUriLocal
import com.doublesymmetry.kotlinaudio.utils.isUriLocalFile
import com.google.android.exoplayer2.C
import com.google.android.exoplayer2.DefaultLoadControl
import com.google.android.exoplayer2.DefaultLoadControl.Builder
Expand Down Expand Up @@ -459,7 +459,7 @@ abstract class BaseAudioPlayer internal constructor(
raw.open(DataSpec(uri))
DataSource.Factory { raw }
}
isUriLocal(uri) -> {
isUriLocalFile(uri) -> {
DefaultDataSourceFactory(context, userAgent)
}
else -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import android.content.ContentResolver
import android.net.Uri
import com.google.android.exoplayer2.upstream.RawResourceDataSource

fun isUriLocal(uri: Uri?): Boolean {
fun isUriLocalFile(uri: Uri?): Boolean {
if (uri == null) return false
val scheme = uri.scheme
val host = uri.host
return scheme == null || scheme == ContentResolver.SCHEME_FILE || scheme == ContentResolver.SCHEME_ANDROID_RESOURCE || scheme == ContentResolver.SCHEME_CONTENT || scheme == RawResourceDataSource.RAW_RESOURCE_SCHEME || scheme == "res" || host == null || host == "localhost" || host == "127.0.0.1" || host == "[::1]"
if((scheme == "http" || scheme == "https") && (host == "localhost" || host == "127.0.0.1" || host == "[::1]"))
{
return false
}
return scheme == null || scheme == ContentResolver.SCHEME_FILE || scheme == ContentResolver.SCHEME_ANDROID_RESOURCE || scheme == ContentResolver.SCHEME_CONTENT || scheme == RawResourceDataSource.RAW_RESOURCE_SCHEME || scheme == "res" || host == null
}

0 comments on commit b09b5c0

Please sign in to comment.