diff --git a/app/src/main/java/org/jellyfin/mobile/player/PlaybackMenus.kt b/app/src/main/java/org/jellyfin/mobile/player/PlaybackMenus.kt index 4c1e8d429..7ea69ba95 100644 --- a/app/src/main/java/org/jellyfin/mobile/player/PlaybackMenus.kt +++ b/app/src/main/java/org/jellyfin/mobile/player/PlaybackMenus.kt @@ -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( @@ -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 { diff --git a/app/src/main/java/org/jellyfin/mobile/player/source/JellyfinMediaSource.kt b/app/src/main/java/org/jellyfin/mobile/player/source/JellyfinMediaSource.kt index 574131de5..ab56ae705 100644 --- a/app/src/main/java/org/jellyfin/mobile/player/source/JellyfinMediaSource.kt +++ b/app/src/main/java/org/jellyfin/mobile/player/source/JellyfinMediaSource.kt @@ -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 diff --git a/app/src/main/java/org/jellyfin/mobile/player/source/MediaSourceManager.kt b/app/src/main/java/org/jellyfin/mobile/player/source/MediaSourceManager.kt index 4d81fd86f..f3a54fbaa 100644 --- a/app/src/main/java/org/jellyfin/mobile/player/source/MediaSourceManager.kt +++ b/app/src/main/java/org/jellyfin/mobile/player/source/MediaSourceManager.kt @@ -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 } /** @@ -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) } } diff --git a/app/src/main/java/org/jellyfin/mobile/utils/MediaExtensions.kt b/app/src/main/java/org/jellyfin/mobile/utils/MediaExtensions.kt index d43b3435f..492bfd008 100644 --- a/app/src/main/java/org/jellyfin/mobile/utils/MediaExtensions.kt +++ b/app/src/main/java/org/jellyfin/mobile/utils/MediaExtensions.kt @@ -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() diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ccc820ef9..25382a86d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -17,6 +17,7 @@ Downloading None + Play method: %s Transcoding: %b Video streams Audio streams