Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PlaybackForwardingActivity for bridging to new playback module #1092

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,8 @@
android:name=".ui.playback.nextup.NextUpActivity"
android:noHistory="true"
android:screenOrientation="landscape" />

<!-- Playback Rewrite - Temporary -->
<activity android:name=".ui.playback.rewrite.PlaybackForwardingActivity" />
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.jellyfin.androidtv.ui.playback
import android.app.Activity
import org.jellyfin.androidtv.preference.UserPreferences
import org.jellyfin.androidtv.preference.constant.PreferredVideoPlayer
import org.jellyfin.androidtv.ui.playback.rewrite.PlaybackForwardingActivity
import org.jellyfin.apiclient.model.dto.BaseItemType

interface PlaybackLauncher {
Expand Down Expand Up @@ -32,8 +33,7 @@ class GarbagePlaybackLauncher(
}
}

// TODO: Move to playback module
class RewritePlaybackLauncher : PlaybackLauncher {
override fun useExternalPlayer(itemType: BaseItemType?) = false
override fun getPlaybackActivityClass(itemType: BaseItemType?) = TODO("Not yet implemented")
override fun getPlaybackActivityClass(itemType: BaseItemType?) = PlaybackForwardingActivity::class.java
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package org.jellyfin.androidtv.ui.playback.rewrite

import android.os.Bundle
import android.widget.Toast
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.lifecycleScope
import org.jellyfin.androidtv.di.userApiClient
import org.jellyfin.androidtv.ui.playback.MediaManager
import org.jellyfin.apiclient.model.dto.BaseItemDto
import org.jellyfin.apiclient.model.dto.BaseItemType
import org.jellyfin.sdk.api.operations.UserLibraryApi
import org.jellyfin.sdk.model.serializer.toUUIDOrNull
import org.koin.android.ext.android.get
import org.koin.android.ext.android.inject
import timber.log.Timber

class PlaybackForwardingActivity : FragmentActivity() {
private val mediaManager by inject<MediaManager>()
private val userLibraryApi by lazy {
UserLibraryApi(get(userApiClient))
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

// Try find the item id
val itemId = findItem()?.id?.toUUIDOrNull()

if (itemId == null) {
Toast.makeText(
this,
"Could not find item to play (itemId=null)",
Toast.LENGTH_LONG
).show()
finishAfterTransition()
return
}

lifecycleScope.launchWhenCreated {
// Get fresh info from API in SDK format
val item by userLibraryApi.getItem(itemId = itemId)

// Log info
Toast.makeText(
this@PlaybackForwardingActivity,
"Found item of type ${item.type} - ${item.name} (${item.id}",
Toast.LENGTH_LONG
).show()
Timber.i(item.toString())

// TODO: Create queue, send to new playback manager, start new player UI
finishAfterTransition()
}
}

private fun findItem(): BaseItemDto? {
var first: BaseItemDto? = null
var best: BaseItemDto? = null

for (item in mediaManager.currentVideoQueue) {
if (first == null) first = item
if (best == null && item.baseItemType !== BaseItemType.Trailer) best = item

if (first != null && best != null) break
}

return best ?: first
}
}