Skip to content

Commit

Permalink
Implement skip action
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsvanvelzen committed Oct 5, 2024
1 parent 16921e5 commit bcc7d1b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,8 @@ public void run() {
mVideoManager.start();
}

PlaybackControllerHelperKt.applyMediaSegments(this, item);

dataRefreshService.getValue().setLastPlayedItem(item);
reportingHelper.getValue().reportStart(item, mbPos);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package org.jellyfin.androidtv.ui.playback

import androidx.annotation.OptIn
import androidx.lifecycle.lifecycleScope
import androidx.media3.common.util.UnstableApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.jellyfin.androidtv.ui.playback.segment.MediaSegmentAction
import org.jellyfin.androidtv.ui.playback.segment.MediaSegmentRepository
import org.jellyfin.sdk.api.client.ApiClient
import org.jellyfin.sdk.api.client.extensions.liveTvApi
import org.jellyfin.sdk.model.api.BaseItemDto
import org.jellyfin.sdk.model.api.MediaSegmentDto
import org.jellyfin.sdk.model.extensions.ticks
import org.koin.android.ext.android.inject
import java.util.UUID

Expand All @@ -22,3 +29,43 @@ fun PlaybackController.getLiveTvChannel(
}
}
}

fun PlaybackController.applyMediaSegments(
item: BaseItemDto
) {
val mediaSegmentRepository by fragment.inject<MediaSegmentRepository>()

fragment.lifecycleScope.launch {
val mediaSegments = runCatching {
mediaSegmentRepository.getSegmentsForItem(item)
}.getOrNull().orEmpty()

for (mediaSegment in mediaSegments) {
val action = mediaSegmentRepository.getMediaSegmentAction(mediaSegment)

when (action) {
MediaSegmentAction.SKIP -> addSkipAction(mediaSegment)

// TODO implement these
MediaSegmentAction.ASK_TO_SKIP -> TODO()
MediaSegmentAction.MUTE -> TODO()

MediaSegmentAction.NOTHING -> Unit
}
}
}
}

@OptIn(UnstableApi::class)
private fun PlaybackController.addSkipAction(mediaSegment: MediaSegmentDto) {
mVideoManager.mExoPlayer
.createMessage { messageType: Int, payload: Any? ->
fragment.lifecycleScope.launch(Dispatchers.Main) {
seek(mediaSegment.endTicks.ticks.inWholeMilliseconds)
}
}
.setPosition(mediaSegment.startTicks.ticks.inWholeMilliseconds)
.setPayload(mediaSegment)
.setDeleteAfterDelivery(false)
.send()
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class VideoManager {
private Limiter mLimiter;
private PlaybackControllerNotifiable mPlaybackControllerNotifiable;
private PlaybackOverlayFragmentHelper _helper;
private ExoPlayer mExoPlayer;
public ExoPlayer mExoPlayer;

Check notice

Code scanning / Android Lint

Unknown nullness Note

Unknown nullability; explicitly declare as @Nullable or @NonNull to improve Kotlin interoperability; see https://developer.android.com/kotlin/interop#nullability_annotations
private PlayerView mExoPlayerView;
private Handler mHandler = new Handler();

Expand Down

0 comments on commit bcc7d1b

Please sign in to comment.