Skip to content
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
60 changes: 60 additions & 0 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Android

# 只在 PR 上跑;合并到 main 的内容已经测过,不再重跑。需要时可以手动运行。
on:
pull_request:
paths: [android/**, ios/scripts/**, ios/testplugin/**, .github/workflows/android.yml]
workflow_dispatch:

permissions:
contents: read

concurrency:
group: android-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-24.04
timeout-minutes: 45
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-java@d1374f8ac74474200d16ef8ecee22c7ae7a51880 # v6.3.0
with:
distribution: temurin
java-version: 21
cache: gradle
- uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0
with:
go-version-file: server/go.mod
cache-dependency-path: server/go.sum
- name: 单元测试、静态检查和编译
working-directory: android
run: ./gradlew --console=plain :app:testDebugUnitTest :app:lintDebug :app:assembleDebug :app:assembleDebugAndroidTest :app:assembleRelease
- name: 允许模拟器使用 KVM
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: 界面测试
uses: reactivecircus/android-emulator-runner@a421e43855164a8197daf9d8d40fe71c6996bb0d # v2.38.0
with:
api-level: 34
target: google_apis
arch: x86_64
profile: pixel_7
script: android/scripts/ui-test.sh "$RUNNER_TEMP/screenshots"
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
if: always()
with:
name: android-screenshots
path: ${{ runner.temp }}/screenshots
if-no-files-found: ignore
retention-days: 14
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: android-apk
path: android/app/build/outputs/apk/release/app-release.apk
retention-days: 14
4 changes: 1 addition & 3 deletions .github/workflows/ios.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
name: iOS

# 只在 PR 上跑;合并到 main 的内容已经测过,不再重跑。需要时可以手动运行。
on:
push:
branches: [main]
paths: [ios/**, .github/workflows/ios.yml]
pull_request:
paths: [ios/**, .github/workflows/ios.yml]
workflow_dispatch:
Expand Down
127 changes: 127 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
name: Release

# 推送 v1.2.3 这样的 tag:编译 iOS(不签名的 ipa)和 Android(正式签名的 APK),发布到 GitHub Release。
# 手动运行只编译、上传产物,不发布,用来在合并前试一遍。
on:
push:
tags: ['v*']
workflow_dispatch:

permissions:
contents: read

concurrency:
group: release-${{ github.ref }}

jobs:
version:
runs-on: ubuntu-24.04
outputs:
name: ${{ steps.v.outputs.name }}
code: ${{ steps.v.outputs.code }}
steps:
- id: v
env:
REF_TYPE: ${{ github.ref_type }}
REF_NAME: ${{ github.ref_name }}
run: |
if [ "$REF_TYPE" = tag ]; then name="${REF_NAME#v}"; else name=0.0.0; fi
if ! [[ "$name" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
echo "tag 要写成 v1.2.3:$REF_NAME" >&2; exit 1
fi
# Android 的 versionCode 必须递增:1.2.3 → 10203。
code=$(( BASH_REMATCH[1] * 10000 + BASH_REMATCH[2] * 100 + BASH_REMATCH[3] ))
echo "name=$name" >> "$GITHUB_OUTPUT"
echo "code=$(( code > 0 ? code : 1 ))" >> "$GITHUB_OUTPUT"

android:
needs: version
runs-on: ubuntu-24.04
timeout-minutes: 30
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: actions/setup-java@d1374f8ac74474200d16ef8ecee22c7ae7a51880 # v6.3.0
with:
distribution: temurin
java-version: 21
- name: 编译并签名
working-directory: android
env:
KEYSTORE_BASE64: ${{ secrets.MUSICGO_KEYSTORE_BASE64 }}
MUSICGO_KEYSTORE_PASSWORD: ${{ secrets.MUSICGO_KEYSTORE_PASSWORD }}
MUSICGO_KEY_ALIAS: ${{ secrets.MUSICGO_KEY_ALIAS }}
MUSICGO_KEY_PASSWORD: ${{ secrets.MUSICGO_KEY_PASSWORD }}
VERSION_NAME: ${{ needs.version.outputs.name }}
VERSION_CODE: ${{ needs.version.outputs.code }}
run: |
# 每个版本必须用同一把密钥签名,否则装不上更新。
test -n "$KEYSTORE_BASE64" || { echo "缺少仓库密钥 MUSICGO_KEYSTORE_BASE64" >&2; exit 1; }
export MUSICGO_KEYSTORE="$RUNNER_TEMP/release.jks"
base64 -d <<<"$KEYSTORE_BASE64" > "$MUSICGO_KEYSTORE"
./gradlew --console=plain :app:assembleRelease \
-Pmusicgo.versionName="$VERSION_NAME" -Pmusicgo.versionCode="$VERSION_CODE"
rm "$MUSICGO_KEYSTORE"
mkdir -p "$RUNNER_TEMP/out"
cp app/build/outputs/apk/release/app-release.apk "$RUNNER_TEMP/out/MusicGo-$VERSION_NAME.apk"
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: android
path: ${{ runner.temp }}/out
if-no-files-found: error

ios:
needs: version
runs-on: ${{ vars.IOS_RUNNER || 'macos-26' }}
timeout-minutes: 45
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: 编译不签名的 ipa
env:
VERSION_NAME: ${{ needs.version.outputs.name }}
VERSION_CODE: ${{ needs.version.outputs.code }}
run: |
set -o pipefail
command -v xcodegen >/dev/null || HOMEBREW_NO_AUTO_UPDATE=1 brew install xcodegen
(cd ios && xcodegen)
xcodebuild build -quiet -project ios/MusicGo.xcodeproj -scheme MusicGo -configuration Release \
-destination 'generic/platform=iOS' -derivedDataPath "$RUNNER_TEMP/build" \
MARKETING_VERSION="$VERSION_NAME" CURRENT_PROJECT_VERSION="$VERSION_CODE" \
CODE_SIGNING_ALLOWED=NO CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY=""
mkdir -p "$RUNNER_TEMP/ipa/Payload" "$RUNNER_TEMP/out"
cp -R "$RUNNER_TEMP/build/Build/Products/Release-iphoneos/MusicGo.app" "$RUNNER_TEMP/ipa/Payload/"
(cd "$RUNNER_TEMP/ipa" && zip -qry "$RUNNER_TEMP/out/MusicGo-$VERSION_NAME-unsigned.ipa" Payload)
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: ios
path: ${{ runner.temp }}/out
if-no-files-found: error

publish:
if: github.ref_type == 'tag'
needs: [version, android, ios]
runs-on: ubuntu-24.04
permissions:
contents: write
steps:
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
path: out
merge-multiple: true
- name: 发布
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ github.ref_name }}
run: |
cat > notes.md <<'NOTES'
## 安装

- **Android**:下载 `.apk` 直接安装。以后的版本可以覆盖安装。
- **iOS**:`-unsigned.ipa` 没有签名,要用 AltStore、Sideloadly 或 xtool 等工具用自己的 Apple ID 签名后安装。免费 Apple ID 签的 App 7 天后要重装。

NOTES
gh release create "$TAG" out/* --repo "$GITHUB_REPOSITORY" --verify-tag --title "$TAG" \
--notes-file notes.md --generate-notes
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,12 @@ filter-allow.txt
/ios/App/Info.plist
.build/
/ios/build/

# Android
/android/.gradle/
/android/.kotlin/
/android/build/
/android/app/build/
/android/local.properties
*.jks
*.keystore
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ http://127.0.0.1:8870/rooms/<房间 ID>#token=<令牌>
| `server/` | Go 服务端和命令行:房间、队列、播放、音源、歌词、飞书 |
| `web/` | 网页大屏:React、TypeScript、Vite |
| `ios/` | iOS 客户端(SwiftUI),见 [ios/README.md](ios/README.md) |
| `android/` | Android 客户端(Kotlin、Compose),见 [android/README.md](android/README.md) |
| `mcp/` | 给 AI Agent 用的 MCP 工具:服务端自带的 `/mcp` 远程入口,以及本地程序 |
| `deploy/` | systemd、Caddy 配置,以及发布、备份、升级脚本 |
| `docs/` | 文档 |
Expand All @@ -78,9 +79,11 @@ make release VERSION=v1.0.0

所有 Go 代码都以 `CGO_ENABLED=0` 编译。

推送 `v1.2.3` 这样的 tag,`.github/workflows/release.yml` 会编译 iOS 和 Android 客户端,发布到 GitHub Release:不签名的 ipa,以及能直接安装的 APK。两个 App 的版本号都取自 tag。

## 目前的限制

- 锁屏播放还没有实现。
- 网页版不支持锁屏播放,锁屏听歌请用 iOS 或 Android 客户端。
- 歌词来自公开的歌词源,找不到就不显示。
- 插件音源的音频由你的服务器转发给房间成员,请只播放你有权播放的内容。

Expand Down
3 changes: 3 additions & 0 deletions THIRD_PARTY_NOTICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ MusicGo 以 [GNU AGPL-3.0](LICENSE) 发布。它包含或改写了下面这些
| [metadata-filter](https://github.com/web-scrobbler/metadata-filter) | MIT | 标题清理规则 |
| [AppleMusicStylePlayer](https://github.com/f728743/AppleMusicStylePlayer) | MIT | iOS 播放页,[`ios/App/Player`](ios/App/Player/NOTICE.md) |
| [MelismaKit for iOS](https://github.com/kmgcc/melismakit-ios) | AGPL-3.0 | iOS 歌词的滚动和逐字高亮,作为依赖使用,见 [`ios/project.yml`](ios/project.yml) |
| [accompanist-lyrics-ui](https://github.com/6xingyv/accompanist-lyrics-ui) | Apache-2.0 | Android 歌词的滚动和逐字高亮,作为依赖使用,见 [`libs.versions.toml`](android/gradle/libs.versions.toml) |
| [Reorderable](https://github.com/Calvin-LL/Reorderable) | Apache-2.0 | Android 拖动调整队列,作为依赖使用 |
| [Material Symbols](https://github.com/google/material-design-icons) | Apache-2.0 | Android 的图标,`android/app/src/main/res/drawable` |

所用的提交、改动和许可全文见各目录的 `NOTICE.md`。

Expand Down
36 changes: 36 additions & 0 deletions android/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# MusicGo Android 客户端

功能与网页版相同:一起听、点歌、调整队列、逐字歌词、投票切歌、管理成员和房间设置。需要 Android 8.0 或更高版本。

## 使用

粘贴房间的进入链接(`https://musicgo.example.com/rooms/<房间>#token=<令牌>`)即可。服务器地址来自链接,令牌存在 App 的私有目录,不参与系统备份。还不是成员时,链接里可以带 `invite=<邀请码>`。公网服务器必须用 `https`。

- 静音,以及通知和耳机上的播放、暂停只管本机;通知里的「下一首」和进度条会影响整个房间。房间的暂停、切歌按[权限](../docs/api.md#权限矩阵)生效。
- YouTube 用官方的内嵌播放器,只在播放页打开时播放,不能在后台听。
- 歌放完后,App 会在后台等 30 分钟,有人点歌就接着放。
- 点待播歌曲右边的 ✕ 撤回;房主和管理员拖动把手可以调整顺序。
- 歌词的时间偏移和手动选的歌词只存在本机。

## 开发

需要 JDK 21 和 Android SDK(设好 `ANDROID_HOME`)。

```sh
cd android
./gradlew :app:installDebug # 装到已连接的设备
./gradlew :app:testDebugUnitTest :app:lintDebug # 单元测试和静态检查
scripts/ui-test.sh # 界面测试,需要开着模拟器,还需要 Go
./gradlew :app:assembleRelease # 发布版
```

正式版本由 GitHub Release 发布(见根目录 README),用仓库密钥 `MUSICGO_KEYSTORE_BASE64` 等签名,每个版本必须用同一把密钥,否则无法覆盖安装。本地编译发布版时,签名读取环境变量 `MUSICGO_KEYSTORE`、`MUSICGO_KEYSTORE_PASSWORD`、`MUSICGO_KEY_ALIAS` 和 `MUSICGO_KEY_PASSWORD`;没设 `MUSICGO_KEYSTORE` 时用调试密钥,只适合自己安装。

| 目录(`app/src/main/java/dev/luckybot/musicgo/`) | 内容 |
|---|---|
| `api/` | 接口、数据结构、链接解析、进度推算、歌词解析 |
| `player/` | 跟着房间播放,以及通知和锁屏控制(Media3) |
| `ui/` | Compose 界面 |
| `RoomSession.kt` | 实时连接和房间操作 |

界面测试在 `app/src/androidTest`,对着 `ios/scripts/test-server.sh` 启动的真实服务端走完整流程。改动推到 PR 后,`.github/workflows/android.yml` 会编译、测试并上传截图(产物 `android-screenshots`)和 APK。
79 changes: 79 additions & 0 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.compose)
alias(libs.plugins.kotlin.serialization)
}

android {
namespace = "dev.luckybot.musicgo"
compileSdk {
version = release(37) { minorApiLevel = 1 }
}

defaultConfig {
applicationId = "dev.luckybot.musicgo"
minSdk = 26
targetSdk = 37
// 发布时由 tag 决定,见 .github/workflows/release.yml。
versionCode = providers.gradleProperty("musicgo.versionCode").orNull?.toInt() ?: 1
versionName = providers.gradleProperty("musicgo.versionName").orNull ?: "0.1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

// 正式签名从环境变量读取;没有时用调试签名,只适合自己安装。
val keystore = System.getenv("MUSICGO_KEYSTORE")
if (keystore != null) {
signingConfigs.create("release") {
storeFile = file(keystore)
storePassword = System.getenv("MUSICGO_KEYSTORE_PASSWORD")
keyAlias = System.getenv("MUSICGO_KEY_ALIAS")
keyPassword = System.getenv("MUSICGO_KEY_PASSWORD")
}
}

buildTypes {
release {
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"))
signingConfig = signingConfigs.findByName("release") ?: signingConfigs.getByName("debug")
}
}

buildFeatures.compose = true
// Media3 的 SimpleBasePlayer 等还标着不稳定,没有替代
lint.disable += "UnsafeOptInUsageError"
}

kotlin {
compilerOptions {
optIn.addAll(
"androidx.compose.material3.ExperimentalMaterial3Api",
"androidx.compose.ui.ExperimentalComposeUiApi",
"kotlinx.serialization.ExperimentalSerializationApi",
)
}
}

dependencies {
implementation(platform(libs.compose.bom))
implementation(libs.compose.material3)
implementation(libs.activity.compose)
implementation(libs.lifecycle.compose)
implementation(libs.media3.exoplayer)
implementation(libs.media3.session)
implementation(libs.okhttp)
implementation(libs.okhttp.coroutines)
implementation(libs.coil.compose)
implementation(libs.coil.okhttp)
implementation(libs.serialization.json)
implementation(libs.coroutines.android)
implementation(libs.lyrics.ui)
implementation(libs.lyrics.core)
implementation(libs.reorderable)

testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.runner)
androidTestImplementation(libs.uiautomator)
}
Loading
Loading