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(custombuttons): Add documentation for custom buttons and mpvkt.l… #162

Merged
merged 2 commits into from
Nov 28, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.automirrored.outlined.HelpOutline
import androidx.compose.material.icons.filled.Add
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ExtendedFloatingActionButton
Expand Down Expand Up @@ -48,6 +49,7 @@ fun CustomButtonsScreen(
onClickMoveUp: (CustomButtonEntity) -> Unit,
onClickMoveDown: (CustomButtonEntity) -> Unit,
onTogglePrimary: (CustomButtonEntity) -> Unit,
onClickFaq: () -> Unit,
onNavigateBack: () -> Unit,
) {
val lazyListState = rememberLazyListState()
Expand All @@ -62,6 +64,11 @@ fun CustomButtonsScreen(
Icon(Icons.AutoMirrored.Default.ArrowBack, null)
}
},
actions = {
IconButton(onClick = { onClickFaq() }) {
Icon(Icons.AutoMirrored.Outlined.HelpOutline, null)
}
}
)
},
floatingActionButton = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package live.mehiz.mpvkt.ui.custombuttons
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.platform.LocalUriHandler
import cafe.adriel.voyager.navigator.LocalNavigator
import cafe.adriel.voyager.navigator.currentOrThrow
import kotlinx.collections.immutable.toImmutableList
Expand All @@ -21,6 +22,7 @@ object CustomButtonsScreen : Screen() {
@Composable
override fun Content() {
val navigator = LocalNavigator.currentOrThrow
val uriHandler = LocalUriHandler.current
val viewModel = koinViewModel<CustomButtonsScreenViewModel>()
val playerPreferences = koinInject<PlayerPreferences>()

Expand All @@ -37,6 +39,7 @@ object CustomButtonsScreen : Screen() {
onTogglePrimary = viewModel::togglePrimary,
onClickMoveUp = viewModel::moveUp,
onClickMoveDown = viewModel::moveDown,
onClickFaq = { uriHandler.openUri(CUSTOM_BUTTONS_DOC_URL) },
onNavigateBack = navigator::pop,
)

Expand Down Expand Up @@ -82,3 +85,5 @@ sealed interface CustomButtonDialog {
data class Edit(val customButton: CustomButtonEntity) : CustomButtonDialog
data class Delete(val customButton: CustomButtonEntity) : CustomButtonDialog
}

private const val CUSTOM_BUTTONS_DOC_URL = "https://github.com/abdallahmehiz/mpvKt/blob/main/docs/CUSTOMBUTTONS.rst"
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,11 @@ class PlayerActivity : AppCompatActivity() {
appendLine("function button${button.id}()")
appendLine(button.content)
appendLine("end")
appendLine("mp.register_script_message('call_button${button.id}', button${button.id})")
appendLine("mp.register_script_message('call_button_${button.id}', button${button.id})")
appendLine("function button${button.id}long()")
appendLine(button.longPressContent)
appendLine("end")
appendLine("mp.register_script_message('call_button${button.id}long', button${button.id}long)")
appendLine("mp.register_script_message('call_button_${button.id}_long', button${button.id}long)")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -583,9 +583,9 @@ fun Float.normalize(inMin: Float, inMax: Float, outMin: Float, outMax: Float): F
}

fun CustomButtonEntity.execute() {
MPVLib.command(arrayOf("script-message", "call_button$id"))
MPVLib.command(arrayOf("script-message", "call_button_$id"))
}

fun CustomButtonEntity.executeLongClick() {
MPVLib.command(arrayOf("script-message", "call_button${id}long"))
MPVLib.command(arrayOf("script-message", "call_button_${id}_long"))
}
46 changes: 46 additions & 0 deletions docs/CUSTOMBUTTONS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
CUSTOM BUTTONS
==============

Custom buttons provides a way to execute lua code by pressing a button in the player. mpvKt also provides an interface to interact with some parts of the player.

The interface is defined in a file placed in the ``scripts`` directory and can be accessed through the ``mpvkt`` table.

Lua interface
-------------

``mpvkt.show_text(text)``
Display a message on the player.

``mpvkt.hide_ui()``
Hide the player UI.

``mpvkt.show_ui()``
Show the player UI.

``mpvkt.toggle_ui()``
Toggle the visibility of the player UI.

``mpvkt.show_subtitle_settings()``
Show the subtitle settings sheet.

``mpvkt.show_subtitle_delay()``
Show the subtitle delay sheet.

``mpvkt.show_audio_delay()``
Show the subtitle delay sheet.

``mpvkt.show_video_filters()``
Show the video filters sheet.

``mpvkt.set_button_title(text)``
Change the title for the primary custom button.

``mpvkt.reset_button_title(text)``
Reset the title for the primary custom button.

Call a custom button from key input or from lua
-----------------------------------------------

Custom buttons can be called from key inputs or from other lua scripts, if so desired. This is done through ``script-message`` with the message ``call_button_<id>`` for normal press and ``call_button_<id>_long`` for long press, where ``<id>`` is the id for the button (shown in top right when editing a button).

Example: ``a script-message call_button_1`` will call the button of id 1 when ``a`` is pressed, if added to ``input.conf``.