Repository navigation
Add Compose Multiplatform player with VK and media session #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
6f696a8
Add Compose Multiplatform player shell
decoder-dev 0d2a796
Fix Rust engine package name
decoder-dev 1e88878
Install native audio dependencies in Compose CI
decoder-dev 7d13d63
Use Gradle required by Android plugin
decoder-dev 7b36cd8
Fix Compose source sets and Android Kotlin DSL
decoder-dev d4e194a
Enable AGP compatibility mode for Compose application
decoder-dev 5a42d5a
Split shared Compose library from Android application
decoder-dev 1ffd02c
Apply Compose compiler in Android application
decoder-dev 92e7bcd
Apply Kotlin Compose compiler plugin
decoder-dev 7bcc1be
Update Compose Multiplatform for AGP 9 compatibility
decoder-dev 4c853aa
Apply compiler in shared module and fix desktop package
decoder-dev 4fbac06
Fix JSON imports and coroutine activity check
decoder-dev c2d2c5f
Package and verify Rust JNI library in APK
decoder-dev b3f60d7
Make JNI packaging configuration-cache safe
decoder-dev 84bb225
Remove unsupported Copy API call
decoder-dev e34a55d
Add VK authentication catalog downloads and lyrics
decoder-dev 5049781
Add Android media session and shared player events
decoder-dev ff22ede
Fix catalog integration and playback build errors
decoder-dev 614af3d
Test shared events and verify Android media manifest
decoder-dev cd0d23a
Use persistent native storage on Android and desktop
decoder-dev 5acddfe
Isolate Compose rendering tests with demo catalog
decoder-dev 8b65fa4
Fix Android login parsing and media service dependencies
decoder-dev b27e9ac
Expand visual tests and add Windows media keys
decoder-dev b46f7b7
Test offline catalog and prevent login polling loops
decoder-dev 9030fca
Build Rust automatically before desktop run
decoder-dev 1ea125f
Verify native mediaPlayback manifest bitmask
decoder-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| name: Compose Multiplatform | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - "compose/**" | ||
| - ".github/workflows/compose.yml" | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| rust: | ||
| name: Rust FFI | ||
| runs-on: ubuntu-24.04 | ||
| steps: | ||
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| - uses: dtolnay/rust-toolchain@stable | ||
|
|
||
| - name: Install native audio dependencies | ||
| run: sudo apt-get update && sudo apt-get install -y libasound2-dev libdbus-1-dev pkg-config | ||
| - name: Build native engine | ||
| run: cargo build --manifest-path compose/rust-ffi/Cargo.toml | ||
|
|
||
| ui: | ||
| name: Compose UI tests and screenshots | ||
| needs: rust | ||
| runs-on: ubuntu-24.04 | ||
| steps: | ||
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| - uses: actions/setup-java@v5 | ||
| with: | ||
| distribution: temurin | ||
| java-version: '17' | ||
| - uses: gradle/gradle-build-action@v3 | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| with: | ||
| gradle-version: '9.5.0' | ||
| - name: Run shared and rendering tests | ||
| working-directory: compose | ||
| run: gradle --no-daemon :composeApp:desktopTest | ||
| - name: Upload Compose screenshots | ||
| if: always() | ||
| uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 | ||
| with: | ||
| name: compose-screenshots | ||
| path: compose/composeApp/build/screenshots/*.png | ||
| if-no-files-found: error | ||
|
|
||
| android: | ||
| name: Compose Android APK | ||
| needs: rust | ||
| runs-on: ubuntu-24.04 | ||
| env: | ||
| NDK_VERSION: 27.2.12479018 | ||
| steps: | ||
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| - uses: actions/setup-java@v5 | ||
| with: | ||
| distribution: temurin | ||
| java-version: '17' | ||
| - uses: gradle/gradle-build-action@v3 | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| with: | ||
| gradle-version: '9.5.0' | ||
| - name: Android SDK, NDK and Rust target | ||
| run: | | ||
| set -euxo pipefail | ||
| . scripts/android-ci-env.sh | ||
| scripts/android-ci-sdk.sh "ndk;${NDK_VERSION}" "platforms;android-36" "build-tools;36.0.0" | ||
| rustup target add aarch64-linux-android | ||
| - name: Build APK with Rust JNI library | ||
| working-directory: compose | ||
| run: gradle --no-daemon :androidApp:assembleDebug -Dpm.rust.abi=arm64-v8a | ||
| - name: Verify Rust JNI library is packaged | ||
| run: unzip -l compose/androidApp/build/outputs/apk/debug/androidApp-debug.apk | grep 'lib/arm64-v8a/libprivate_music_engine.so' | ||
| - name: Verify media service and permissions in APK | ||
| run: | | ||
| "$ANDROID_HOME/build-tools/36.0.0/aapt2" dump xmltree --file AndroidManifest.xml compose/androidApp/build/outputs/apk/debug/androidApp-debug.apk > compose/androidApp/build/outputs/apk/debug/manifest.txt | ||
| grep -q 'PlaybackService' compose/androidApp/build/outputs/apk/debug/manifest.txt || { echo 'PlaybackService is missing'; exit 1; } | ||
| grep -q 'POST_NOTIFICATIONS' compose/androidApp/build/outputs/apk/debug/manifest.txt || { echo 'Notification permission is missing'; exit 1; } | ||
| grep -q 'FOREGROUND_SERVICE_MEDIA_PLAYBACK' compose/androidApp/build/outputs/apk/debug/manifest.txt || { echo 'Media playback foreground permission is missing'; exit 1; } | ||
| # aapt2 prints the enum as its native bit mask (FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK = 1 << 4). | ||
| grep -Eq 'foregroundServiceType.*0x0*10' compose/androidApp/build/outputs/apk/debug/manifest.txt || { echo 'mediaPlayback service type is missing'; exit 1; } | ||
| - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 | ||
| with: | ||
| name: compose-android-debug | ||
| path: compose/androidApp/build/outputs/apk/debug/*.apk | ||
| if-no-files-found: error | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| plugins { | ||
| id("com.android.application") | ||
| id("org.jetbrains.compose") | ||
| kotlin("plugin.compose") | ||
| } | ||
|
|
||
| android { | ||
| namespace = "com.dec.privatemusic.compose.app" | ||
| compileSdk = 36 | ||
| buildToolsVersion = "36.0.0" | ||
| defaultConfig { | ||
| applicationId = "com.dec.privatemusic.compose.app" | ||
| minSdk = 26 | ||
| targetSdk = 35 | ||
| versionCode = 1 | ||
| versionName = "0.1.0" | ||
| } | ||
| buildTypes { | ||
| getByName("release") { | ||
| isMinifyEnabled = false | ||
| } | ||
| getByName("debug") { | ||
| isDebuggable = true | ||
| isJniDebuggable = true | ||
| } | ||
| } | ||
| compileOptions { | ||
| sourceCompatibility = JavaVersion.VERSION_17 | ||
| targetCompatibility = JavaVersion.VERSION_17 | ||
| } | ||
| buildFeatures { | ||
| compose = true | ||
| } | ||
| packaging { | ||
| jniLibs { | ||
| useLegacyPackaging = true | ||
| } | ||
| } | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation(project(":composeApp")) | ||
| implementation("androidx.activity:activity-compose:1.10.1") | ||
| implementation("androidx.core:core-ktx:1.16.0") | ||
| implementation("androidx.media:media:1.7.1") | ||
| implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.9.0") | ||
| } | ||
|
|
||
| val rustAbi = System.getProperty("pm.rust.abi") ?: "arm64-v8a" | ||
| val rustTarget = when (rustAbi) { | ||
| "arm64-v8a" -> "aarch64-linux-android" | ||
| "x86_64" -> "x86_64-linux-android" | ||
| else -> error("Unsupported Rust ABI: $rustAbi") | ||
| } | ||
| val rustRoot = rootDir.resolve("rust-ffi") | ||
| val rustOutput = System.getenv("CARGO_TARGET_DIR")?.let { file(it) } ?: rustRoot.resolve("target") | ||
| val nativeLibrary = rustOutput.resolve("$rustTarget/release/libprivate_music_engine.so") | ||
|
|
||
| tasks.register<Exec>("cargoBuildPrivateMusic") { | ||
| workingDir = rustRoot | ||
| commandLine("cargo", "build", "--release", "--target", rustTarget) | ||
| } | ||
|
|
||
| tasks.register<Copy>("packagePrivateMusicJni") { | ||
| dependsOn("cargoBuildPrivateMusic") | ||
| from(nativeLibrary) | ||
| into("src/main/jniLibs/$rustAbi") | ||
| } | ||
|
|
||
| tasks.named("preBuild") { | ||
| dependsOn("packagePrivateMusicJni") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
| <uses-permission android:name="android.permission.INTERNET" /> | ||
| <uses-permission android:name="android.permission.POST_NOTIFICATIONS" /> | ||
| <uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> | ||
| <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" /> | ||
| <uses-permission android:name="android.permission.WAKE_LOCK" /> | ||
| <uses-feature android:name="android.hardware.audio.output" android:required="false" /> | ||
| <application | ||
| android:name=".PrivateMusicApplication" | ||
| android:allowBackup="true" | ||
| android:icon="@android:drawable/ic_media_play" | ||
| android:label="Private Music" | ||
| android:supportsRtl="true" | ||
| android:theme="@style/Theme.PrivateMusic"> | ||
| <activity | ||
| android:name=".MainActivity" | ||
| android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize|keyboardHidden" | ||
| android:exported="true"> | ||
| <intent-filter> | ||
| <action android:name="android.intent.action.MAIN" /> | ||
| <category android:name="android.intent.category.LAUNCHER" /> | ||
| </intent-filter> | ||
| </activity> | ||
| <activity | ||
| android:name=".VkLoginActivity" | ||
| android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize|keyboardHidden" | ||
| android:excludeFromRecents="true" | ||
| android:theme="@style/Theme.PrivateMusic" /> | ||
| <service | ||
| android:name=".PlaybackService" | ||
| android:exported="false" | ||
| android:foregroundServiceType="mediaPlayback" /> | ||
| </application> | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Comment on lines
+9
to
+34
|
||
| </manifest> | ||
59 changes: 59 additions & 0 deletions
59
compose/androidApp/src/main/kotlin/com/dec/privatemusic/compose/app/MainActivity.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package com.dec.privatemusic.compose.app | ||
|
|
||
| import android.Manifest | ||
| import android.content.Intent | ||
| import android.content.pm.PackageManager | ||
| import android.os.Build | ||
| import android.os.Bundle | ||
| import androidx.core.content.ContextCompat | ||
| import androidx.activity.ComponentActivity | ||
| import androidx.activity.compose.setContent | ||
| import androidx.activity.enableEdgeToEdge | ||
| import androidx.activity.result.contract.ActivityResultContracts | ||
| import androidx.compose.runtime.remember | ||
| import com.dec.privatemusic.player.PlayerViewModel | ||
| import com.dec.privatemusic.player.SessionStore | ||
| import com.dec.privatemusic.player.SessionViewModel | ||
| import com.dec.privatemusic.player.platformPlayerApi | ||
| import com.dec.privatemusic.ui.PrivateMusicApp | ||
|
|
||
| class MainActivity : ComponentActivity() { | ||
| private lateinit var sessions: SessionStore | ||
| private lateinit var sessionViewModel: SessionViewModel | ||
| private val loginLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> | ||
| if (result.resultCode == RESULT_OK) { | ||
| result.data?.getStringExtra("session")?.let { | ||
| sessions.saveJson(it) | ||
| sessions.sync() | ||
| sessionViewModel.refresh() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private val notificationPermission = registerForActivityResult(ActivityResultContracts.RequestPermission()) { } | ||
|
|
||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| super.onCreate(savedInstanceState) | ||
| sessions = SessionStore(this) | ||
| sessions.sync() | ||
| sessionViewModel = SessionViewModel() | ||
| ContextCompat.startForegroundService(this, Intent(this, PlaybackService::class.java)) | ||
| if (Build.VERSION.SDK_INT >= 33 && ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { | ||
| notificationPermission.launch(Manifest.permission.POST_NOTIFICATIONS) | ||
| } | ||
| enableEdgeToEdge() | ||
| setContent { | ||
| val api = remember { platformPlayerApi() } | ||
| val player = remember(api) { PlayerViewModel(api) } | ||
| PrivateMusicApp( | ||
| viewModel = player, | ||
| sessionViewModel = sessionViewModel, | ||
| onLogin = { loginLauncher.launch(Intent(this, VkLoginActivity::class.java)) }, | ||
| onLogout = { | ||
| sessions.clear() | ||
| sessionViewModel.refresh() | ||
| }, | ||
| ) | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.