Skip to content

Commit

Permalink
Merge pull request #61 from jellyfin/media-source-tweaks
Browse files Browse the repository at this point in the history
MediaSource tweaks
  • Loading branch information
nielsvanvelzen authored Aug 25, 2020
2 parents 90e6a7d + 3c80ea0 commit f9f80a4
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 26 deletions.
9 changes: 7 additions & 2 deletions app/src/main/java/org/jellyfin/mobile/player/PlaybackMenus.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class PlaybackMenus(private val activity: PlayerActivity) : PopupMenu.OnDismissL
buildMenuItems(subtitlesMenu.menu, SUBTITLES_MENU_GROUP, item.subtitleTracksGroup, true)
buildMenuItems(audioStreamsMenu.menu, AUDIO_MENU_GROUP, item.audioTracksGroup)

val playMethod = activity.getString(R.string.playback_info_play_method, item.playMethod)
val transcodingInfo = activity.getString(R.string.playback_info_transcoding, item.isTranscoding)
val videoTracksInfo = item.videoTracksGroup.tracks.run {
joinToString(
Expand All @@ -62,8 +63,12 @@ class PlaybackMenus(private val activity: PlayerActivity) : PopupMenu.OnDismissL
truncated = activity.getString(R.string.playback_info_and_x_more, size - 3)
) { "- ${it.title} (${it.language})" }
}
val info = "$transcodingInfo\n\n$videoTracksInfo\n\n$audioTracksInfo"
playbackInfo.text = info
playbackInfo.text = listOf(
playMethod,
transcodingInfo,
videoTracksInfo,
audioTracksInfo,
).joinToString("\n\n")
}

private fun createSubtitlesMenu() = PopupMenu(activity, subtitlesButton).apply {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package org.jellyfin.mobile.player.source

import android.net.Uri
import com.google.android.exoplayer2.util.MimeTypes
import org.jellyfin.mobile.utils.Constants
import org.json.JSONArray
import org.json.JSONObject

class JellyfinMediaSource(item: JSONObject) {
val title: String = item.getString("title")
val url: String = item.getString("url")
val id: String = item.optJSONObject("item")?.optString("Id") ?: ""
val title: String = item.optString("title")
val uri: Uri = Uri.parse(item.optString("url"))
val playMethod: String = item.optString("playMethod")
val mediaDurationMs: Long
val mediaStartMs: Long = item.optLong("playerStartPositionTicks") / Constants.TICKS_PER_MILLISECOND
val videoTracksGroup: ExoPlayerTracksGroup<ExoPlayerTrack.Video>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,23 @@ class MediaSourceManager(private val viewModel: PlayerViewModel) {
val eventLogger = EventLogger(trackSelector)

fun handleIntent(intent: Intent, replace: Boolean = false): Boolean {
return if (_jellyfinMediaSource.value == null || replace) {
val newSource = createFromIntent(intent)
if (newSource != null) {
val oldSource = _jellyfinMediaSource.value
_jellyfinMediaSource.value = newSource
val oldSource = _jellyfinMediaSource.value
if (oldSource == null || replace) {
val newSource = createFromIntent(intent) ?: return false
_jellyfinMediaSource.value = newSource

// Keep current selections in the new item
if (oldSource != null) {
newSource.subtitleTracksGroup.selectedTrack = oldSource.subtitleTracksGroup.selectedTrack
newSource.audioTracksGroup.selectedTrack = oldSource.audioTracksGroup.selectedTrack
}
val mediaSource = prepareStreams(newSource)
if (mediaSource != null) {
viewModel.playMedia(mediaSource, startPosition = newSource.mediaStartMs)
viewModel.updateMediaMetadata(newSource)
}
true
} else false
} else true
// Keep current selections in the new item
if (oldSource != null) {
newSource.subtitleTracksGroup.selectedTrack = oldSource.subtitleTracksGroup.selectedTrack
newSource.audioTracksGroup.selectedTrack = oldSource.audioTracksGroup.selectedTrack
}

// Create ExoPlayer MediaSource
val mediaSource = prepareStreams(newSource) ?: return false
viewModel.playMedia(mediaSource, startPosition = newSource.mediaStartMs)
viewModel.updateMediaMetadata(newSource)
}
return true
}

/**
Expand Down Expand Up @@ -78,11 +76,10 @@ class MediaSourceManager(private val viewModel: PlayerViewModel) {

@CheckResult
private fun createVideoMediaSource(item: JellyfinMediaSource, dataSourceFactory: DataSource.Factory): MediaSource {
val uri: Uri = Uri.parse(item.url)
return if (item.isTranscoding) {
HlsMediaSource.Factory(dataSourceFactory).setAllowChunklessPreparation(true).createMediaSource(uri)
HlsMediaSource.Factory(dataSourceFactory).setAllowChunklessPreparation(true).createMediaSource(item.uri)
} else {
ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(uri)
ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(item.uri)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ inline fun MediaSession.applyDefaultLocalAudioAttributes(contentType: Int) {
}

fun JellyfinMediaSource.toMediaMetadata(): MediaMetadata = MediaMetadata.Builder().apply {
putString(MediaMetadata.METADATA_KEY_MEDIA_ID, url)
putString(MediaMetadata.METADATA_KEY_MEDIA_ID, id)
putString(MediaMetadata.METADATA_KEY_TITLE, title)
putLong(MediaMetadata.METADATA_KEY_DURATION, mediaDurationMs)
}.build()
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<string name="downloading">Downloading</string>

<string name="menu_item_none">None</string>
<string name="playback_info_play_method">Play method: %s</string>
<string name="playback_info_transcoding">Transcoding: %b</string>
<string name="playback_info_video_streams">Video streams</string>
<string name="playback_info_audio_streams">Audio streams</string>
Expand Down

0 comments on commit f9f80a4

Please sign in to comment.