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

feat(external-player): add mpvkt #1531

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<package android:name="com.mxtech.videoplayer.pro" />
<package android:name="is.xyz.mpv" />
<package android:name="org.videolan.vlc" />
<package android:name="live.mehiz.mpvkt" />
</queries>

<application
Expand Down
27 changes: 27 additions & 0 deletions app/src/main/java/org/jellyfin/mobile/bridge/ExternalPlayer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class ExternalPlayer(
Constants.MPV_PLAYER_RESULT_ACTION -> handleMPVPlayer(resultCode, intent)
Constants.MX_PLAYER_RESULT_ACTION -> handleMXPlayer(resultCode, intent)
Constants.VLC_PLAYER_RESULT_ACTION -> handleVLCPlayer(resultCode, intent)
Constants.MPVKT_PLAYER_RESULT_ACTION -> handleMPVKTPlayer(resultCode, intent)
else -> {
if (action != null && resultCode != Activity.RESULT_CANCELED) {
Timber.d("Unknown action $action [resultCode=$resultCode]")
Expand Down Expand Up @@ -289,6 +290,29 @@ class ExternalPlayer(
}
}

private fun handleMPVKTPlayer(resultCode: Int, data: Intent) {
val player = "mpvKt Player"
when (resultCode) {
Activity.RESULT_OK -> {
val position = data.getIntExtra("position", 0)
if (position > 0) {
Timber.d("Playback stopped [player=$player, position=$position]")
notifyEvent(Constants.EVENT_TIME_UPDATE, "$position")
notifyEvent(Constants.EVENT_ENDED)
} else {
Timber.d("Playback completed [player=$player]")
notifyEvent(Constants.EVENT_TIME_UPDATE)
notifyEvent(Constants.EVENT_ENDED)
}
}
else -> {
Timber.d("Invalid state [player=$player, resultCode=$resultCode]")
notifyEvent(Constants.EVENT_CANCELED)
context.toast(R.string.external_player_unknown_error, Toast.LENGTH_LONG)
}
}
}

/**
* To ensure that the correct activity is called.
*/
Expand All @@ -303,6 +327,9 @@ class ExternalPlayer(
ExternalPlayerPackage.VLC_PLAYER -> {
ComponentName(packageName, "$packageName.StartActivity")
}
ExternalPlayerPackage.MPVKT_PLAYER -> {
ComponentName(packageName, "$packageName.ui.player.PlayerActivity")
}
else -> null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
ExternalPlayerPackage.MX_PLAYER_FREE,
ExternalPlayerPackage.MX_PLAYER_PRO,
ExternalPlayerPackage.VLC_PLAYER,
ExternalPlayerPackage.MPVKT_PLAYER,
ExternalPlayerPackage.SYSTEM_DEFAULT
})
public @interface ExternalPlayerPackage {
String MPV_PLAYER = "is.xyz.mpv";
String MX_PLAYER_FREE = "com.mxtech.videoplayer.ad";
String MX_PLAYER_PRO = "com.mxtech.videoplayer.pro";
String VLC_PLAYER = "org.videolan.vlc";
String MPVKT_PLAYER = "live.mehiz.mpvkt";
String SYSTEM_DEFAULT = "~system~";
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ class SettingsFragment : Fragment(), BackPressInterceptor {
R.string.external_player_vlc_player,
R.string.external_player_vlc_player_description,
),
SelectionItem(
ExternalPlayerPackage.MPVKT_PLAYER,
R.string.external_player_mpvkt,
R.string.external_player_mpvkt_description,
),
).filter { item ->
item.key == ExternalPlayerPackage.SYSTEM_DEFAULT || packageManager.isPackageInstalled(item.key)
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/org/jellyfin/mobile/utils/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ object Constants {
const val MPV_PLAYER_RESULT_ACTION = "is.xyz.mpv.MPVActivity.result"
const val MX_PLAYER_RESULT_ACTION = "com.mxtech.intent.result.VIEW"
const val VLC_PLAYER_RESULT_ACTION = "org.videolan.vlc.player.result"
const val MPVKT_PLAYER_RESULT_ACTION = "live.mehiz.mpvkt.ui.player.PlayerActivity.result"

// External player webapp events
const val EVENT_ENDED = "Ended"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@
<string name="external_player_mx_player_pro_description">The paid version of MX Player which provides an uninterrupted video experience.</string>
<string name="external_player_vlc_player">VLC Player</string>
<string name="external_player_vlc_player_description">Free and open source cross-platform multimedia player that plays most multimedia files.</string>
<string name="external_player_mpvkt">mpvKt Player</string>
<string name="external_player_mpvkt_description">A media player based on mpv-android aiming to provide a nicer user interface over the original.</string>
<string name="external_player_system_default">System default</string>
<string name="external_player_system_default_description">Let the system handle the player choice, some players may not be fully compatible.</string>

Expand Down