Pick several audio sources at once, with the apps' own icons

The phone had no way to choose which apps a stream carries: the
studio's audio picker added one source and closed, and Android's app
list had names only. The picker now marks what is mixed in already
(stream.audio_sources) and switches a source on or off with a tap, so
several apps (and the microphone, desktop audio, test tones) are picked
in one go; Done closes it. Android's launchable apps come with their
icons: Kotlin draws each app's icon once per installed version into a
96 px PNG in the cache and hands over its path (AudioApp::icon), which
the picker shows. The shared window's audio is not offered on Android,
which shares the whole screen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
selikhovandClaude Opus 5.5 committed 2026-10-03 18:30:04 +03:00
1 parent 1eabbb4704
commit ecb0e11668
7 files changed
+144 -47

No files matched your search

@@ -4,7 +4,11 @@ import android.Manifest
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.content.pm.ResolveInfo
import android.graphics.Bitmap
import android.graphics.Canvas
import android.os.Build
import java.io.File
/**
* What the Rust library (crates/voelin-android/src/bridge.rs) calls, from any
@@ -88,7 +92,10 @@ object Bridge {
ScreenCaptureService.stopInput(id)
}
/** Launchable apps other than us, as "label<TAB>package" lines sorted by label. */
/**
* Launchable apps other than us, as "label<TAB>package<TAB>icon" lines
* sorted by label; the icon is a PNG in our cache (empty if it has none).
*/
@JvmStatic
fun launchableApps(): String {
val pm = app.packageManager
@@ -100,12 +107,37 @@ object Bridge {
pm.queryIntentActivities(launcher, 0)
}
val separators = Regex("[\t\n]")
val icons = File(app.cacheDir, "app-icons").apply { mkdirs() }
return activities
.map { it.activityInfo.packageName to it.loadLabel(pm).toString() }
.filter { it.first != app.packageName }
.distinctBy { it.first }
.sortedBy { it.second.lowercase() }
.joinToString("\n") { (packageName, label) -> label.replace(separators, " ") + "\t" + packageName }
.filter { it.activityInfo.packageName != app.packageName }
.distinctBy { it.activityInfo.packageName }
.map { Triple(it, it.activityInfo.packageName, it.loadLabel(pm).toString()) }
.sortedBy { it.third.lowercase() }
.joinToString("\n") { (info, packageName, label) ->
val icon = appIcon(pm, info, packageName, icons)?.path.orEmpty()
label.replace(separators, " ") + "\t" + packageName + "\t" + icon
}
}
private const val ICON_SIZE = 96
/** The app's icon as a PNG in `dir`, drawn once per installed version. */
private fun appIcon(pm: PackageManager, info: ResolveInfo, packageName: String, dir: File): File? {
val version = info.activityInfo.applicationInfo.sourceDir?.let { File(it).lastModified() } ?: 0L
val file = File(dir, "$packageName-$version.png")
if (file.exists()) return file
return try {
val bitmap = Bitmap.createBitmap(ICON_SIZE, ICON_SIZE, Bitmap.Config.ARGB_8888)
info.loadIcon(pm).apply { setBounds(0, 0, ICON_SIZE, ICON_SIZE) }.draw(Canvas(bitmap))
file.outputStream().use { bitmap.compress(Bitmap.CompressFormat.PNG, 100, it) }
bitmap.recycle()
// Icons of earlier versions.
dir.listFiles { f -> f.name.startsWith("$packageName-") && f.name != file.name }?.forEach { it.delete() }
file
} catch (e: Exception) {
file.delete()
null
}
}
/** The cameras, as CameraCapture.list describes them. */
+11 -8
View File
@@ -181,8 +181,9 @@ pub fn stop_audio_input(id: u64) -> Result<()> {
})
}
/// Launchable apps other than ours, as `(label, package)`, sorted by label.
pub fn launchable_apps() -> Result<Vec<(String, String)>> {
/// Launchable apps other than ours, as `(label, package, icon)`, sorted by
/// label; `icon` is the path of a PNG in the app's cache, or empty.
pub fn launchable_apps() -> Result<Vec<(String, String, String)>> {
let lines = with_bridge(|env, class| {
let value = env
.call_static_method(
@@ -201,15 +202,17 @@ pub fn launchable_apps() -> Result<Vec<(String, String)>> {
Ok(parse_apps(&lines))
}
/// `label<TAB>package` lines.
fn parse_apps(lines: &str) -> Vec<(String, String)> {
/// `label<TAB>package<TAB>icon` lines (the icon may be missing).
fn parse_apps(lines: &str) -> Vec<(String, String, String)> {
lines
.lines()
.filter_map(|line| {
let (label, package) = line.split_once('\t')?;
let package = package.trim();
let label = if label.trim().is_empty() { package } else { label.trim() };
(!package.is_empty()).then(|| (label.to_owned(), package.to_owned()))
let mut parts = line.split('\t');
let label = parts.next()?.trim();
let package = parts.next()?.trim();
let icon = parts.next().unwrap_or_default().trim();
let label = if label.is_empty() { package } else { label };
(!package.is_empty()).then(|| (label.to_owned(), package.to_owned(), icon.to_owned()))
})
.collect()
}
+2 -1
View File
@@ -196,9 +196,10 @@ impl AudioProvider for PlaybackAudio {
match bridge::launchable_apps() {
Ok(apps) => apps
.into_iter()
.map(|(name, package)| AudioApp {
.map(|(name, package, icon)| AudioApp {
name,
binary: Some(package),
icon: (!icon.is_empty()).then_some(icon),
..AudioApp::default()
})
.collect(),
+2 -2
View File
@@ -73,8 +73,8 @@ pub(crate) fn wire(bridge: &StudioBridge) {
bridge.on_list_audio(|| {
with_app(|app| app.studio_list_audio());
});
bridge.on_add_audio(|i| {
with_app(|app| app.studio_add_audio(index(i)));
bridge.on_toggle_audio(|i| {
with_app(|app| app.studio_toggle_audio(index(i)));
});
bridge.on_set_gain(|i, db, done| {
with_app(|app| app.studio_set_gain(index(i), db, done));
+45 -14
View File
@@ -12,7 +12,7 @@
//! VecModels) and get the same values; their callbacks come here
//! (bind/studio.rs). Commands go to the studio through one task, in order.
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::rc::Rc;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Weak};
@@ -831,7 +831,12 @@ impl App {
.iter()
.map(|(id, _)| {
let (channel, server) = self.studio_destination_parts(*id);
StudioPick { name: channel.into(), detail: server.into(), kind: "server".into() }
StudioPick {
name: channel.into(),
detail: server.into(),
kind: "server".into(),
..Default::default()
}
})
.collect();
vm::list::sync(&self.studio.models.destinations, &rows);
@@ -1453,6 +1458,7 @@ impl App {
name: name.into(),
detail: detail.into(),
kind: icon.into(),
..Default::default()
};
let mut picks: Vec<(Pick, StudioPick)> = Vec::new();
let source = |name: &str, kind: SourceKind| Pick::Source { name: name.into(), kind };
@@ -1611,11 +1617,24 @@ impl App {
let settings = self.studio_settings();
let current = settings.get(&STREAM_AUDIO_SOURCES);
let mut picks: Vec<(Pick, StudioPick)> = Vec::new();
let mut add = |setting: AudioSourceSetting, name: String, detail: String| {
let (_, _, kind) = vm::studio::audio_label(&setting.kind);
let row = StudioPick { name: name.into(), detail: detail.into(), kind: kind.into() };
picks.push((Pick::Audio(setting), row));
};
let mut add =
|setting: AudioSourceSetting, name: String, detail: String, icon: Option<&str>| {
let (_, _, kind) = vm::studio::audio_label(&setting.kind);
let row = StudioPick {
name: name.into(),
detail: detail.into(),
kind: kind.into(),
// An application's own icon, when it gave a file (Android
// does; a desktop icon theme name is left out).
icon: icon
.map(Path::new)
.filter(|p| p.is_absolute())
.map(crate::images::file)
.unwrap_or_default(),
selected: current.iter().any(|s| s.kind == setting.kind),
};
picks.push((Pick::Audio(setting), row));
};
let fixed = [
(AudioSourceKindSetting::Microphone, "Microphone", "What you say in voice, cleaned up"),
(
@@ -1630,14 +1649,17 @@ impl App {
),
];
for (kind, name, detail) in fixed {
if !current.iter().any(|s| s.kind == kind) {
add(AudioSourceSetting::new(kind), name.into(), detail.into());
// A phone shares the whole screen: there is no window's app.
if cfg!(target_os = "android") && kind == AudioSourceKindSetting::Window {
continue;
}
add(AudioSourceSetting::new(kind), name.into(), detail.into(), None);
}
if self.demo_ui {
for frequency in [330, 550] {
for frequency in [440, 660, 330] {
let kind = AudioSourceKindSetting::Synthetic { frequency };
add(AudioSourceSetting::new(kind), "Test tone".into(), format!("{frequency} Hz"));
let detail = format!("{frequency} Hz");
add(AudioSourceSetting::new(kind), "Test tone".into(), detail, None);
}
} else {
if self.studio.apps.is_none() {
@@ -1654,7 +1676,7 @@ impl App {
.media
.clone()
.unwrap_or_else(|| if app.playing { "playing".into() } else { String::new() });
add(AudioSourceSetting::new(kind), app.name, detail);
add(AudioSourceSetting::new(kind), app.name, detail, app.icon.as_deref());
}
}
self.studio_set_picks(picks);
@@ -1670,10 +1692,19 @@ impl App {
self.studio_refresh_audio();
}
pub(crate) fn studio_add_audio(&mut self, index: usize) {
/// Mix a picked source in, or take it out if it is (the picker
/// chooses several at once), and mark the picks again.
pub(crate) fn studio_toggle_audio(&mut self, index: usize) {
let Some(Pick::Audio(setting)) = self.studio.picks.get(index) else { return };
let setting = setting.clone();
self.studio_audio_sources(|sources| sources.push(setting));
self.studio_audio_sources(|sources| {
if sources.iter().any(|s| s.kind == setting.kind) {
sources.retain(|s| s.kind != setting.kind);
} else {
sources.push(setting);
}
});
self.studio_list_audio();
}
/// While dragging the gain goes to the mixer directly; at the end it is
+39 -14
View File
@@ -1926,8 +1926,8 @@ component SourceDialog inherits Modal {
component PickDialog inherits Modal {
in property <string> kind;
callback done();
title: kind == "screen" ? @tr("Share a screen") : kind == "window" ? @tr("Share a window") : kind == "camera" ? @tr("Add a camera") : @tr("Add an audio source");
subtitle: kind == "audio" ? @tr("Mixed into the stream's audio.") : @tr("Added to the live scene.");
title: kind == "screen" ? @tr("Share a screen") : kind == "window" ? @tr("Share a window") : kind == "camera" ? @tr("Add a camera") : @tr("Audio sources");
subtitle: kind == "audio" ? @tr("Mixed into the stream's audio. Pick as many as you like.") : @tr("Added to the live scene.");
icon: StudioKinds.icon(kind == "audio" ? "microphone" : kind);
card-width: 520px;
card-height: 540px;
@@ -1948,24 +1948,22 @@ component PickDialog inherits Modal {
accessible-role: AccessibleRole.button;
accessible-label: pick.name;
accessible-description: pick.detail;
accessible-action-default => {
if root.kind == "audio" {
StudioBridge.add-audio(i);
} else {
StudioBridge.add-picked(root.kind, i);
}
root.done();
}
accessible-checkable: root.kind == "audio";
accessible-checked: pick.selected;
accessible-action-default => { pick-touch.pick(); }
pick-touch := TouchArea {
mouse-cursor: MouseCursor.pointer;
clicked => {
// Audio sources are switched on and off (several at once);
// the rest is added and the picker closes.
function pick() {
if root.kind == "audio" {
StudioBridge.add-audio(i);
StudioBridge.toggle-audio(i);
} else {
StudioBridge.add-picked(root.kind, i);
root.done();
}
root.done();
}
clicked => { self.pick(); }
}
HorizontalLayout {
padding-left: Theme.space-3;
@@ -1977,10 +1975,15 @@ component PickDialog inherits Modal {
y: (parent.height - self.height) / 2;
border-radius: Theme.radius-md;
background: Theme.surface-3;
Icon {
if pick.icon.width == 0: Icon {
source: StudioKinds.icon(pick.kind);
size: 18px;
}
if pick.icon.width > 0: Image {
width: 28px;
height: 28px;
source: pick.icon;
}
}
VerticalLayout {
alignment: center;
@@ -1997,9 +2000,31 @@ component PickDialog inherits Modal {
overflow: elide;
}
}
if root.kind == "audio": Rectangle {
width: 24px;
height: 24px;
y: (parent.height - self.height) / 2;
border-radius: 12px;
background: pick.selected ? Theme.accent : transparent;
border-width: pick.selected ? 0 : 1.5px;
border-color: Theme.border-strong;
if pick.selected: Icon {
source: Icons.check;
size: 16px;
tint: Theme.on-accent;
}
}
}
}
}
if root.kind == "audio": HorizontalLayout {
alignment: end;
Button {
kind: ButtonKind.primary;
text: @tr("Done");
clicked => { root.done(); }
}
}
}
// Rename a scene.
+7 -2
View File
@@ -78,6 +78,10 @@ export struct StudioPick {
detail: string,
// For the icon: monitor, window, portal, camera, microphone, desktop, app, tone
kind: string,
// The application's own icon (audio), if it has one.
icon: image,
// Already mixed in (audio): picking it again takes it out.
selected: bool,
}
// The header, the preview's badges and the bottom bar.
@@ -223,9 +227,10 @@ export global StudioBridge {
// The phone layout's source cards: screen, camera, window.
callback main-source(string);
// Audio: fill `picks` with what can be added; add, change, remove.
// Audio: fill `picks` with what can be mixed in (marking what is);
// mix one in or take it out, change, remove.
callback list-audio();
callback add-audio(int);
callback toggle-audio(int);
// While dragging (`done` false) and at the end.
callback set-gain(int, float, bool);
callback toggle-mute(int);