Compare commits

...

24 Commits

Author SHA1 Message Date
Niels van Velzen
118eacfa90 Specify BUILD_TOOLS_VERSION for r0adkll/sign-android-release step in publish workflow 2024-02-13 13:45:10 +01:00
MichaelR416
91ccf32f77 Fix media details tag for multiple versions support
(cherry picked from commit 9ec9de0ba1)
2024-02-11 16:14:29 +01:00
Niels van Velzen
065e738773 Only show PG-13 content in screensaver
(cherry picked from commit 5ff02c7e5d)
2024-02-11 16:12:35 +01:00
MichaelR416
65a7bbf501 Add if else statement for audio downmixing support
(cherry picked from commit d5c5bcc41c)
2024-02-11 16:12:30 +01:00
renovate[bot]
d661c2faf3 fix(deps): update dependency org.jellyfin.media3:media3-ffmpeg-decoder to v1.2.1+1
(cherry picked from commit 60eac66d90)
2024-02-11 16:12:14 +01:00
renovate[bot]
8175dbd1c0 fix(deps): update androidx.media3 to v1.2.1
(cherry picked from commit abf46d42f5)
2024-02-11 16:12:13 +01:00
lawadr
f068be6945 Widen support for HEVC Main 10
Previously the HEVC codec profile only flagged support for HEVC Main 10
when MediaCodec advertised its support for level 5 (main tier) or above.
This meant devices that support only levels 4 or 4.1 (such as the
Chromecast with Google TV HD) would transcode HEVC Main 10 content even
when supported.

This change lowers the requirement from level 5 to level 4 and also adds
additional profiles specifically for HEVC Main and Main 10 with
conditions on the level so that levels beyond what is supported by
MediaCodec get transcoded.

The result is that HEVC Main 10 level 5 videos get transcoded on devices
supporting only 4.1, but HEVC Main 10 level 4.1 content plays back
directly.

(cherry picked from commit 1fb3e0399c)
2024-02-11 16:11:41 +01:00
MichaelR416
fe465db020 Use LTR for default subtitle direction
(cherry picked from commit 17b76e1536)
2024-02-11 16:11:36 +01:00
Gwilherm Folliot
d6fe265b38 Fix crash when quitting player after two plays
If you play a title from a device and play another without quitting the player and then quit the player the app crash.

Its because the NavigationRepository stacks two players and when coming to the last one, the app crash because the last player is terminated.

My fix just replace the last destination if an fragment is active

java.lang.NullPointerException: Parameter specified as non-null is null: method androidx.activity.OnBackPressedDispatcher.addCallback, parameter onBackPressedCallback
	at androidx.activity.OnBackPressedDispatcher.addCallback(Unknown Source:3)
	at org.jellyfin.androidtv.ui.playback.CustomPlaybackOverlayFragment.onActivityCreated(CustomPlaybackOverlayFragment.java:346)
	at androidx.fragment.app.Fragment.performActivityCreated(Fragment.java:3156)
	at androidx.fragment.app.FragmentStateManager.activityCreated(FragmentStateManager.java:619)
	at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:275)
	at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1934)
	at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1839)
	at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1782)
	at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:565)
	at android.os.Handler.handleCallback(Handler.java:942)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loopOnce(Looper.java:201)
	at android.os.Looper.loop(Looper.java:288)
	at android.app.ActivityThread.main(ActivityThread.java:7884)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

(cherry picked from commit 6867c319bb)
2024-02-11 16:11:29 +01:00
Niels van Velzen
8eecfab5d7 Disable tunneling 2024-01-07 14:53:05 +01:00
Niels van Velzen
0f9ffcacb9 Defer home initialization until user info is available
(cherry picked from commit d721482127)
2024-01-06 13:50:56 +01:00
Niels van Velzen
aa7c45d462 Disable crossfading for CardLegacyImageView to fix scaling issue
(cherry picked from commit 1fbc19740b)
2024-01-05 19:54:19 +01:00
Gwilherm Folliot
156f5ecd3c Fix crash when DISPLAY_CONTENT while playing
When a video is playing and on another device you browse libraries on a casting device it cause the app to crash

The onDisplayContent method is trying to read ExoPlayer state but from the socket thread and not the main thread

java.lang.IllegalStateException: Player is accessed on the wrong thread.
Current thread: 'DefaultDispatcher-worker-4'
Expected thread: 'main'
See https://developer.android.com/guide/topics/media/issues/player-accessed-on-wrong-thread
	at androidx.media3.exoplayer.ExoPlayerImpl.verifyApplicationThread(ExoPlayerImpl.java:2842)
	at androidx.media3.exoplayer.ExoPlayerImpl.getPlaybackState(ExoPlayerImpl.java:514)
	at androidx.media3.common.BasePlayer.isPlaying(BasePlayer.java:124)
	at org.jellyfin.androidtv.ui.playback.VideoManager.isPlaying(VideoManager.java:341)
	at org.jellyfin.androidtv.ui.playback.PlaybackController.isPlaying(PlaybackController.java:262)
	at org.jellyfin.androidtv.data.eventhandling.SocketHandler.onDisplayContent(SocketHandler.kt:184)
	at org.jellyfin.androidtv.data.eventhandling.SocketHandler.lambda$13$lambda$8(SocketHandler.kt:103)
	at org.jellyfin.androidtv.data.eventhandling.SocketHandler$$ExternalSyntheticLambda3.onReceive(Unknown Source:4)
	at org.jellyfin.androidtv.data.eventhandling.SocketHandler$_init_$lambda$13$$inlined$addGeneralCommandsListener$default$1.onReceive(ListenerRegistrationExtensions.kt:68)
	at org.jellyfin.sdk.api.sockets.helper.ListenerHelper.forwardMessage(ListenerHelper.kt:37)
	at org.jellyfin.sdk.api.sockets.SocketInstance.forwardMessage(SocketInstance.kt:283)
	at org.jellyfin.sdk.api.sockets.SocketInstance.access$forwardMessage(SocketInstance.kt:35)
	at org.jellyfin.sdk.api.sockets.SocketInstance$connectAndBind$2.invokeSuspend(SocketInstance.kt:220)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)

