Skip to content

Commit

Permalink
Disallow unavailable media in preload
Browse files Browse the repository at this point in the history
  • Loading branch information
Senorsen committed Aug 29, 2017
1 parent a21c79e commit 9132cf6
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion wukong/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ android {
minSdkVersion 21
targetSdkVersion 25
versionCode 141
versionName "0.1.43"
versionName "0.1.44"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ class MediaSourceSelector(private val context: Context) {
}.filterNotNull()
}

fun selectFromMultipleMediaFiles(song: Song): Pair<List<File>, List<String>> {
fun selectFromMultipleMediaFiles(song: Song, acceptUnavailable: Boolean = true): Pair<List<File>, List<String>> {
pullSettings()
val defaultQualityIndex = qualities.indexOf(preferAudioQualityData)
val originalFiles = song.musics?.sortedByDescending(File::audioBitrate) ?:
val files = if (acceptUnavailable) song.musics else song.musics?.filterNot { it.unavailable == true}
val originalFiles = files?.sortedByDescending(File::audioBitrate) ?:
return Pair(listOf(), listOf())

val resultFiles = originalFiles.filter { qualities.indexOf(it.audioQuality) >= defaultQualityIndex }.toMutableList()
Expand Down
2 changes: 1 addition & 1 deletion wukong/src/main/java/com/senorsen/wukong/model/Song.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ data class Song(

// A File is an object which contains uri and other required metadata.
data class File(
var available: Boolean? = null,
var unavailable: Boolean? = null,
var file: String? = null,
var fileViaCdn: String? = null,
var format: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ class WukongService : Service() {
if (out != null) {
Log.d(TAG, "cache exists, skip preload ${song.songKey}")
} else {
val (files, mediaSources) = mediaSourceSelector.selectFromMultipleMediaFiles(song)
val (files, mediaSources) = mediaSourceSelector.selectFromMultipleMediaFiles(song, false)
Log.d(TAG, "preload media sources: $mediaSources")

val source = MediaSourcePreparer.setMediaSources(mediaPlayerForPreloadVerification, mediaSources)
Expand Down

0 comments on commit 9132cf6

Please sign in to comment.