SDL3 for Android: Audio with SDL3_mixer SDL3 для Android: Работа со звуком через SDL3_mixer
Playing sound effects on screen touch using the SDL3_mixer library. Воспроизведение звуковых эффектов при касании экрана с помощью библиотеки SDL3_mixer.
SDL3_mixer is the standard library for audio playback. SDL3_mixer — это библиотека для воспроизведения аудио.
1. Download Resources 1. Загрузка ресурсов
- Download the source code for this example. Скачайте исходный код этого примера.
- Download the Android development binaries (AAR files): Скачайте файлы .aar для Android:
2. Project Configuration 2. Конфигурация проекта
Extract the AAR files and copy them to android-project/app/libs.
Извлеките файлы .aar и скопируйте их в папку android-project/app/libs.
Open android-project/app/build.gradle and add the dependencies:
Откройте android-project/app/build.gradle и добавьте зависимости:
dependencies {
implementation files('libs/SDL3-3.4.0.aar')
implementation files('libs/SDL3_mixer-3.1.2.aar')
implementation 'androidx.appcompat:appcompat:1.5.1'
}
3. CMake and ABI Settings 3. Настройки CMake и ABI
In the same build.gradle file, find the externalNativeBuild section. We need to enable the Mixer and target the correct architecture (ARM64 for modern devices):
В том же файле build.gradle найдите секцию externalNativeBuild. Нам нужно включить Mixer и указать архитектуру (ARM64):
externalNativeBuild {
cmake {
arguments '-DANDROID_STL=c++_shared', '-DWITH_IMAGE=OFF', '-DWITH_MIXER=ON', '-DWITH_NET=OFF', '-DWITH_BOX2D=OFF'
// abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
abiFilters 'arm64-v8a'
}
}
4. Build and Run 4. Сборка и запуск
Terminal 1: AssembleКонсоль 1: Сборка
gradlew assembleDebug
Terminal 2: InstallКонсоль 2: Установка
adb install -r app-debug.apk
5. Debugging Audio 5. Отладка звука
If the app crashes or you hear no sound, use adb logcat to see the system logs:
Если приложение закрывается или звука нет, используйте adb logcat для просмотра логов:
adb logcat SDL:V DEBUG:I *:S