Skip to content

Your Android phone and your Windows PC, working as one. Local-first, end-to-end encrypted, no account.

Play on phone: the phone's Watch screen

Bee6266336f0793
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index 0cdf299..3e96634 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -325,6 +325,14 @@
android:foregroundServiceType="camera" />
<!-- Continuity Camera: takes a photo or scans a document for a paired PC. -->
+ <!-- Play on phone: a PC player's picture and sound, full screen. -->
+ <activity
+ android:name=".ui.watch.WatchActivity"
+ android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize|keyboard|keyboardHidden"
+ android:exported="false"
+ android:launchMode="singleTop"
+ android:theme="@style/Theme.Nectarlink" />
+
<activity
android:name=".camera.ContinuityCameraActivity"
android:exported="false"
diff --git a/android/app/src/main/kotlin/app/nectarlink/android/core/Core.kt b/android/app/src/main/kotlin/app/nectarlink/android/core/Core.kt
index 4ad1f7c..2c48c95 100644
--- a/android/app/src/main/kotlin/app/nectarlink/android/core/Core.kt
+++ b/android/app/src/main/kotlin/app/nectarlink/android/core/Core.kt
@@ -97,6 +97,15 @@ class Core(context: Context, private val scope: CoroutineScope) : EventListener
ringer,
phoneMedia,
onLink = { pc, url -> LinkNotifications.show(this.context, _state.value.nameOf(pc).orEmpty(), url) },
+ onWatch = { pc, player, title ->
+ app.nectarlink.android.media.WatchOffers.show(
+ this.context,
+ pc,
+ _state.value.nameOf(pc).orEmpty(),
+ player,
+ title,
+ )
+ },
onTask = { pc, task ->
app.nectarlink.android.notifications.TaskNotifications.show(
this.context,
@@ -1592,6 +1601,8 @@ class Core(context: Context, private val scope: CoroutineScope) : EventListener
/** What this phone offers PCs (docs/protocol/capabilities.md). */
private fun capabilities(notificationAccess: Boolean): List<String> =
CLIPBOARD_CAPABILITIES +
+ // Play on phone: shows a PC's playback, streamed from the PC.
+ listOf("media.watch") +
toggles.capabilities() +
(if (notificationAccess) NOTIFICATION_CAPABILITIES + MEDIA_CAPABILITIES else emptyList()) +
(if (notificationAccess && NotificationListener.canReadSensitive(context)) listOf("notify.sensitive") else emptyList()) +
diff --git a/android/app/src/main/kotlin/app/nectarlink/android/core/PhonePlatform.kt b/android/app/src/main/kotlin/app/nectarlink/android/core/PhonePlatform.kt
index 257ef50..3c38c3d 100644
--- a/android/app/src/main/kotlin/app/nectarlink/android/core/PhonePlatform.kt
+++ b/android/app/src/main/kotlin/app/nectarlink/android/core/PhonePlatform.kt
@@ -61,6 +61,8 @@ internal class PhonePlatform(
private val media: PhoneMedia,
/** Shows a link a PC sent: (PC's ID, link) → shown. */
private val onLink: (String, String) -> Boolean,
+ /** Shows a PC's Play on phone offer: (PC's ID, player, title) → shown. */
+ private val onWatch: (String, String, String?) -> Boolean,
/** Shows or updates a watched task from a PC: (PC's ID, task) → shown. */
private val onTask: (String, TaskNotify) -> Boolean,
/** The phone's calls (created after this). */
@@ -103,6 +105,9 @@ internal class PhonePlatform(
override fun openLink(fromId: String, url: String): Boolean = onLink(fromId, url)
+ override fun watchOffered(fromId: String, player: String, title: String?): Boolean =
+ onWatch(fromId, player, title)
+
override fun taskNotify(fromId: String, task: TaskNotify): Boolean = onTask(fromId, task)
override fun openPhoto(id: String): FileToSend? = RecentPhotos.open(context, id)
diff --git a/android/app/src/main/kotlin/app/nectarlink/android/links/LinkNotifications.kt b/android/app/src/main/kotlin/app/nectarlink/android/links/LinkNotifications.kt
index daaf2dd..fe01b20 100644
--- a/android/app/src/main/kotlin/app/nectarlink/android/links/LinkNotifications.kt
+++ b/android/app/src/main/kotlin/app/nectarlink/android/links/LinkNotifications.kt
@@ -25,7 +25,8 @@ import app.nectarlink.core.trackingSearchUrl
* in a notification on the same channel.
*/
object LinkNotifications {
- private const val CHANNEL = "links"
+ /** Also Play on phone's offers ([app.nectarlink.android.media.WatchOffers]). */
+ internal const val CHANNEL = "links"
private const val TAG = "link"
private const val CLIP_TAG = "clip_suggestion"
private const val CLIP_NOTIFICATION_ID = 0x434C4950 // "CLIP"
diff --git a/android/app/src/main/kotlin/app/nectarlink/android/media/PcMedia.kt b/android/app/src/main/kotlin/app/nectarlink/android/media/PcMedia.kt
index ea2e397..ae78208 100644
--- a/android/app/src/main/kotlin/app/nectarlink/android/media/PcMedia.kt
+++ b/android/app/src/main/kotlin/app/nectarlink/android/media/PcMedia.kt
@@ -63,6 +63,11 @@ class PcMedia(
var activeSeedColor: UInt? = null
private set
+ private val _playing = kotlinx.coroutines.flow.MutableStateFlow<Map<String, Boolean>>(emptyMap())
+
+ /** Whether each PC player plays, by "pc/player" (for Play on phone's controls). */
+ val playing: kotlinx.coroutines.flow.StateFlow<Map<String, Boolean>> = _playing
+
private val _summaryFlow = kotlinx.coroutines.flow.MutableStateFlow<Summary?>(null)
val summaryFlow: kotlinx.coroutines.flow.StateFlow<Summary?> = _summaryFlow
@@ -100,10 +105,14 @@ class PcMedia(
art[cacheKey] = entry
}
if (list.isEmpty()) players.remove(pc) else players[pc] = list
+ _playing.value = players.flatMap { (id, all) -> all.map { "$id/${it.id}" to it.playing } }.toMap()
render()
}
}
+ /** Asks the PC [pc]'s [player] to [action] (Play on phone's controls). */
+ fun command(pc: String, player: String, action: MediaAction) = send(pc, player, action, null)
+
private fun command(action: MediaAction, position: ULong? = null) {
val (pc, player) = shown ?: return
send(pc, player.id, action, position)
diff --git a/android/app/src/main/kotlin/app/nectarlink/android/media/WatchOffers.kt b/android/app/src/main/kotlin/app/nectarlink/android/media/WatchOffers.kt
new file mode 100644
index 0000000..351589e
--- /dev/null
+++ b/android/app/src/main/kotlin/app/nectarlink/android/media/WatchOffers.kt
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+package app.nectarlink.android.media
+
+import android.Manifest
+import android.app.PendingIntent
+import android.content.Context
+import android.content.Intent
+import android.content.pm.PackageManager
+import androidx.core.app.NotificationCompat
+import androidx.core.app.NotificationManagerCompat
+import androidx.core.content.ContextCompat
+import app.nectarlink.android.R
+import app.nectarlink.android.links.LinkNotifications
+import app.nectarlink.android.ui.watch.WatchActivity
+
+/**
+ * Play on phone: a PC offers to stream what one of its players plays. Android doesn't let an
+ * app in the background open a screen, so the offer waits in a notification (on the links
+ * channel, as links from the PC do); with NectarLink in front, the Watch screen opens at once.
+ */
+object WatchOffers {
+ private const val TAG = "watch"
+
+ /** Shows the offer; false if notifications are off and it couldn't open either. */
+ fun show(context: Context, pcId: String, pcName: String, player: String, title: String?): Boolean {
+ val from = pcName.ifEmpty { context.getString(R.string.your_pc) }
+ val watch = WatchActivity.intent(context, pcId, from, player, title)
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ // Allowed only while NectarLink is in front; otherwise Android ignores it.
+ val opened = runCatching { context.startActivity(watch) }.isSuccess
+ if (ContextCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) !=
+ PackageManager.PERMISSION_GRANTED
+ ) {
+ return opened
+ }
+ val open = PendingIntent.getActivity(
+ context,
+ "$pcId/$player".hashCode(),
+ watch,
+ PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT,
+ )
+ val text = title?.takeIf { it.isNotBlank() } ?: context.getString(R.string.watch_offer_untitled)
+ val notification = NotificationCompat.Builder(context, LinkNotifications.CHANNEL)
+ .setSmallIcon(R.drawable.ic_notification)
+ .setContentTitle(context.getString(R.string.watch_offer_title, from))
+ .setContentText(text)
+ .setContentIntent(open)
+ .addAction(0, context.getString(R.string.watch_offer_action), open)
+ .setAutoCancel(true)
+ .setTimeoutAfter(OFFER_MS)
+ .setCategory(NotificationCompat.CATEGORY_RECOMMENDATION)
+ .setPriority(NotificationCompat.PRIORITY_HIGH)
+ .build()
+ val shown = runCatching {
+ NotificationManagerCompat.from(context).notify(TAG, pcId.hashCode(), notification)
+ }.isSuccess
+ return shown || opened
+ }
+
+ /** Takes the offer's notification away (the Watch screen opened). */
+ fun dismiss(context: Context, pcId: String) {
+ runCatching { NotificationManagerCompat.from(context).cancel(TAG, pcId.hashCode()) }
+ }
+
+ /** As long as the PC keeps an offer open (docs/protocol/media.md §4). */
+ private const val OFFER_MS = 10 * 60 * 1000L
+}
diff --git a/android/app/src/main/kotlin/app/nectarlink/android/ui/remote/PcMirrorView.kt b/android/app/src/main/kotlin/app/nectarlink/android/ui/remote/PcMirrorView.kt
index dfafb9b..ac40e9c 100644
--- a/android/app/src/main/kotlin/app/nectarlink/android/ui/remote/PcMirrorView.kt
+++ b/android/app/src/main/kotlin/app/nectarlink/android/ui/remote/PcMirrorView.kt
@@ -29,6 +29,7 @@ import androidx.compose.foundation.Canvas
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.awaitEachGesture
import androidx.compose.foundation.gestures.awaitFirstDown
+import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
@@ -299,6 +300,9 @@ private fun isSystemAutoRotateOn(context: Context): Boolean =
* Decodes the PC's low-latency H.264/H.265/AV1 stream onto a single persistent [TextureView]
* across portrait and immersive landscape full-screen modes, mapping touch, drag,
* two-finger scroll, right-click, and keyboard input back to the PC.
+ *
+ * With [watch] (Play on phone), it shows what that PC player plays instead, full screen,
+ * and sends the PC nothing: a tap calls [onTap].
*/
@Composable
fun PcMirrorView(
@@ -308,6 +312,8 @@ fun PcMirrorView(
modifier: Modifier = Modifier,
isFullScreen: Boolean = false,
onFullScreenChange: (Boolean) -> Unit = {},
+ watch: String? = null,
+ onTap: () -> Unit = {},
) {
val context = LocalContext.current
val view = LocalView.current
@@ -320,7 +326,8 @@ fun PcMirrorView(
val activeConfig = mirrorConfig?.takeIf { it.pcId == pcId }
val effectiveCodec = activeConfig?.codec ?: "h264"
- var highQuality by rememberSaveable { mutableStateOf(false) }
+ // Video looks its best at 1080p; the PC's desktop starts at 720p.
+ var highQuality by rememberSaveable { mutableStateOf(watch != null) }
var showKeyboardBar by rememberSaveable { mutableStateOf(false) }
var typedText by rememberSaveable { mutableStateOf("") }
var surface by remember { mutableStateOf<Surface?>(null) }
@@ -430,7 +437,8 @@ fun PcMirrorView(
}
}
}
- if (listener.canDetectOrientation()) {
+ // Watching stays full screen, however the phone is held.
+ if (watch == null && listener.canDetectOrientation()) {
listener.enable()
}
onDispose {
@@ -441,7 +449,7 @@ fun PcMirrorView(
// Also follow configuration orientation changes when system auto-rotate is enabled
// (for example, emulator window rotation).
LaunchedEffect(configuration.orientation, autoRotateEnabled) {
- if (!autoRotateEnabled) return@LaunchedEffect
+ if (!autoRotateEnabled || watch != null) return@LaunchedEffect
if (
configuration.orientation == Configuration.ORIENTATION_LANDSCAPE &&
!isFullScreen &&
@@ -523,7 +531,7 @@ fun PcMirrorView(
"PcMirrorView",
"startPcMirror maxSize=$maxSize fps=30 bitrate=$bitrate",
)
- core.startPcMirror(pcId, maxSize = maxSize, fps = 30, bitrate = bitrate)
+ core.startPcMirror(pcId, maxSize = maxSize, fps = 30, bitrate = bitrate, watch = watch)
}
DisposableEffect(pcId) {
@@ -744,7 +752,12 @@ fun PcMirrorView(
.clip(outerShape)
.background(Color.Black)
.semantics { contentDescription = viewportDescription }
- .pointerInput(pcId) {
+ .pointerInput(pcId, watch) {
+ if (watch != null) {
+ // Watching: nothing goes to the PC.
+ detectTapGestures(onTap = { onTap() })
+ return@pointerInput
+ }
val tapSlop = viewConfiguration.touchSlop
val scrollStepPx = 16.dp.toPx().coerceAtLeast(1f)
val tapTimeoutMs = 280L
@@ -972,7 +985,7 @@ fun PcMirrorView(
}
// Expand button in the corner of the portrait viewer
- if (!isFullScreen) {
+ if (!isFullScreen && watch == null) {
IconButton(
onClick = { enterFullScreen(fromButton = true) },
colors = IconButtonDefaults.iconButtonColors(
@@ -990,7 +1003,7 @@ fun PcMirrorView(
}
// Slim overlay row in full screen: appears on tap and fades out after 3 s
- if (isFullScreen) {
+ if (isFullScreen && watch == null) {
androidx.compose.animation.AnimatedVisibility(
visible = overlayVisible,
enter = if (reducedMotion) EnterTransition.None else fadeIn(tween(180)),
@@ -1174,7 +1187,7 @@ fun PcMirrorView(
}
// Portrait action bar
- if (!isFullScreen) {
+ if (!isFullScreen && watch == null) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(8.dp),
diff --git a/android/app/src/main/kotlin/app/nectarlink/android/ui/watch/WatchActivity.kt b/android/app/src/main/kotlin/app/nectarlink/android/ui/watch/WatchActivity.kt
new file mode 100644
index 0000000..a5d9458
--- /dev/null
+++ b/android/app/src/main/kotlin/app/nectarlink/android/ui/watch/WatchActivity.kt
@@ -0,0 +1,221 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+package app.nectarlink.android.ui.watch
+
+import android.content.Context
+import android.content.Intent
+import android.os.Bundle
+import androidx.activity.ComponentActivity
+import androidx.activity.compose.setContent
+import androidx.activity.enableEdgeToEdge
+import androidx.compose.animation.AnimatedVisibility
+import androidx.compose.animation.EnterTransition
+import androidx.compose.animation.ExitTransition
+import androidx.compose.animation.core.tween
+import androidx.compose.animation.fadeIn
+import androidx.compose.animation.fadeOut
+import androidx.compose.foundation.Canvas
+import androidx.compose.foundation.background
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.size
+import androidx.compose.material3.Icon
+import androidx.compose.material3.IconButton
+import androidx.compose.material3.IconButtonDefaults
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableIntStateOf
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.setValue
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.geometry.Offset
+import androidx.compose.ui.graphics.Brush
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.StrokeCap
+import androidx.compose.ui.res.painterResource
+import androidx.compose.ui.res.stringResource
+import androidx.compose.ui.semantics.contentDescription
+import androidx.compose.ui.semantics.semantics
+import androidx.compose.ui.text.style.TextOverflow
+import androidx.compose.ui.unit.dp
+import androidx.lifecycle.compose.collectAsStateWithLifecycle
+import app.nectarlink.android.NectarlinkApplication
+import app.nectarlink.android.R
+import app.nectarlink.android.core.Core
+import app.nectarlink.android.media.WatchOffers
+import app.nectarlink.android.ui.Preferences
+import app.nectarlink.android.ui.remote.PcMirrorView
+import app.nectarlink.android.ui.theme.LocalReducedMotion
+import app.nectarlink.android.ui.theme.NectarlinkTheme
+import app.nectarlink.core.MediaAction
+import kotlinx.coroutines.delay
+
+/**
+ * Play on phone: what a PC player plays, streamed from the PC with its sound, full screen.
+ * A tap shows what it is, play and pause (on the PC's player) and close; they fade after a
+ * few seconds. Nothing else goes to the PC.
+ */
+class WatchActivity : ComponentActivity() {
+ override fun onCreate(savedInstanceState: Bundle?) {
+ enableEdgeToEdge()
+ super.onCreate(savedInstanceState)
+ val pcId = intent.getStringExtra(EXTRA_PC)
+ val player = intent.getStringExtra(EXTRA_PLAYER)
+ if (pcId == null || player == null) {
+ finish()
+ return
+ }
+ val pcName = intent.getStringExtra(EXTRA_PC_NAME).orEmpty()
+ val title = intent.getStringExtra(EXTRA_TITLE)
+ WatchOffers.dismiss(this, pcId)
+ val core = (application as NectarlinkApplication).core
+ val preferences = Preferences(this)
+ setContent {
+ val appearance by preferences.appearance.collectAsStateWithLifecycle()
+ NectarlinkTheme(appearance) {
+ WatchScreen(core, pcId, pcName, player, title, onClose = ::finish)
+ }
+ }
+ }
+
+ companion object {
+ private const val EXTRA_PC = "watch_pc"
+ private const val EXTRA_PC_NAME = "watch_pc_name"
+ private const val EXTRA_PLAYER = "watch_player"
+ private const val EXTRA_TITLE = "watch_title"
+
+ fun intent(context: Context, pcId: String, pcName: String, player: String, title: String?): Intent =
+ Intent(context, WatchActivity::class.java)
+ .putExtra(EXTRA_PC, pcId)
+ .putExtra(EXTRA_PC_NAME, pcName)
+ .putExtra(EXTRA_PLAYER, player)
+ .putExtra(EXTRA_TITLE, title)
+ }
+}
+
+@Composable
+private fun WatchScreen(
+ core: Core,
+ pcId: String,
+ pcName: String,
+ player: String,
+ title: String?,
+ onClose: () -> Unit,
+) {
+ val reducedMotion = LocalReducedMotion.current
+ val playing by core.pcMedia.playing.collectAsStateWithLifecycle()
+ val isPlaying = playing["$pcId/$player"] ?: true
+ var controls by remember { mutableStateOf(true) }
+ var shownAt by remember { mutableIntStateOf(0) }
+
+ // The controls fade a few seconds after they show or are used.
+ LaunchedEffect(controls, shownAt) {
+ if (controls) {
+ delay(CONTROLS_MS)
+ controls = false
+ }
+ }
+
+ Box(Modifier.fillMaxSize().background(Color.Black)) {
+ PcMirrorView(
+ pcId = pcId,
+ pcName = pcName,
+ core = core,
+ modifier = Modifier.fillMaxSize(),
+ isFullScreen = true,
+ onFullScreenChange = { full -> if (!full) onClose() },
+ watch = player,
+ onTap = {
+ controls = !controls
+ shownAt++
+ },
+ )
+ AnimatedVisibility(
+ visible = controls,
+ enter = if (reducedMotion) EnterTransition.None else fadeIn(tween(180)),
+ exit = if (reducedMotion) ExitTransition.None else fadeOut(tween(220)),
+ modifier = Modifier.fillMaxSize(),
+ ) {
+ Column(Modifier.fillMaxSize()) {
+ // What it is and where from, over a shade so it reads on any picture.
+ Row(
+ modifier = Modifier
+ .fillMaxWidth()
+ .background(Brush.verticalGradient(listOf(Color.Black.copy(alpha = 0.7f), Color.Transparent)))
+ .padding(horizontal = 20.dp, vertical = 14.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ horizontalArrangement = Arrangement.spacedBy(12.dp),
+ ) {
+ Column(Modifier.weight(1f)) {
+ Text(
+ text = title?.takeIf { it.isNotBlank() } ?: stringResource(R.string.watch_offer_untitled),
+ style = MaterialTheme.typography.titleMedium,
+ color = Color.White,
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis,
+ )
+ Text(
+ text = stringResource(R.string.watch_from, pcName),
+ style = MaterialTheme.typography.bodySmall,
+ color = Color.White.copy(alpha = 0.75f),
+ maxLines = 1,
+ )
+ }
+ val closeLabel = stringResource(R.string.watch_close)
+ IconButton(
+ onClick = onClose,
+ colors = IconButtonDefaults.iconButtonColors(
+ containerColor = Color.White.copy(alpha = 0.14f),
+ contentColor = Color.White,
+ ),
+ modifier = Modifier.size(40.dp).semantics { contentDescription = closeLabel },
+ ) {
+ CloseIcon()
+ }
+ }
+ Box(Modifier.weight(1f).fillMaxWidth(), contentAlignment = Alignment.Center) {
+ val label = stringResource(if (isPlaying) R.string.media_pause else R.string.media_play)
+ IconButton(
+ onClick = {
+ core.pcMedia.command(pcId, player, if (isPlaying) MediaAction.PAUSE else MediaAction.PLAY)
+ shownAt++
+ },
+ colors = IconButtonDefaults.iconButtonColors(
+ containerColor = Color.Black.copy(alpha = 0.5f),
+ contentColor = Color.White,
+ ),
+ modifier = Modifier.size(64.dp).semantics { contentDescription = label },
+ ) {
+ Icon(
+ painter = painterResource(if (isPlaying) R.drawable.ic_pause else R.drawable.ic_play),
+ contentDescription = null,
+ modifier = Modifier.size(30.dp),
+ )
+ }
+ }
+ }
+ }
+ }
+}
+
+/** An X, in the stroke style of the app's other drawn icons. */
+@Composable
+private fun CloseIcon() {
+ Canvas(Modifier.size(16.dp)) {
+ val width = 2.dp.toPx()
+ drawLine(Color.White, Offset(0f, 0f), Offset(size.width, size.height), width, StrokeCap.Round)
+ drawLine(Color.White, Offset(size.width, 0f), Offset(0f, size.height), width, StrokeCap.Round)
+ }
+}
+
+/** How long the controls stay after they show or are used. */
+private const val CONTROLS_MS = 3_000L
diff --git a/android/app/src/main/res/values-zh-rCN/strings.xml b/android/app/src/main/res/values-zh-rCN/strings.xml
index 34f9314..6a593f7 100644
--- a/android/app/src/main/res/values-zh-rCN/strings.xml
+++ b/android/app/src/main/res/values-zh-rCN/strings.xml
@@ -262,6 +262,11 @@
<string name="pc_sleeping">%1$s 正在进入睡眠。</string>
<string name="pc_actions_off">%1$s 上已对本手机关闭锁定与睡眠功能。</string>
<string name="channel_links">来自电脑的链接</string>
+ <string name="watch_offer_title">观看 %1$s 上的播放</string>
+ <string name="watch_offer_untitled">电脑上正在播放的内容</string>
+ <string name="watch_offer_action">观看</string>
+ <string name="watch_from">来自 %1$s</string>
+ <string name="watch_close">关闭</string>
<string name="link_from">来自 %1$s 的链接</string>
<string name="link_opened_on">已在 %1$s 上打开</string>
<string name="link_pick_pc">在哪台电脑上打开?</string>
diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml
index 37a71ce..fe5ebe5 100644
--- a/android/app/src/main/res/values/strings.xml
+++ b/android/app/src/main/res/values/strings.xml
@@ -270,6 +270,12 @@
<string name="pc_sleeping">%1$s is going to sleep.</string>
<string name="pc_actions_off">Locking and sleep are turned off for this phone on %1$s.</string>
<string name="channel_links">Links from your PC</string>
+ <!-- Play on phone: what a PC plays, streamed to the phone. -->
+ <string name="watch_offer_title">Watch from %1$s</string>
+ <string name="watch_offer_untitled">What\'s playing on your PC</string>
+ <string name="watch_offer_action">Watch</string>
+ <string name="watch_from">From %1$s</string>
+ <string name="watch_close">Close</string>
<string name="link_from">Link from %1$s</string>
<string name="link_opened_on">Opened on %1$s</string>
<string name="link_pick_pc">Open on which PC?</string>
diff --git a/core/nectarlink-ffi/src/lib.rs b/core/nectarlink-ffi/src/lib.rs
index ad98093..3c0b849 100644
--- a/core/nectarlink-ffi/src/lib.rs
+++ b/core/nectarlink-ffi/src/lib.rs
@@ -2581,6 +2581,10 @@ pub trait Platform: Send + Sync {
/// A paired PC sent a web link (http or https, checked) to open.
/// False if it couldn't be shown.
fn open_link(&self, from_id: String, url: String) -> bool;
+ /// Play on phone: a paired PC offers to stream what its `player` plays
+ /// (`title`). Show the offer; taking it starts PC mirroring with
+ /// `watch` set to `player`. False if it couldn't be shown.
+ fn watch_offered(&self, from_id: String, player: String, title: Option<String>) -> bool;
/// A paired PC sent an ongoing or completed task notification (`task.notify`).
/// False if it couldn't be shown.
fn task_notify(&self, from_id: String, task: TaskNotify) -> bool;
@@ -2782,6 +2786,13 @@ impl core::Platform for PlatformAdapter {
fn open_link(&self, from: &DeviceId, url: &str) -> Result<(), String> {
if self.0.open_link(from.to_string(), url.to_owned()) { Ok(()) } else { Err("not shown".into()) }
}
+ fn watch_offered(&self, from: &DeviceId, player: &str, title: Option<&str>) -> Result<(), String> {
+ if self.0.watch_offered(from.to_string(), player.to_owned(), title.map(str::to_owned)) {
+ Ok(())
+ } else {
+ Err("not shown".into())
+ }
+ }
fn task_notify(&self, from: &DeviceId, task: &core::TaskNotify) -> Result<(), String> {
if self.0.task_notify(from.to_string(), task.clone().into()) {
Ok(())