Skip to content

Commit

Permalink
docs: add intent specification
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Oct 5, 2022
1 parent ab9c3eb commit 0eb3cdc
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 14 deletions.
15 changes: 2 additions & 13 deletions app/src/main/java/is/xyz/mpv/MPVActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -282,18 +282,7 @@ class MPVActivity : AppCompatActivity(), MPVLib.EventObserver, TouchGesturesObse
}

private fun finishWithResult(code: Int, includeTimePos: Boolean = false) {
/*
* Description of result intent (inspired by https://mx.j2inter.com/api)
* ============================
* action: constant "is.xyz.mpv.MPVActivity.result"
* code:
* RESULT_CANCELED: playback did not start due to an error
* RESULT_OK: playback ended normally or user exited
* data: same URI mpv was started with
* extras:
* "position" (int): last playback pos in milliseconds, missing if playback finished normally
* "duration" (int): total playback length in milliseconds, missing if playback finished normally
*/
// Refer to http://mpv-android.github.io/mpv-android/intent.html
// FIXME: should track end-file events to accurately report OK vs CANCELED
val result = Intent(RESULT_INTENT)
result.data = if (intent.data?.scheme == "file") null else intent.data
Expand Down Expand Up @@ -917,7 +906,7 @@ class MPVActivity : AppCompatActivity(), MPVLib.EventObserver, TouchGesturesObse
if (extras == null)
return

// API reference: http://mx.j2inter.com/api (partially implemented)
// Refer to http://mpv-android.github.io/mpv-android/intent.html
if (extras.getByte("decode_mode") == 2.toByte())
onloadCommands.add(arrayOf("set", "file-local-options/hwdec", "no"))
if (extras.containsKey("subs")) {
Expand Down
3 changes: 2 additions & 1 deletion docs/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
}
body {
font-family: system-ui, -apple-system, "Segoe UI", "Roboto",
"Ubuntu", "Cantarell", "Noto Sans", sans-serif
"Ubuntu", "Cantarell", "Noto Sans", sans-serif;
line-height: 1.25;
}
pre, code {
font-family: "Menlo", "Consolas", "Roboto Mono", "Ubuntu Monospace",
Expand Down
1 change: 1 addition & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ <h1 style="color: #520053;">mpv-android</h1>

<h4>Page Index</h4>
<ul>
<li><a href="intent.html">Intent specification</a></li>
<li><a href="privacy.html">Privacy Policy</a></li>
</ul>
</body>
Expand Down
83 changes: 83 additions & 0 deletions docs/intent.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<!DOCTYPE html>
<html>
<head>
<title>Intent specification</title>
<link href="default.css" rel="stylesheet">
</head>
<body>
<h2 id="intent">Intent</h2>

<p>You can use an intent to launch the playback activity of mpv-android.</p>

<p>package: <code>is.xyz.mpv</code><br>
action: <code>android.intent.action.VIEW</code></p>
<ul>
<li>
data: URI with schemes <code>rtmp, rtmps, rtp, rtsp, mms, mmst, mmsh, tcp, udp</code>
(as supported by <a href="http://ffmpeg.org/ffmpeg-protocols.html" target="_blank" rel="noopener">FFmpeg</a>)<br>
<i>or</i>
</li>
<li>
data: URI with schemes <code>content, file, http, https</code><br>
type: <code>video/*</code> or <code>audio/*</code><br>
<i>or</i>
</li>
<li>
data: URI with schemes <code>http, https</code> and file extension <code>mkv, mp4, webm, mov, flac, mp3, ogg, m3u, m3u8</code><br>
</li>
</ul>
<p>If you need to force an URL to be opened in mpv even though file extension
may not match set the MIME type to <code>video/any</code>.<br>
extras: <i>(optional)</i></p>
<ul>
<li>
<code>decode_mode</code> (Byte): if set to 2, hardware decoding will be disabled
</li>
<li>
<code>subs</code> (ParcelableArray of Uri): list of subtitle files to be added as additional tracks
</li>
<li>
<code>subs.enable</code> (ParcelableArray of Uri): specifies which of the subtitles should be selected by default, subset of previous array
</li>
<li>
<code>position</code> (Int): starting point of video playback in milliseconds
</li>
</ul>

<details>
<summary>Examples</summary>
<div style="margin-left: 1em;">
<h5>Kotlin</h5>
<pre>val intent = Intent(Intent.ACTION_VIEW)
intent.setDataAndType(Uri.parse("https://example.org/media.png"), "video/any")
intent.setPackage("is.xyz.mpv")
startActivity(intent)</pre>
<h5>HTML (Chrome)</h5>
<pre>&lt;a href="intent://example.org/media.png#Intent;type=video/any;package=is.xyz.mpv;scheme=https;end;"&gt;Click me&lt;/a&gt;</pre>
<h5>Command line (e.g. adb or Termux)</h5>
<pre>am start -a android.intent.action.VIEW -t video/any -p is.xyz.mpv -d "https://example.org/media.png" </pre>
</div>
</details>

<h2 id="result-intent">Result Intent</h2>

<p>Once the activity exits mpv-android will deliver a result intent back to the invoker.<br>
action: <code>is.xyz.mpv.MPVActivity.result</code><br>
code:</p>
<ul>
<li><code>RESULT_CANCELED</code>: playback did not start due to an error</li>
<li><code>RESULT_OK</code>: playback ended normally or user exited</li>
</ul>
<p>data: the same URI mpv was launched with<br>
extras:</p>
<ul>
<li><code>position</code> (Int): last playback position in milliseconds, missing if playback finished normally</li>
<li><code>duration</code> (Int): total media length in milliseconds, missing if playback finished normally</li>
</ul>

<h2 id="notes">Notes</h2>

<p>This API was inspired by the counterpart in <a href="http://mx.j2inter.com/api" target="_blank" rel="noopener">MXPlayer</a>.<br>
Note that only Java code is powerful enough to use the full features of this specification or receive result intents.</p>
</body>
</html>

0 comments on commit 0eb3cdc

Please sign in to comment.