(cherry picked from commit 0116530794)
2024-01-05 19:54:18 +01:00
Niels van Velzen
e56fd0d024 Set TsExtractor TimestampSearchBytes parameter based on device memory capabilities
(cherry picked from commit 76acd17d81)
2024-01-05 19:54:18 +01:00
Niels van Velzen
06e245fe48 Enable tunneling in VideoManager
(cherry picked from commit e646192196)
2024-01-05 19:54:17 +01:00
Niels van Velzen
9f0fa644a7 Enable tunneling in ExoPlayerBackend
(cherry picked from commit 1f0345f16f)
2024-01-05 19:54:17 +01:00
Niels van Velzen
5b213199dd Add <queries> element to Manifest for remote trailers
(cherry picked from commit b91fd1a0f5)
2024-01-05 19:54:16 +01:00
Niels van Velzen
b4f6273ede Disable SocketHandler when using RewriteMediaManager
(cherry picked from commit 332b6af3da)
2024-01-05 19:54:16 +01:00
Niels van Velzen
66c624e16c Replace ExoPlayer with androidx.media3
(cherry picked from commit bd204fdf87)
2024-01-05 19:54:15 +01:00
Niels van Velzen
e47916f1c2 Fix crash and inconsistent ordering when using ShuffleOrderIndexProvider
(cherry picked from commit b9e19b2515)
2024-01-05 19:54:15 +01:00
Niels van Velzen
ab7875cbb3 Fix opening collections via search results showing empty screen
(cherry picked from commit 2bbbb93dbf)
2024-01-05 19:54:14 +01:00
Niels van Velzen
5f15615a96 Fix playing audio from search queues entire row
(cherry picked from commit 8b43402192)
2024-01-05 19:54:14 +01:00
Niels van Velzen
9cda86ab84 Fix focus issue when pressing back in Fire TV soft keyboard
(cherry picked from commit c70f814064)
2024-01-05 19:54:14 +01:00
Niels van Velzen
1873497fec Fix RewriteMediaManager never used in production builds
(cherry picked from commit 75b6b12147)
2023-12-18 22:21:02 +01:00
35 changed files with 406 additions and 176 deletions

View File

@@ -27,6 +27,8 @@ jobs:
- name: Sign APK
id: signApk
uses: r0adkll/sign-android-release@349ebdef58775b1e0d8099458af0816dc79b6407 # tag=v1
env:
BUILD_TOOLS_VERSION: "34.0.0"
with:
releaseDirectory: app/build/outputs/apk/release
signingKeyBase64: ${{ secrets.KEYSTORE }}
@@ -36,6 +38,8 @@ jobs:
- name: Sign app bundle
id: signAab
uses: r0adkll/sign-android-release@349ebdef58775b1e0d8099458af0816dc79b6407 # tag=v1
env:
BUILD_TOOLS_VERSION: "34.0.0"
with:
releaseDirectory: app/build/outputs/bundle/release
signingKeyBase64: ${{ secrets.KEYSTORE }}

View File

