Compare commits
3
Commits
3b8918d45d
...
94485dc326
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
94485dc326 | ||
|
|
75445d06c5 | ||
|
|
448b4b8edf |
@@ -19,8 +19,8 @@ android {
|
||||
applicationId = "de.fojadrachi.playtube"
|
||||
minSdk = 26
|
||||
targetSdk = 36
|
||||
versionCode = 10
|
||||
versionName = "1.6.0"
|
||||
versionCode = 11
|
||||
versionName = "1.6.1"
|
||||
|
||||
// Update-Quelle: eigener Gitea-Server (kein GitHub/Google Play).
|
||||
buildConfigField("String", "UPDATE_SERVER", "\"https://git.fojadrachi.de\"")
|
||||
|
||||
@@ -72,6 +72,13 @@ object DiagReport {
|
||||
return listOf("absturz", "exception", "error", "fehler", "fehlgeschlagen", "failed").any { it in lower }
|
||||
}
|
||||
|
||||
/** Vermerk zum Bericht: manuell gesendet (ggf. ohne neue Einträge) oder leer. */
|
||||
fun note(manual: Boolean, noNewLines: Boolean): String = when {
|
||||
manual && noNewLines -> "manuell gesendet (keine neuen Einträge)"
|
||||
manual -> "manuell gesendet"
|
||||
else -> ""
|
||||
}
|
||||
|
||||
fun build(installId: String, version: String, androidVersion: String, device: String, lines: List<String>, note: String = ""): JSONObject =
|
||||
JSONObject()
|
||||
.put("app", "android")
|
||||
|
||||
@@ -85,17 +85,21 @@ object Diagnostics {
|
||||
if (!isEnabled(context)) return
|
||||
val now = System.currentTimeMillis()
|
||||
if (now - prefs(context).getLong(KEY_LAST_TRY, 0) < INTERVAL_MS) return
|
||||
send(context) { }
|
||||
send(context, manual = false) { }
|
||||
}
|
||||
|
||||
/** Senden; [done] bekommt (null = nichts Neues, true/false = Erfolg) auf dem Hauptthread. */
|
||||
fun send(context: Context, done: (Boolean?) -> Unit) {
|
||||
/**
|
||||
* Senden; [done] bekommt (null = nichts Neues, true/false = Erfolg) auf dem Hauptthread.
|
||||
* [manual] ("Jetzt senden"): geht auch ohne neue Logzeilen raus, dann mit dem Vermerk
|
||||
* "manuell gesendet" (Version, Gerät und Kennung reichen zum Prüfen).
|
||||
*/
|
||||
fun send(context: Context, manual: Boolean, done: (Boolean?) -> Unit) {
|
||||
val ctx = context.applicationContext
|
||||
Thread {
|
||||
val prefs = prefs(ctx)
|
||||
val text = runCatching { logFile(ctx).readText() }.getOrDefault("")
|
||||
val collected = DiagReport.collect(text, prefs.getLong(KEY_LAST_SENT, 0))
|
||||
if (collected.lines.isEmpty()) {
|
||||
if (collected.lines.isEmpty() && !manual) {
|
||||
main.post { done(null) }
|
||||
return@Thread
|
||||
}
|
||||
@@ -106,6 +110,7 @@ object Diagnostics {
|
||||
Build.VERSION.RELEASE ?: "?",
|
||||
"${Build.MANUFACTURER} ${Build.MODEL}".take(80),
|
||||
collected.lines,
|
||||
DiagReport.note(manual, collected.lines.isEmpty()),
|
||||
)
|
||||
val ok = post("${BuildConfig.JAM_SERVER}/api/diag", body.toString())
|
||||
if (ok) prefs.edit().putLong(KEY_LAST_SENT, collected.latest).apply()
|
||||
|
||||
@@ -17,6 +17,7 @@ import okhttp3.WebSocketListener
|
||||
import org.json.JSONObject
|
||||
import java.io.IOException
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlin.math.abs
|
||||
|
||||
/**
|
||||
* Playtube Jam: Verbindung zum Jam-Server und gemeinsamer Zustand fuer [JamActivity] (Anzeige)
|
||||
@@ -382,11 +383,15 @@ object JamHub {
|
||||
fun syncPlayer(probe: JSONObject): Actions {
|
||||
val s = state ?: return Actions(null, emptyList())
|
||||
val now = SystemClock.elapsedRealtime()
|
||||
val want = JamSync.target(s, clock.serverNow(System.currentTimeMillis().toDouble()))
|
||||
// Soll-Position zum Zeitpunkt der Messung in der Seite (nicht erst nach der Antwort).
|
||||
val wall = System.currentTimeMillis().toDouble()
|
||||
val sampled = probe.optDouble("now", wall).takeIf { it.isFinite() && abs(it - wall) < 5000 } ?: wall
|
||||
val want = JamSync.target(s, clock.serverNow(sampled))
|
||||
val local = JamSync.Local(
|
||||
videoId = probe.optString("id").takeIf { it.isNotEmpty() && it != "null" && !probe.isNull("id") },
|
||||
pos = probe.optDouble("t", 0.0),
|
||||
paused = probe.optBoolean("paused", true),
|
||||
rate = probe.optDouble("rate", 1.0).takeIf { it.isFinite() && it > 0 } ?: 1.0,
|
||||
)
|
||||
val duration = probe.optDouble("d", 0.0)
|
||||
val scripts = ArrayList<String>()
|
||||
@@ -477,6 +482,7 @@ object JamHub {
|
||||
expectUntil = now + 3000
|
||||
scripts.add(pause)
|
||||
}
|
||||
is JamSync.Step.Rate -> scripts.add(JamSync.rateScript(step.rate))
|
||||
}
|
||||
}
|
||||
return Actions(load, scripts)
|
||||
|
||||
@@ -13,7 +13,25 @@ import kotlin.math.max
|
||||
* paused ? position : position + (T - ref) / 1000. Negativ heisst "startet gleich".
|
||||
*/
|
||||
object JamSync {
|
||||
const val TOLERANCE_S = 1.5
|
||||
const val TOLERANCE_S = 1.0
|
||||
|
||||
/** Beim Spulen etwas vorhalten: bis das Video an der neuen Stelle spielt, vergeht Zeit. */
|
||||
const val SEEK_LEAD_S = 0.2
|
||||
private const val NUDGE_START_S = 0.08
|
||||
private const val NUDGE_STOP_S = 0.03
|
||||
private const val NUDGE_GAIN = 0.25
|
||||
private const val NUDGE_MAX = 0.08
|
||||
|
||||
/**
|
||||
* Wiedergabetempo, das eine kleine Abweichung [drift] (eigene minus Jam-Position, s) ausgleicht -
|
||||
* unhoerbar, die Tonhoehe bleibt. Einmal angefangen ([current] != 1) bis fast 0 ausgleichen.
|
||||
*/
|
||||
fun nudgeRate(drift: Double, current: Double): Double {
|
||||
val threshold = if (abs(current - 1.0) > 0.001) NUDGE_STOP_S else NUDGE_START_S
|
||||
if (!drift.isFinite() || abs(drift) < threshold) return 1.0
|
||||
val rate = (1.0 - NUDGE_GAIN * drift).coerceIn(1.0 - NUDGE_MAX, 1.0 + NUDGE_MAX)
|
||||
return Math.round(rate * 1000.0) / 1000.0
|
||||
}
|
||||
private const val CODE_ALPHABET = "ABCDEFGHJKMNPQRSTUVWXYZ23456789"
|
||||
private val VIDEO_ID = Regex("^[A-Za-z0-9_-]{11}$")
|
||||
|
||||
@@ -207,13 +225,14 @@ object JamSync {
|
||||
return Target(item.videoId, item.id, positionAt(state.playback, serverNow), state.playback.paused, item.dur)
|
||||
}
|
||||
|
||||
data class Local(val videoId: String?, val pos: Double, val paused: Boolean)
|
||||
data class Local(val videoId: String?, val pos: Double, val paused: Boolean, val rate: Double = 1.0)
|
||||
|
||||
sealed class Step {
|
||||
data class Load(val videoId: String, val pos: Double) : Step()
|
||||
data class Seek(val pos: Double) : Step()
|
||||
data object Play : Step()
|
||||
data object Pause : Step()
|
||||
data class Rate(val rate: Double) : Step()
|
||||
}
|
||||
|
||||
/** Was der eigene Player tun soll, damit er zum Jam passt. */
|
||||
@@ -233,9 +252,14 @@ object JamSync {
|
||||
if (local.pos > 0.5) steps.add(Step.Seek(0.0))
|
||||
return steps
|
||||
}
|
||||
if (abs(local.pos - want.pos) > tolerance && !(nearEnd && local.pos > want.pos)) steps.add(Step.Seek(want.pos))
|
||||
val drift = local.pos - want.pos
|
||||
val seek = abs(drift) > tolerance && !(nearEnd && local.pos > want.pos)
|
||||
if (seek) steps.add(Step.Seek(if (want.paused) want.pos else want.pos + SEEK_LEAD_S))
|
||||
if (want.paused && !local.paused) steps.add(Step.Pause)
|
||||
if (!want.paused && local.paused) steps.add(Step.Play)
|
||||
// Feinabgleich ueber das Tempo, solange beide normal laufen.
|
||||
val desired = if (!seek && !want.paused && !local.paused && !nearEnd) nudgeRate(drift, local.rate) else 1.0
|
||||
if (abs(desired - local.rate) > 0.004) steps.add(Step.Rate(desired))
|
||||
return steps
|
||||
}
|
||||
|
||||
@@ -271,6 +295,8 @@ object JamSync {
|
||||
d: api('getDuration') && player.getDuration() > 0 ? player.getDuration() : ((video && isFinite(video.duration)) ? video.duration : 0),
|
||||
paused: paused,
|
||||
ended: state === 0 || (video ? video.ended : false),
|
||||
rate: video && video.playbackRate > 0 ? video.playbackRate : 1,
|
||||
now: Date.now(),
|
||||
ad: ad,
|
||||
error: error,
|
||||
title: meta && meta.title ? meta.title : null,
|
||||
@@ -288,6 +314,14 @@ object JamSync {
|
||||
"var v=p&&p.querySelector('video')||document.querySelector('video');if(v){v.$prop();}})();"
|
||||
}
|
||||
|
||||
/** Wiedergabetempo des Players (Feinabgleich, Tonhoehe bleibt). */
|
||||
fun rateScript(rate: Double): String {
|
||||
val r = if (rate.isFinite()) rate.coerceIn(0.5, 2.0) else 1.0
|
||||
return "(function(){var p=document.getElementById('movie_player');" +
|
||||
"var v=p&&p.querySelector('video')||document.querySelector('video');" +
|
||||
"if(v){v.preservesPitch=true;v.playbackRate=$r;}})();"
|
||||
}
|
||||
|
||||
fun seekScript(seconds: Double): String {
|
||||
val s = if (seconds.isFinite()) max(0.0, seconds) else 0.0
|
||||
return "(function(){var p=document.getElementById('movie_player');var s=$s;" +
|
||||
|
||||
@@ -276,7 +276,7 @@ class MainActivity : AppCompatActivity() {
|
||||
.setView(content)
|
||||
.setPositiveButton(R.string.diag_done, null)
|
||||
.setNeutralButton(R.string.diag_send_now) { _, _ ->
|
||||
Diagnostics.send(this) { ok ->
|
||||
Diagnostics.send(this, manual = true) { ok ->
|
||||
val text = when (ok) {
|
||||
null -> R.string.diag_nothing
|
||||
true -> R.string.diag_sent
|
||||
|
||||
@@ -47,6 +47,16 @@ class DiagReportTest {
|
||||
assertEquals("[701] Zeile 701", lines.first())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun manualReportWithoutLinesHasNote() {
|
||||
assertEquals("manuell gesendet (keine neuen Einträge)", DiagReport.note(manual = true, noNewLines = true))
|
||||
assertEquals("manuell gesendet", DiagReport.note(manual = true, noNewLines = false))
|
||||
assertEquals("", DiagReport.note(manual = false, noNewLines = true))
|
||||
val report = DiagReport.build("abc123abc123", "1.6.1", "15", "Google Pixel 9", emptyList(), DiagReport.note(true, true))
|
||||
assertEquals(0, report.getJSONArray("lines").length())
|
||||
assertTrue(report.getString("note").isNotEmpty()) // sonst lehnt der Server den Bericht als leer ab
|
||||
}
|
||||
|
||||
@Test
|
||||
fun buildsReport() {
|
||||
val lines = listOf("[1] Absturz in main: java.lang.IllegalStateException", "[2] ok")
|
||||
|
||||
@@ -42,6 +42,22 @@ class JamSyncTest {
|
||||
assertNull(JamSync.videoIdFromSharedText("kein Link hier"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `gleicht kleine Abweichungen ueber das Tempo aus`() {
|
||||
val want = JamSync.Target("aaaaaaaaaaa", "i", 30.0, false, 200.0)
|
||||
fun local(pos: Double, rate: Double = 1.0, paused: Boolean = false) = JamSync.Local("aaaaaaaaaaa", pos, paused, rate)
|
||||
assertEquals(listOf(JamSync.Step.Rate(0.92)), JamSync.decide(want, local(30.4)))
|
||||
assertEquals(listOf(JamSync.Step.Rate(1.05)), JamSync.decide(want, local(29.8)))
|
||||
assertEquals(listOf(JamSync.Step.Rate(1.0)), JamSync.decide(want, local(30.01, rate = 1.05)))
|
||||
assertEquals(emptyList<JamSync.Step>(), JamSync.decide(want, local(30.05)))
|
||||
assertEquals(
|
||||
listOf(JamSync.Step.Seek(30.0 + JamSync.SEEK_LEAD_S), JamSync.Step.Rate(1.0)),
|
||||
JamSync.decide(want, local(34.0, rate = 1.08)),
|
||||
)
|
||||
assertEquals(0.988, JamSync.nudgeRate(0.05, 1.02), 1e-9)
|
||||
assertEquals(1.0, JamSync.nudgeRate(0.05, 1.0), 1e-9)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `liest Playlist-Links`() {
|
||||
assertEquals("PLabc_1", JamSync.parsePlaylistId("https://music.youtube.com/playlist?list=PLabc_1"))
|
||||
@@ -110,8 +126,8 @@ class JamSyncTest {
|
||||
@Test
|
||||
fun `spult erst ab der Toleranz`() {
|
||||
val id = "aaaaaaaaaaa"
|
||||
assertTrue(JamSync.decide(want(30.0), local(id, 31.2, false)).isEmpty())
|
||||
assertEquals(listOf(Step.Seek(30.0)), JamSync.decide(want(30.0), local(id, 34.0, false)))
|
||||
assertTrue(JamSync.decide(want(30.0), local(id, 30.05, false)).isEmpty())
|
||||
assertEquals(listOf(Step.Seek(30.0 + JamSync.SEEK_LEAD_S)), JamSync.decide(want(30.0), local(id, 34.0, false)))
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+20
-14
@@ -1,21 +1,27 @@
|
||||
## Playtube für Android 1.6.0
|
||||
## Playtube für Android 1.6.1
|
||||
|
||||
- **Diagnosedaten:** Damit Fehler schneller behoben werden, schickt Playtube Abstürze und Verbindungsfehler
|
||||
(ohne Cookies, Anmeldedaten, Suchanfragen, Songtitel oder Video-IDs) an den Playtube-Server; gespeichert
|
||||
wird 30 Tage. Beim ersten Start erscheint ein Hinweis, abschalten geht jederzeit über das neue
|
||||
**Zahnrad** am rechten Rand. Details: playtube-ppp-eula.pages.dev/playtube/privacy/#diag
|
||||
- **„Jetzt senden“ schickt immer einen Bericht:** Bisher passierte nach einer frischen Installation nichts
|
||||
(„Keine neuen Einträge“). Jetzt geht auch ohne neue Einträge ein kurzer Bericht mit App-Version, Gerät
|
||||
und dem Vermerk „manuell gesendet“ raus – so lässt sich prüfen, ob der Versand klappt.
|
||||
- **Jam genauer synchron:** Kleine Abweichungen werden unhörbar über ein leicht angepasstes Tempo ausgeglichen
|
||||
(die Tonhöhe bleibt gleich); gesprungen wird erst ab 1 Sekunde Abweichung und mit Vorhalt.
|
||||
|
||||
Alles Weitere wie in 1.5.0 (Playlists und Alben im Jam, Songs laufen automatisch weiter). Voraussetzung:
|
||||
Android 8.0 oder neuer.
|
||||
Neu in 1.6.0: Diagnosedaten (Abstürze und Verbindungsfehler, ohne Cookies, Anmeldedaten, Suchanfragen oder
|
||||
Songtitel), abschaltbar über das Zahnrad am rechten Rand. Details: playtube-ppp-eula.pages.dev/playtube/privacy/#diag
|
||||
|
||||
Voraussetzung: Android 8.0 oder neuer.
|
||||
|
||||
---
|
||||
|
||||
## Playtube for Android 1.6.0
|
||||
## Playtube for Android 1.6.1
|
||||
|
||||
- **Diagnostic data:** to fix bugs faster, Playtube sends crashes and connection errors (no cookies, sign-in data,
|
||||
searches, song titles or video IDs) to the Playtube server; reports are kept for 30 days. A notice is shown on
|
||||
first start, and you can turn it off at any time via the new **gear** button on the right edge.
|
||||
Details: playtube-ppp-eula.pages.dev/playtube/privacy/#diag
|
||||
- **"Send now" always sends a report:** after a fresh install nothing happened ("No new entries"). Now a short
|
||||
report with app version, device and the note "sent manually" goes out even without new entries – so you can
|
||||
check that sending works.
|
||||
- **Jam stays more closely in sync:** small offsets are corrected inaudibly by slightly adjusting the playback
|
||||
speed (pitch stays the same); it only seeks once the offset reaches 1 second, with a lead time.
|
||||
|
||||
Everything else as in 1.5.0 (playlists and albums in the jam, songs continue automatically). Requires Android
|
||||
8.0 or newer.
|
||||
New in 1.6.0: diagnostic data (crashes and connection errors, no cookies, sign-in data, searches or song titles),
|
||||
can be turned off via the gear button on the right edge. Details: playtube-ppp-eula.pages.dev/playtube/privacy/#diag
|
||||
|
||||
Requires Android 8.0 or newer.
|
||||
|
||||
Reference in New Issue
Block a user