@@ -12,6 +12,7 @@
- [GodTamIt](https://github.com/GodTamIt)
- [sparky3387](https://github.com/sparky3387)
- [mohd-akram](https://github.com/mohd-akram)
- [3l0w](https://github.com/3l0w)
# Emby Contributors

View File

@@ -139,8 +139,10 @@ dependencies {
implementation(libs.bundles.koin)
// Media players
implementation(libs.exoplayer)
implementation(libs.jellyfin.exoplayer.ffmpegextension)
implementation(libs.androidx.media3.exoplayer)
implementation(libs.androidx.media3.exoplayer.hls)
implementation(libs.androidx.media3.ui)
implementation(libs.jellyfin.androidx.media3.ffmpeg.decoder)
implementation(libs.libvlc)
// Markdown

View File

@@ -28,6 +28,15 @@
android:name="android.hardware.microphone"
android:required="false" />
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<data
android:host="youtube.com"
android:scheme="https" />
</intent>
</queries>
<application
android:name=".JellyfinApplication"
android:allowBackup="true"

View File

@@ -14,6 +14,7 @@ import org.jellyfin.androidtv.ui.navigation.Destinations
import org.jellyfin.androidtv.ui.navigation.NavigationRepository
import org.jellyfin.androidtv.ui.playback.MediaManager
import org.jellyfin.androidtv.ui.playback.PlaybackControllerContainer
import org.jellyfin.androidtv.ui.playback.rewrite.RewriteMediaManager
import org.jellyfin.androidtv.util.apiclient.PlaybackHelper
import org.jellyfin.sdk.api.client.ApiClient
import org.jellyfin.sdk.api.client.exception.ApiClientException
@@ -137,36 +138,52 @@ class SocketHandler(
@Suppress("ComplexMethod")
private fun onPlayStateMessage(message: PlayStateMessage) = coroutineScope.launch(Dispatchers.Main) {
Timber.i("Received PlayStateMessage with command ${message.request.command}")
val playbackController = playbackControllerContainer.playbackController
// Audio playback uses the mediaManager, video playback and live tv use the playbackController
if (mediaManager.isAudioPlayerInitialized) when (message.request.command) {
PlaystateCommand.STOP -> mediaManager.stopAudio(true)
PlaystateCommand.PAUSE, PlaystateCommand.UNPAUSE, PlaystateCommand.PLAY_PAUSE -> mediaManager.playPauseAudio()
PlaystateCommand.NEXT_TRACK -> mediaManager.nextAudioItem()
PlaystateCommand.PREVIOUS_TRACK -> mediaManager.prevAudioItem()
// Not implemented
PlaystateCommand.SEEK,
PlaystateCommand.REWIND,
PlaystateCommand.FAST_FORWARD -> Unit
} else when (message.request.command) {
PlaystateCommand.STOP -> playbackController?.endPlayback(true)
PlaystateCommand.PAUSE, PlaystateCommand.UNPAUSE, PlaystateCommand.PLAY_PAUSE -> playbackController?.playPause()
PlaystateCommand.NEXT_TRACK -> playbackController?.next()
PlaystateCommand.PREVIOUS_TRACK -> playbackController?.prev()
PlaystateCommand.SEEK -> playbackController?.seek(
(message.request.seekPositionTicks ?: 0) / TICKS_TO_MS
)
PlaystateCommand.REWIND -> playbackController?.rewind()
PlaystateCommand.FAST_FORWARD -> playbackController?.fastForward()
// Audio playback uses (Rewrite)MediaManager, (legacy) video playback uses playbackController
when {
// Ignore RewriteMediaManager
mediaManager is RewriteMediaManager && mediaManager.hasAudioQueueItems() -> {
Timber.i("Ignoring PlayStateMessage: should be handled by PlaySessionSocketService")
return@launch
}
// LegacyMediaManager
mediaManager.hasAudioQueueItems() -> when (message.request.command) {
PlaystateCommand.STOP -> mediaManager.stopAudio(true)
PlaystateCommand.PAUSE, PlaystateCommand.UNPAUSE, PlaystateCommand.PLAY_PAUSE -> mediaManager.playPauseAudio()
PlaystateCommand.NEXT_TRACK -> mediaManager.nextAudioItem()
PlaystateCommand.PREVIOUS_TRACK -> mediaManager.prevAudioItem()
// Not implemented
PlaystateCommand.SEEK,
PlaystateCommand.REWIND,
PlaystateCommand.FAST_FORWARD -> Unit
}
// PlaybackController
else -> {
val playbackController = playbackControllerContainer.playbackController
when (message.request.command) {
PlaystateCommand.STOP -> playbackController?.endPlayback(true)
PlaystateCommand.PAUSE, PlaystateCommand.UNPAUSE, PlaystateCommand.PLAY_PAUSE -> playbackController?.playPause()
PlaystateCommand.NEXT_TRACK -> playbackController?.next()
PlaystateCommand.PREVIOUS_TRACK -> playbackController?.prev()
PlaystateCommand.SEEK -> playbackController?.seek(
(message.request.seekPositionTicks ?: 0) / TICKS_TO_MS
)
PlaystateCommand.REWIND -> playbackController?.rewind()
PlaystateCommand.FAST_FORWARD -> playbackController?.fastForward()
}
}
}
}
private fun onDisplayContent(itemId: UUID, itemKind: BaseItemKind) {
private fun onDisplayContent(itemId: UUID, itemKind: BaseItemKind) = coroutineScope.launch(Dispatchers.Main) {
val playbackController = playbackControllerContainer.playbackController
if (playbackController?.isPlaying == true || playbackController?.isPaused == true) {
Timber.i("Not launching $itemId: playback in progress")
return
return@launch
}
Timber.i("Launching $itemId")

View File

@@ -35,7 +35,7 @@ val playbackModule = module {
factory {
val preferences = get<UserPreferences>()
val useRewrite = preferences[UserPreferences.playbackRewriteAudioEnabled] && BuildConfig.DEVELOPMENT
val useRewrite = preferences[UserPreferences.playbackRewriteAudioEnabled]
if (useRewrite) get<RewriteMediaManager>()
else get<LegacyMediaManager>()

View File

@@ -76,6 +76,9 @@ private suspend fun getRandomLibraryShowcase(
sortBy = listOf(ItemSortBy.Random),
limit = 5,
imageTypes = listOf(ImageType.BACKDROP),
// TODO: Add preferences for these two settings
maxOfficialRating = "PG-13",
// hasParentalRating = true,
)
val item = response.items?.firstOrNull { item ->

View File

@@ -82,7 +82,10 @@ class AsyncImageView @JvmOverloads constructor(
}.build())
} else {
imageLoader.enqueue(ImageRequest.Builder(context).apply {
crossfade(crossFadeDuration.inWholeMilliseconds.toInt())
val crossFadeDurationMs = crossFadeDuration.inWholeMilliseconds.toInt()
if (crossFadeDurationMs > 0) crossfade(crossFadeDurationMs)
else crossfade(false)
target(this@AsyncImageView)
data(url)
placeholder(placeholderOrBlurHash)

View File

@@ -1,52 +1,36 @@
package org.jellyfin.androidtv.ui.browsing;
import android.os.Bundle;
import org.jellyfin.androidtv.R;
import org.jellyfin.androidtv.data.querying.StdItemQuery;
import org.jellyfin.androidtv.util.Utils;
import org.jellyfin.apiclient.model.querying.ItemFields;
import org.jellyfin.sdk.model.api.BaseItemKind;
public class CollectionFragment extends EnhancedBrowseFragment {
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
@Override
protected void setupQueries(RowLoader rowLoader) {
if (Utils.getSafeValue(mFolder.getChildCount(), 0) > 0) {
StdItemQuery movies = new StdItemQuery(new ItemFields[]{
ItemFields.PrimaryImageAspectRatio,
ItemFields.Overview,
ItemFields.ItemCounts,
ItemFields.DisplayPreferencesId,
ItemFields.ChildCount,
ItemFields.MediaStreams,
ItemFields.MediaSources
});
movies.setParentId(mFolder.getId().toString());
movies.setIncludeItemTypes(new String[]{"Movie"});
mRows.add(new BrowseRowDef(getString(R.string.lbl_movies), movies, 100));
StdItemQuery movies = new StdItemQuery(new ItemFields[]{
ItemFields.PrimaryImageAspectRatio,
ItemFields.Overview,
ItemFields.ItemCounts,
ItemFields.DisplayPreferencesId,
ItemFields.ChildCount,
ItemFields.MediaStreams,
ItemFields.MediaSources
});
movies.setParentId(mFolder.getId().toString());
movies.setIncludeItemTypes(new String[]{BaseItemKind.MOVIE.getSerialName()});
mRows.add(new BrowseRowDef(getString(R.string.lbl_movies), movies, 100));
StdItemQuery series = new StdItemQuery();
series.setParentId(mFolder.getId().toString());
series.setIncludeItemTypes(new String[]{"Series"});
mRows.add(new BrowseRowDef(getString(R.string.lbl_tv_series), series, 100));
StdItemQuery others = new StdItemQuery();
others.setParentId(mFolder.getId().toString());
others.setExcludeItemTypes(new String[]{"Movie", "Series"});
mRows.add(new BrowseRowDef(getString(R.string.lbl_other), others, 100));
rowLoader.loadRows(mRows);
}
StdItemQuery series = new StdItemQuery();
series.setParentId(mFolder.getId().toString());
series.setIncludeItemTypes(new String[]{BaseItemKind.SERIES.getSerialName()});
mRows.add(new BrowseRowDef(getString(R.string.lbl_tv_series), series, 100));
StdItemQuery others = new StdItemQuery();
others.setParentId(mFolder.getId().toString());
others.setExcludeItemTypes(new String[]{BaseItemKind.MOVIE.getSerialName(), BaseItemKind.SERIES.getSerialName()});
mRows.add(new BrowseRowDef(getString(R.string.lbl_other), others, 100));
rowLoader.loadRows(mRows);
}
}

View File

@@ -17,11 +17,14 @@ import androidx.lifecycle.repeatOnLifecycle
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.awaitCancellation
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlinx.coroutines.withTimeout
import org.jellyfin.androidtv.auth.repository.UserRepository
import org.jellyfin.androidtv.constant.CustomMessage
import org.jellyfin.androidtv.constant.HomeSectionType
@@ -88,15 +91,17 @@ class HomeRowsFragment : RowsSupportFragment(), AudioEventListener, View.OnKeyLi
adapter = MutableObjectAdapter<Row>(PositionableListRowPresenter())
val currentUser = userRepository.currentUser.value
lifecycleScope.launch(Dispatchers.IO) {
val currentUser = withTimeout(30.seconds) {
userRepository.currentUser.filterNotNull().first()
}
// Start out with default sections
val homesections = userSettingPreferences.homesections
var includeLiveTvRows = false
// Check for live TV support
if (homesections.contains(HomeSectionType.LIVE_TV) && currentUser?.policy?.enableLiveTvAccess == true) {
if (homesections.contains(HomeSectionType.LIVE_TV) && currentUser.policy?.enableLiveTvAccess == true) {
// This is kind of ugly, but it mirrors how web handles the live TV rows on the home screen
// If we can retrieve one live TV recommendation, then we should display the rows
val recommendedPrograms by api.liveTvApi.getRecommendedPrograms(

View File

@@ -5,6 +5,7 @@ import android.content.Context;
import androidx.annotation.Nullable;
import org.jellyfin.androidtv.constant.LiveTvOption;
import org.jellyfin.androidtv.constant.QueryType;
import org.jellyfin.androidtv.data.model.ChapterItemInfo;
import org.jellyfin.androidtv.preference.LibraryPreferences;
import org.jellyfin.androidtv.preference.PreferencesRepository;
@@ -106,6 +107,8 @@ public class ItemLauncher {
} else if (mediaManager.hasAudioQueueItems() && rowItem instanceof AudioQueueItem && pos < mediaManager.getCurrentAudioQueueSize()) {
Timber.d("playing audio queue item");
mediaManager.playFrom(pos);
} else if (adapter.getQueryType() == QueryType.Search) {
mediaManager.playNow(context, rowItem.getBaseItem());
} else {
Timber.d("playing audio item");
List<BaseItemDto> audioItemsAsList = new ArrayList<>();

View File

@@ -9,14 +9,16 @@ import android.os.Handler;
import android.os.Looper;
import android.widget.Toast;
import com.google.android.exoplayer2.DefaultRenderersFactory;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.PlaybackException;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.source.ProgressiveMediaSource;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import androidx.annotation.OptIn;
import androidx.media3.common.MediaItem;
import androidx.media3.common.PlaybackException;
import androidx.media3.common.Player;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.datasource.DataSource;
import androidx.media3.datasource.DefaultDataSourceFactory;
import androidx.media3.exoplayer.DefaultRenderersFactory;
import androidx.media3.exoplayer.ExoPlayer;
import androidx.media3.exoplayer.source.ProgressiveMediaSource;
import org.jellyfin.androidtv.R;
import org.jellyfin.androidtv.constant.QueryType;
@@ -53,6 +55,7 @@ import java.util.Random;
import kotlin.Lazy;
import timber.log.Timber;
@OptIn(markerClass = UnstableApi.class)
public class LegacyMediaManager implements MediaManager {
private Context context;

View File

@@ -18,25 +18,28 @@ import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.OptIn;
import androidx.media3.common.C;
import androidx.media3.common.Format;
import androidx.media3.common.MediaItem;
import androidx.media3.common.PlaybackException;
import androidx.media3.common.PlaybackParameters;
import androidx.media3.common.Player;
import androidx.media3.common.Timeline;
import androidx.media3.common.TrackGroup;
import androidx.media3.common.TrackSelectionOverride;
import androidx.media3.common.TrackSelectionParameters;
import androidx.media3.common.Tracks;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.exoplayer.DefaultRenderersFactory;
import androidx.media3.exoplayer.ExoPlayer;
import androidx.media3.exoplayer.source.DefaultMediaSourceFactory;
import androidx.media3.exoplayer.trackselection.DefaultTrackSelector;
import androidx.media3.extractor.DefaultExtractorsFactory;
import androidx.media3.extractor.ts.TsExtractor;
import androidx.media3.ui.AspectRatioFrameLayout;
import androidx.media3.ui.PlayerView;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.DefaultRenderersFactory;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.PlaybackException;
import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.Tracks;
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory;
import com.google.android.exoplayer2.extractor.ts.TsExtractor;
import com.google.android.exoplayer2.source.DefaultMediaSourceFactory;
import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.trackselection.TrackSelectionOverride;
import com.google.android.exoplayer2.trackselection.TrackSelectionParameters;
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
import com.google.android.exoplayer2.ui.StyledPlayerView;
import com.google.common.collect.ImmutableSet;
import org.jellyfin.androidtv.R;
@@ -58,6 +61,7 @@ import java.util.Optional;
import timber.log.Timber;
@OptIn(markerClass = UnstableApi.class)
public class VideoManager implements IVLCVout.OnNewVideoLayoutListener {
public final static int ZOOM_FIT = 0;
public final static int ZOOM_AUTO_CROP = 1;
@@ -76,7 +80,7 @@ public class VideoManager implements IVLCVout.OnNewVideoLayoutListener {
private SurfaceView mSubtitlesSurface;
private FrameLayout mSurfaceFrame;
private ExoPlayer mExoPlayer;
private StyledPlayerView mExoPlayerView;
private PlayerView mExoPlayerView;
private LibVLC mLibVLC;
private MediaPlayer mVlcPlayer;
private Media mCurrentMedia;
@@ -94,7 +98,7 @@ public class VideoManager implements IVLCVout.OnNewVideoLayoutListener {
private long mMetaDuration = -1;
private long mMetaVLCStreamStartPosition = -1;
private long lastExoPlayerPosition = -1;
private boolean nightModeEnabled = false;
private boolean nightModeEnabled;
private boolean nativeMode = false;
private boolean mSurfaceReady = false;
@@ -202,6 +206,16 @@ public class VideoManager implements IVLCVout.OnNewVideoLayoutListener {
defaultRendererFactory.setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON);
exoPlayerBuilder.setRenderersFactory(defaultRendererFactory);
DefaultTrackSelector trackSelector = new DefaultTrackSelector(context);
trackSelector.setParameters(trackSelector.buildUponParameters()
.setAudioOffloadPreferences(new TrackSelectionParameters.AudioOffloadPreferences.Builder()
.setAudioOffloadMode(TrackSelectionParameters.AudioOffloadPreferences.AUDIO_OFFLOAD_MODE_ENABLED)
.build()
)
.build()
);
exoPlayerBuilder.setTrackSelector(trackSelector);
DefaultExtractorsFactory defaultExtractorsFactory = new DefaultExtractorsFactory().setTsExtractorTimestampSearchBytes(TsExtractor.DEFAULT_TIMESTAMP_SEARCH_BYTES * 3);
exoPlayerBuilder.setMediaSourceFactory(new DefaultMediaSourceFactory(context, defaultExtractorsFactory));

View File

@@ -7,7 +7,9 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.EditorInfo
import android.view.inputmethod.InputMethodManager
import android.widget.EditText
import androidx.core.content.getSystemService
import androidx.fragment.app.Fragment
import androidx.leanback.app.RowsSupportFragment
import androidx.lifecycle.lifecycleScope
@@ -63,12 +65,23 @@ class TextSearchFragment : Fragment() {
}
private fun EditText.onSubmit(onSubmit: (String) -> Unit) {
setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_DONE) {
onSubmit(text.toString())
true
} else {
false
setOnEditorActionListener { view, actionId, _ ->
when (actionId) {
EditorInfo.IME_ACTION_DONE,
EditorInfo.IME_ACTION_SEARCH,
EditorInfo.IME_ACTION_PREVIOUS -> {
onSubmit(text.toString())
// Manually close IME to workaround focus issue with Fire TV
context.getSystemService<InputMethodManager>()
?.hideSoftInputFromWindow(view.windowToken, 0)
// Focus on search results
binding.resultsFrame.requestFocus()
true
}
else -> false
}
}
}

View File

@@ -107,7 +107,7 @@ public class InfoLayoutHelper {
if (includeRuntime) addRuntime(context, item, layout, includeEndTime);
addSeriesStatus(context, item, layout);
addRatingAndRes(context, item, mediaSourceIndex, layout);
addMediaDetails(context, audioStream, layout);
addMediaDetails(context, item, mediaSourceIndex, layout);
}
private static void addText(Context context, String text, LinearLayout layout, int maxWidth) {
@@ -392,25 +392,27 @@ public class InfoLayoutHelper {
}
}
private static void addMediaDetails(Context context, MediaStream stream, LinearLayout layout) {
private static void addMediaDetails(Context context, BaseItemDto item, int mediaSourceIndex, LinearLayout layout) {
if (stream != null) {
if (stream.getProfile() != null && stream.getProfile().contains("Dolby Atmos")) {
MediaStream audioStream = StreamHelper.getFirstAudioStream(item, mediaSourceIndex);
if (audioStream != null) {
if (audioStream.getProfile() != null && audioStream.getProfile().contains("Dolby Atmos")) {
addBlockText(context, layout, "ATMOS");
addSpacer(context, layout, " ");
} else if (stream.getProfile() != null && stream.getProfile().contains("DTS:X")) {
} else if (audioStream.getProfile() != null && audioStream.getProfile().contains("DTS:X")) {
addBlockText(context, layout, "DTS:X");
addSpacer(context, layout, " ");
} else {
String codec = null;
if (stream.getProfile() != null && stream.getProfile().contains("DTS-HD")) {
if (audioStream.getProfile() != null && audioStream.getProfile().contains("DTS-HD")) {
codec = "DTS-HD";
} else if (stream.getCodec() != null && stream.getCodec().trim().length() > 0) {
switch (stream.getCodec().toLowerCase()) {
} else if (audioStream.getCodec() != null &audioStream.getCodec().trim().length() > 0) {
switch (audioStream.getCodec().toLowerCase()) {
case "dca": codec = "DTS"; break;
case "eac3": codec = "DD+"; break;
case "ac3": codec = "DD"; break;
default: codec = stream.getCodec().toUpperCase();
default: codec = audioStream.getCodec().toUpperCase();
}
}
if (codec != null) {
@@ -418,8 +420,8 @@ public class InfoLayoutHelper {
addSpacer(context, layout, " ");
}
}
if (stream.getChannelLayout() != null && stream.getChannelLayout().trim().length() > 0) {
addBlockText(context, layout, stream.getChannelLayout().toUpperCase());
if (audioStream.getChannelLayout() != null && audioStream.getChannelLayout().trim().length() > 0) {
addBlockText(context, layout, audioStream.getChannelLayout().toUpperCase());
addSpacer(context, layout, " ");
}
}

View File

@@ -1,6 +1,7 @@
package org.jellyfin.androidtv.util.apiclient;
import android.content.Context;
import android.provider.MediaStore;
import org.jellyfin.androidtv.R;
import org.jellyfin.androidtv.auth.repository.SessionRepository;
@@ -8,6 +9,8 @@ import org.jellyfin.androidtv.preference.UserPreferences;
import org.jellyfin.androidtv.ui.navigation.Destination;
import org.jellyfin.androidtv.ui.navigation.NavigationRepository;
import org.jellyfin.androidtv.ui.playback.MediaManager;
import org.jellyfin.androidtv.ui.playback.PlaybackController;
import org.jellyfin.androidtv.ui.playback.PlaybackControllerContainer;
import org.jellyfin.androidtv.ui.playback.PlaybackLauncher;
import org.jellyfin.androidtv.ui.playback.VideoQueueManager;
import org.jellyfin.androidtv.util.TimeUtils;
@@ -298,7 +301,12 @@ public class PlaybackHelper {
default:
KoinJavaComponent.<VideoQueueManager>get(VideoQueueManager.class).setCurrentVideoQueue(response);
Destination destination = playbackLauncher.getPlaybackDestination(item.getType(), pos);
navigationRepository.navigate(destination);
PlaybackController playbackController = KoinJavaComponent.<PlaybackControllerContainer>get(PlaybackControllerContainer.class).getPlaybackController();
navigationRepository.navigate(
destination,
playbackController != null && playbackController.hasFragment()
);
}
}
});

View File

@@ -7,6 +7,7 @@ import org.jellyfin.androidtv.util.Utils
import org.jellyfin.androidtv.util.profile.ProfileHelper.audioDirectPlayProfile
import org.jellyfin.androidtv.util.profile.ProfileHelper.deviceAV1CodecProfile
import org.jellyfin.androidtv.util.profile.ProfileHelper.deviceHevcCodecProfile
import org.jellyfin.androidtv.util.profile.ProfileHelper.deviceHevcLevelCodecProfiles
import org.jellyfin.androidtv.util.profile.ProfileHelper.h264VideoLevelProfileCondition
import org.jellyfin.androidtv.util.profile.ProfileHelper.h264VideoProfileCondition
import org.jellyfin.androidtv.util.profile.ProfileHelper.max1080pProfileConditions
@@ -191,8 +192,9 @@ class ExoPlayerProfile(
)
)
})
// HEVC profile
// HEVC profiles
add(deviceHevcCodecProfile)
addAll(deviceHevcLevelCodecProfiles)
// AV1 profile
add(deviceAV1CodecProfile)
// Limit video resolution support for older devices
@@ -203,7 +205,8 @@ class ExoPlayerProfile(
})
}
// Audio channel profile
add(maxAudioChannelsCodecProfile(channels = 8))
if (!Utils.downMixAudio(context)) add(maxAudioChannelsCodecProfile(channels = 8))
else add(maxAudioChannelsCodecProfile(channels = 2))
}.toTypedArray()
subtitleProfiles = arrayOf(

View File

@@ -5,6 +5,7 @@ import org.jellyfin.androidtv.constant.Codec
import org.jellyfin.androidtv.util.Utils
import org.jellyfin.androidtv.util.profile.ProfileHelper.audioDirectPlayProfile
import org.jellyfin.androidtv.util.profile.ProfileHelper.deviceHevcCodecProfile
import org.jellyfin.androidtv.util.profile.ProfileHelper.deviceHevcLevelCodecProfiles
import org.jellyfin.androidtv.util.profile.ProfileHelper.h264VideoLevelProfileCondition
import org.jellyfin.androidtv.util.profile.ProfileHelper.h264VideoProfileCondition
import org.jellyfin.androidtv.util.profile.ProfileHelper.maxAudioChannelsCodecProfile
@@ -116,21 +117,22 @@ class LibVlcProfile(
photoDirectPlayProfile
)
codecProfiles = arrayOf(
codecProfiles = buildList {
// HEVC profile
deviceHevcCodecProfile,
add(deviceHevcCodecProfile)
addAll(deviceHevcLevelCodecProfiles)
// H264 profile
CodecProfile().apply {
add(CodecProfile().apply {
type = CodecType.Video
codec = Codec.Video.H264
conditions = arrayOf(
h264VideoProfileCondition,
h264VideoLevelProfileCondition
)
},
})
// Audio channel profile
maxAudioChannelsCodecProfile(channels = 8)
)
add(maxAudioChannelsCodecProfile(channels = 8))
}.toTypedArray()
containerProfiles = arrayOf(
ContainerProfile().apply {

View File

@@ -24,7 +24,15 @@ class MediaCodecCapabilitiesTest {
fun supportsHevcMain10(): Boolean = hasDecoder(
MediaFormat.MIMETYPE_VIDEO_HEVC,
CodecProfileLevel.HEVCProfileMain10,
CodecProfileLevel.HEVCMainTierLevel5
CodecProfileLevel.HEVCMainTierLevel4
)
fun getHevcMainLevel(): String = getHevcLevelString(
CodecProfileLevel.HEVCProfileMain
)
fun getHevcMain10Level(): String = getHevcLevelString(
CodecProfileLevel.HEVCProfileMain10
)
fun supportsAVCHigh10(): Boolean = hasDecoder(
@@ -33,6 +41,48 @@ class MediaCodecCapabilitiesTest {
CodecProfileLevel.AVCLevel4
)
private fun getHevcLevelString(profile: Int) : String {
val level = getDecoderLevel(MediaFormat.MIMETYPE_VIDEO_HEVC, profile)
when {
level < CodecProfileLevel.HEVCMainTierLevel1 -> return "0"
level < CodecProfileLevel.HEVCMainTierLevel2 -> return "30"
level < CodecProfileLevel.HEVCMainTierLevel21 -> return "60"
level < CodecProfileLevel.HEVCMainTierLevel3 -> return "63"
level < CodecProfileLevel.HEVCMainTierLevel31 -> return "90"
level < CodecProfileLevel.HEVCMainTierLevel4 -> return "93"
level < CodecProfileLevel.HEVCMainTierLevel41 -> return "120"
level < CodecProfileLevel.HEVCMainTierLevel5 -> return "123"
level < CodecProfileLevel.HEVCMainTierLevel51 -> return "150"
level < CodecProfileLevel.HEVCMainTierLevel52 -> return "153"
level < CodecProfileLevel.HEVCMainTierLevel6 -> return "156"
level < CodecProfileLevel.HEVCMainTierLevel61 -> return "180"
level < CodecProfileLevel.HEVCMainTierLevel62 -> return "183"
else -> return "186"
}
}
private fun getDecoderLevel(mime: String, profile: Int) : Int {
var maxLevel = 0
for (info in mediaCodecList.codecInfos) {
if (info.isEncoder) continue
try {
val capabilities = info.getCapabilitiesForType(mime)
for (profileLevel in capabilities.profileLevels) {
if (profileLevel.profile == profile) {
maxLevel = maxOf(maxLevel, profileLevel.level)
}
}
} catch (e: IllegalArgumentException) {
Timber.w(e)
}
}
return maxLevel
}
private fun hasDecoder(mime: String, profile: Int, level: Int): Boolean {
for (info in mediaCodecList.codecInfos) {
if (info.isEncoder) continue

View File

@@ -105,6 +105,56 @@ object ProfileHelper {
}
}
val deviceHevcLevelCodecProfiles by lazy {
buildList {
if (MediaTest.supportsHevc()) {
add(CodecProfile().apply {
type = CodecType.Video
codec = Codec.Video.HEVC
applyConditions = arrayOf(
ProfileCondition(
ProfileConditionType.Equals,
ProfileConditionValue.VideoProfile,
"Main"
)
)
conditions = arrayOf(
ProfileCondition(
ProfileConditionType.LessThanEqual,
ProfileConditionValue.VideoLevel,
MediaTest.getHevcMainLevel()
)
)
})
if (MediaTest.supportsHevcMain10()) {
add(CodecProfile().apply {
type = CodecType.Video
codec = Codec.Video.HEVC
applyConditions = arrayOf(
ProfileCondition(
ProfileConditionType.Equals,
ProfileConditionValue.VideoProfile,
"Main 10"
)
)
conditions = arrayOf(
ProfileCondition(
ProfileConditionType.LessThanEqual,
ProfileConditionValue.VideoLevel,
MediaTest.getHevcMain10Level()
)
)
})
}
}
}
}
val h264VideoLevelProfileCondition by lazy {
ProfileCondition(
ProfileConditionType.LessThanEqual,

View File

@@ -12,6 +12,7 @@
MODIFIED to add Jellyfin specifics
-->
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:lb="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="androidx.leanback.widget.BaseCardView">
@@ -26,6 +27,7 @@
tools:ignore="UnusedAttribute"
tools:visibility="visible">
<!-- Crossfading is broken with this specific layout, especially when using thumbnails -->
<org.jellyfin.androidtv.ui.AsyncImageView
android:id="@+id/main_image"
android:layout_width="wrap_content"
@@ -33,6 +35,7 @@
android:background="@drawable/shape_card_image_background"
android:contentDescription="@null"
android:scaleType="centerCrop"
app:crossfadeDuration="0"
lb:layout_viewType="main"
tools:src="@drawable/app_logo" />

View File

@@ -31,7 +31,7 @@
</FrameLayout>
<com.google.android.exoplayer2.ui.StyledPlayerView
<androidx.media3.ui.PlayerView
android:id="@+id/exoPlayerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
@@ -55,6 +55,7 @@
android:gravity="center"
android:textColor="@color/white"
android:textSize="28sp"
android:textDirection="ltr"
app:strokeWidth="5.0"
tools:text="Subtitles" />

View File

@@ -15,7 +15,7 @@ androidx-core = "1.12.0"
androidx-fragment = "1.6.2"
androidx-leanback = "1.1.0-rc01"
androidx-lifecycle = "2.6.2"
androidx-media3 = "1.2.0"
androidx-media3 = "1.2.1"
androidx-preference = "1.2.1"
androidx-recyclerview = "1.3.2"
androidx-startup = "1.1.1"
@@ -25,10 +25,9 @@ androidx-work = "2.9.0"
blurhash = "0.2.0"
coil = "2.5.0"
detekt = "1.23.4"
exoplayer = "2.19.1"
gson = "2.8.9"
jellyfin-androidx-media = "1.2.1+1"
jellyfin-apiclient = "v0.7.10"
jellyfin-exoplayer-ffmpegextension = "2.19.1+1"
jellyfin-sdk = "1.4.6"
junit = "4.13.2"
koin = "3.5.0"
@@ -79,6 +78,7 @@ androidx-lifecycle-runtime = { module = "androidx.lifecycle:lifecycle-runtime-kt
androidx-lifecycle-service = { module = "androidx.lifecycle:lifecycle-service", version.ref = "androidx-lifecycle" }
androidx-lifecycle-viewmodel = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "androidx-lifecycle" }
androidx-media3-session = { module = "androidx.media3:media3-session", version.ref = "androidx-media3" }
androidx-media3-ui = { module = "androidx.media3:media3-ui", version.ref = "androidx-media3" }
androidx-preference = { module = "androidx.preference:preference-ktx", version.ref = "androidx-preference" }
androidx-recyclerview = { module = "androidx.recyclerview:recyclerview", version.ref = "androidx-recyclerview" }
androidx-startup = { module = "androidx.startup:startup-runtime", version.ref = "androidx-startup" }
@@ -93,8 +93,9 @@ koin-androidx-compose = { module = "io.insert-koin:koin-androidx-compose", versi
koin-androidx-workmanager = { module = "io.insert-koin:koin-androidx-workmanager", version.ref = "koin" }
# Media players
exoplayer = { module = "com.google.android.exoplayer:exoplayer", version.ref = "exoplayer" }
jellyfin-exoplayer-ffmpegextension = { group = "org.jellyfin.exoplayer", name = "exoplayer-ffmpeg-extension", version.ref = "jellyfin-exoplayer-ffmpegextension" }
androidx-media3-exoplayer = { module = "androidx.media3:media3-exoplayer", version.ref = "androidx-media3" }
androidx-media3-exoplayer-hls = { module = "androidx.media3:media3-exoplayer-hls", version.ref = "androidx-media3" }
jellyfin-androidx-media3-ffmpeg-decoder = { group = "org.jellyfin.media3", name = "media3-ffmpeg-decoder", version.ref = "jellyfin-androidx-media" }
libvlc = { module = "org.videolan.android:libvlc-all", version.ref = "libvlc" }
# Markwon

View File

@@ -93,14 +93,15 @@ internal class MediaSessionPlayer(
val previous = state.queue.peekPrevious()
val next = state.queue.peekNext()
listOfNotNull(previous, current, next)
val playlist = listOfNotNull(previous, current, next)
.distinctBy { it.metadata.mediaId }
.map {
MediaItemData.Builder(requireNotNull(it.metadata.mediaId)).apply {
setMediaItem(it.metadata.toMediaItem())
setDurationUs(it.metadata.duration?.inWholeMicroseconds ?: C.TIME_UNSET)
}.build()
}.let(::setPlaylist)
}
setPlaylist(playlist)
setPlaybackState(when (state.playState.value) {
PlayState.STOPPED -> STATE_IDLE
@@ -109,7 +110,7 @@ internal class MediaSessionPlayer(
PlayState.ERROR -> STATE_ENDED
})
setCurrentMediaItemIndex(if (previous == null) 0 else 1)
setCurrentMediaItemIndex(if (previous == null || playlist.size <= 1) 0 else 1)
} else {
setPlaybackState(STATE_IDLE)
setCurrentMediaItemIndex(C.INDEX_UNSET)

View File

@@ -91,18 +91,14 @@ class DefaultPlayerQueueState(
override fun replaceQueue(queue: Queue) {
Timber.d("Queue changed, setting index to 0")
_current.value = queue
orderIndexProvider.reset()
if (orderIndexProvider != defaultOrderIndexProvider) defaultOrderIndexProvider.reset()
currentQueueIndicesPlayed.clear()
coroutineScope.launch {
when (state.playbackOrder.value) {
PlaybackOrder.DEFAULT -> setIndex(0)
PlaybackOrder.RANDOM,
PlaybackOrder.SHUFFLE -> setIndex((0 until queue.size).random())
}
_current.value = queue
orderIndexProvider.reset()
if (orderIndexProvider != defaultOrderIndexProvider) defaultOrderIndexProvider.reset()
currentQueueIndicesPlayed.clear()
setIndex(0)
}
}

View File

@@ -20,13 +20,13 @@ internal class ShuffleOrderIndexProvider : OrderIndexProvider {
} else {
val remainingIndices = (0..queue.size).filterNot {
it in playedIndices || it in nextIndices
}.shuffled()
}
List(min(amount, remainingItemsSize)) { i ->
if (i <= nextIndices.lastIndex) {
if (i < nextIndices.lastIndex) {
nextIndices[i]
} else {
val index = remainingIndices[i - nextIndices.size]
val index = remainingIndices.random()
nextIndices.add(index)
index
}

View File

@@ -29,9 +29,12 @@ dependencies {
implementation(libs.kotlinx.coroutines)
implementation(libs.kotlinx.coroutines.guava)
// AndroidX
implementation(libs.androidx.core)
// ExoPlayer
implementation(libs.exoplayer)
implementation(libs.jellyfin.exoplayer.ffmpegextension)
implementation(libs.androidx.media3.exoplayer)
implementation(libs.jellyfin.androidx.media3.ffmpeg.decoder)
// Logging
implementation(libs.timber)

View File

@@ -1,13 +1,22 @@
package org.jellyfin.playback.exoplayer
import android.app.ActivityManager
import android.content.Context
import com.google.android.exoplayer2.C
import com.google.android.exoplayer2.DefaultRenderersFactory
import com.google.android.exoplayer2.ExoPlayer
import com.google.android.exoplayer2.MediaItem
import com.google.android.exoplayer2.PlaybackException
import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.video.VideoSize
import androidx.annotation.OptIn
import androidx.core.content.getSystemService
import androidx.media3.common.C
import androidx.media3.common.MediaItem
import androidx.media3.common.PlaybackException
import androidx.media3.common.Player
import androidx.media3.common.TrackSelectionParameters
import androidx.media3.common.VideoSize
import androidx.media3.common.util.UnstableApi
import androidx.media3.exoplayer.DefaultRenderersFactory
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.exoplayer.source.DefaultMediaSourceFactory
import androidx.media3.exoplayer.trackselection.DefaultTrackSelector
import androidx.media3.extractor.DefaultExtractorsFactory
import androidx.media3.extractor.ts.TsExtractor
import org.jellyfin.playback.core.backend.BasePlayerBackend
import org.jellyfin.playback.core.mediastream.MediaStream
import org.jellyfin.playback.core.mediastream.PlayableMediaStream
@@ -21,22 +30,40 @@ import kotlin.time.Duration
import kotlin.time.Duration.Companion.ZERO
import kotlin.time.Duration.Companion.milliseconds
@OptIn(UnstableApi::class)
class ExoPlayerBackend(
private val context: Context,
) : BasePlayerBackend() {
companion object {
const val TS_SEARCH_BYTES_LM = TsExtractor.TS_PACKET_SIZE * 1800
const val TS_SEARCH_BYTES_HM = TsExtractor.DEFAULT_TIMESTAMP_SEARCH_BYTES
}
private var currentStream: PlayableMediaStream? = null
private val exoPlayer by lazy {
val renderersFactory = DefaultRenderersFactory(context).apply {
setEnableDecoderFallback(true)
setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON)
}
ExoPlayer.Builder(context, renderersFactory)
ExoPlayer.Builder(context)
.setRenderersFactory(DefaultRenderersFactory(context).apply {
setEnableDecoderFallback(true)
setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON)
})
.setTrackSelector(DefaultTrackSelector(context).apply {
setParameters(buildUponParameters().apply {
setAudioOffloadPreferences(TrackSelectionParameters.AudioOffloadPreferences.DEFAULT.buildUpon().apply {
setAudioOffloadMode(TrackSelectionParameters.AudioOffloadPreferences.AUDIO_OFFLOAD_MODE_ENABLED)
}.build())
})
})
.setMediaSourceFactory(DefaultMediaSourceFactory(
context,
DefaultExtractorsFactory().apply {
val isLowRamDevice = context.getSystemService<ActivityManager>()?.isLowRamDevice == true
setTsExtractorTimestampSearchBytes(when (isLowRamDevice) {
true -> TS_SEARCH_BYTES_LM
false -> TS_SEARCH_BYTES_HM
})
}
))
.setPauseAtEndOfMediaItems(true)
.build()
.also { player -> player.addListener(PlayerListener()) }

View File

@@ -1,6 +1,6 @@
package org.jellyfin.playback.exoplayer.mapping
import com.google.android.exoplayer2.util.MimeTypes
import androidx.media3.common.MimeTypes
fun getFfmpegAudioMimeType(codec: String): String {
return ffmpegAudioMimeTypes.getOrDefault(codec, codec)

View File

@@ -1,6 +1,8 @@
package org.jellyfin.playback.exoplayer.mapping
import com.google.android.exoplayer2.util.MimeTypes
import androidx.annotation.OptIn
import androidx.media3.common.MimeTypes
import androidx.media3.common.util.UnstableApi
fun getFfmpegContainerMimeType(codec: String): String {
// Find in container mime type list
@@ -13,6 +15,7 @@ fun getFfmpegContainerMimeType(codec: String): String {
}
}
@OptIn(UnstableApi::class)
val ffmpegContainerMimeTypes = mapOf(
"aac" to MimeTypes.AUDIO_AAC,
"alaw" to MimeTypes.AUDIO_ALAW,

View File

@@ -1,6 +1,8 @@
package org.jellyfin.playback.exoplayer.support
import com.google.android.exoplayer2.RendererCapabilities
import androidx.annotation.OptIn
import androidx.media3.common.util.UnstableApi
import androidx.media3.exoplayer.RendererCapabilities
enum class AdaptiveSupport {
SEAMLESS,
@@ -8,6 +10,7 @@ enum class AdaptiveSupport {
NOT_SUPPORTED;
companion object {
@OptIn(UnstableApi::class)
fun fromFlags(flags: Int) = when (RendererCapabilities.getAdaptiveSupport(flags)) {
RendererCapabilities.ADAPTIVE_SEAMLESS -> SEAMLESS
RendererCapabilities.ADAPTIVE_NOT_SEAMLESS -> NOT_SEAMLESS

View File

@@ -1,6 +1,8 @@
package org.jellyfin.playback.exoplayer.support
import com.google.android.exoplayer2.RendererCapabilities
import androidx.annotation.OptIn
import androidx.media3.common.util.UnstableApi
import androidx.media3.exoplayer.RendererCapabilities
enum class DecoderSupport {
PRIMARY,
@@ -8,6 +10,7 @@ enum class DecoderSupport {
FALLBACK;
companion object {
@OptIn(UnstableApi::class)
fun fromFlags(flags: Int) = when (RendererCapabilities.getDecoderSupport(flags)) {
RendererCapabilities.DECODER_SUPPORT_PRIMARY -> PRIMARY
RendererCapabilities.DECODER_SUPPORT_FALLBACK_MIMETYPE -> FALLBACK_MIMETYPE

View File

@@ -1,9 +1,11 @@
package org.jellyfin.playback.exoplayer.support
import com.google.android.exoplayer2.BaseRenderer
import com.google.android.exoplayer2.ExoPlayer
import com.google.android.exoplayer2.Format
import com.google.android.exoplayer2.RendererCapabilities
import androidx.annotation.OptIn
import androidx.media3.common.Format
import androidx.media3.common.util.UnstableApi
import androidx.media3.exoplayer.BaseRenderer
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.exoplayer.RendererCapabilities
import org.jellyfin.playback.core.support.PlaySupportReport
data class ExoPlayerPlaySupportReport(
@@ -16,6 +18,7 @@ data class ExoPlayerPlaySupportReport(
override val canPlay = format == FormatSupport.HANDLED || tunneling == true || hardwareAcceleration == true
companion object {
@OptIn(UnstableApi::class)
fun fromFlags(flags: Int): ExoPlayerPlaySupportReport = ExoPlayerPlaySupportReport(
format = FormatSupport.fromFlags(RendererCapabilities.getFormatSupport(flags)),
adaptive = AdaptiveSupport.fromFlags(RendererCapabilities.getAdaptiveSupport(flags)),
@@ -24,12 +27,14 @@ data class ExoPlayerPlaySupportReport(
decoder = DecoderSupport.fromFlags(RendererCapabilities.getDecoderSupport(flags)),
)
@OptIn(UnstableApi::class)
private fun tunnelingFromFlags(flags: Int) = when (RendererCapabilities.getTunnelingSupport(flags)) {
RendererCapabilities.TUNNELING_SUPPORTED -> true
RendererCapabilities.TUNNELING_NOT_SUPPORTED -> false
else -> null
}
@OptIn(UnstableApi::class)
private fun hardwareAccelerationFromFlags(flags: Int) = when (RendererCapabilities.getHardwareAccelerationSupport(flags)) {
RendererCapabilities.HARDWARE_ACCELERATION_SUPPORTED -> true
RendererCapabilities.HARDWARE_ACCELERATION_NOT_SUPPORTED -> false
@@ -41,6 +46,7 @@ data class ExoPlayerPlaySupportReport(
fun ExoPlayer.getPlaySupportReport(format: Format): ExoPlayerPlaySupportReport =
ExoPlayerPlaySupportReport.fromFlags(supportsFormat(format))
@OptIn(UnstableApi::class)
fun ExoPlayer.supportsFormat(format: Format): Int {
var capabilities = 0

View File

@@ -1,6 +1,9 @@
package org.jellyfin.playback.exoplayer.support
import com.google.android.exoplayer2.RendererCapabilities
import androidx.annotation.OptIn
import androidx.media3.common.C
import androidx.media3.common.util.UnstableApi
import androidx.media3.exoplayer.RendererCapabilities
enum class FormatSupport {
HANDLED,
@@ -10,12 +13,13 @@ enum class FormatSupport {
UNSUPPORTED_TYPE;
companion object {
@OptIn(UnstableApi::class)
fun fromFlags(flags: Int) = when (RendererCapabilities.getFormatSupport(flags)) {
RendererCapabilities.FORMAT_HANDLED -> HANDLED
RendererCapabilities.FORMAT_EXCEEDS_CAPABILITIES -> EXCEEDS_CAPABILITIES
RendererCapabilities.FORMAT_UNSUPPORTED_DRM -> UNSUPPORTED_DRM
RendererCapabilities.FORMAT_UNSUPPORTED_SUBTYPE -> UNSUPPORTED_SUBTYPE
RendererCapabilities.FORMAT_UNSUPPORTED_TYPE -> UNSUPPORTED_TYPE
C.FORMAT_HANDLED -> HANDLED
C.FORMAT_EXCEEDS_CAPABILITIES -> EXCEEDS_CAPABILITIES
C.FORMAT_UNSUPPORTED_DRM -> UNSUPPORTED_DRM
C.FORMAT_UNSUPPORTED_SUBTYPE -> UNSUPPORTED_SUBTYPE
C.FORMAT_UNSUPPORTED_TYPE -> UNSUPPORTED_TYPE
else -> null
}
}

View File

@@ -1,11 +1,14 @@
package org.jellyfin.playback.exoplayer.support
import com.google.android.exoplayer2.Format
import androidx.annotation.OptIn
import androidx.media3.common.Format
import androidx.media3.common.util.UnstableApi
import org.jellyfin.playback.core.mediastream.MediaStream
import org.jellyfin.playback.core.mediastream.MediaStreamAudioTrack
import org.jellyfin.playback.exoplayer.mapping.getFfmpegAudioMimeType
import org.jellyfin.playback.exoplayer.mapping.getFfmpegContainerMimeType
@OptIn(UnstableApi::class)
fun MediaStream.toFormat() = Format.Builder().also { f ->
f.setId(identifier)
f.setContainerMimeType(getFfmpegContainerMimeType(container.format))