Move dead submodules in-tree
Signed-off-by: swurl <swurl@swurl.xyz>
1
externals/oboe/samples/minimaloboe/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/build
|
19
externals/oboe/samples/minimaloboe/README.md
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
# Minimal Oboe
|
||||
|
||||
## Overview
|
||||
|
||||
This app is a very simple demonstration of turning on audio from buttons.
|
||||
It uses a low-latency Oboe stream.
|
||||
|
||||
## Implementation
|
||||
|
||||
The app is written using Kotlin and Jetpack Compose.
|
||||
|
||||
The app state is maintained by subclassing DefaultLifecycleObserver.
|
||||
Oboe is called through an external native function.
|
||||
|
||||
This app uses shared_ptr for passing callbacks to Oboe.
|
||||
When the stream is disconnected, it starts a new stream.
|
||||
|
||||
## Screenshots
|
||||

|
75
externals/oboe/samples/minimaloboe/build.gradle
vendored
Normal file
|
@ -0,0 +1,75 @@
|
|||
plugins {
|
||||
id 'com.android.application'
|
||||
id 'org.jetbrains.kotlin.android'
|
||||
id 'org.jetbrains.kotlin.plugin.compose'
|
||||
}
|
||||
|
||||
android {
|
||||
defaultConfig {
|
||||
applicationId "com.example.minimaloboe"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 35
|
||||
compileSdkVersion 35
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
vectorDrawables {
|
||||
useSupportLibrary true
|
||||
}
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_18
|
||||
targetCompatibility JavaVersion.VERSION_18
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = '18'
|
||||
}
|
||||
buildFeatures {
|
||||
compose true
|
||||
}
|
||||
composeOptions {
|
||||
kotlinCompilerExtensionVersion compose_version
|
||||
}
|
||||
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
path 'src/main/cpp/CMakeLists.txt'
|
||||
}
|
||||
}
|
||||
packagingOptions {
|
||||
resources {
|
||||
excludes += '/META-INF/{AL2.0,LGPL2.1}'
|
||||
}
|
||||
}
|
||||
namespace 'com.example.minimaloboe'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "androidx.core:core-ktx:$core_version"
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.1"
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.10.1"
|
||||
implementation "androidx.activity:activity-ktx:1.10.1"
|
||||
implementation "androidx.lifecycle:lifecycle-process:$lifecycle_version"
|
||||
implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
|
||||
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:$lifecycle_version"
|
||||
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
|
||||
implementation "androidx.lifecycle:lifecycle-runtime-compose:$lifecycle_version"
|
||||
implementation "androidx.compose.ui:ui:$compose_version"
|
||||
implementation "androidx.compose.material:material:$compose_version"
|
||||
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
|
||||
implementation 'androidx.activity:activity-compose:1.10.1'
|
||||
implementation 'androidx.appcompat:appcompat:1.7.0'
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
|
||||
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
|
||||
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
|
||||
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
|
||||
}
|
BIN
externals/oboe/samples/minimaloboe/minimaloboe-screenshot.png
vendored
Normal file
After Width: | Height: | Size: 97 KiB |
21
externals/oboe/samples/minimaloboe/proguard-rules.pro
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
24
externals/oboe/samples/minimaloboe/src/main/AndroidManifest.xml
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.Samples">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/Theme.Samples">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
53
externals/oboe/samples/minimaloboe/src/main/cpp/CMakeLists.txt
vendored
Normal file
|
@ -0,0 +1,53 @@
|
|||
#
|
||||
# Copyright 2022 The Android Open Source Project
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
cmake_minimum_required(VERSION 3.4.1)
|
||||
|
||||
# Set the path to the Oboe library directory
|
||||
set (OBOE_DIR ../../../../../)
|
||||
#message("OBOE_DIR = " + ${OBOE_DIR})
|
||||
|
||||
add_subdirectory(${OBOE_DIR} ./oboe-bin)
|
||||
|
||||
# include folders
|
||||
include_directories(
|
||||
${OBOE_DIR}/include
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
# App specific sources
|
||||
set (APP_SOURCES
|
||||
SimpleNoiseMaker.cpp
|
||||
MinimalOboeJNI.cpp
|
||||
)
|
||||
|
||||
# Build the minimaloboe (native) library
|
||||
add_library(minimaloboe SHARED
|
||||
${APP_SOURCES}
|
||||
)
|
||||
|
||||
# Enable optimization flags: if having problems with source level debugging,
|
||||
# disable -Ofast ( and debug ), re-enable after done debugging.
|
||||
target_compile_options(minimaloboe PRIVATE -Wall -Werror "$<$<CONFIG:RELEASE>:-Ofast>")
|
||||
|
||||
target_link_libraries( # Specifies the target library.
|
||||
minimaloboe
|
||||
oboe
|
||||
|
||||
# Links the target library to the log library
|
||||
# included in the NDK.
|
||||
log)
|
||||
target_link_options(minimaloboe PRIVATE "-Wl,-z,max-page-size=16384")
|
66
externals/oboe/samples/minimaloboe/src/main/cpp/MinimalOboeJNI.cpp
vendored
Normal file
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Copyright 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <jni.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static const char *TAG = "MinimalOboeJNI";
|
||||
|
||||
#include <android/log.h>
|
||||
|
||||
#include <SimpleNoiseMaker.h>
|
||||
|
||||
// JNI functions are "C" calling convention
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
using namespace oboe;
|
||||
|
||||
// Use a static object so we don't have to worry about it getting deleted at the wrong time.
|
||||
static SimpleNoiseMaker sPlayer;
|
||||
|
||||
/**
|
||||
* Native (JNI) implementation of AudioPlayer.startAudiostreamNative()
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_example_minimaloboe_AudioPlayer_startAudioStreamNative(
|
||||
JNIEnv * /* env */, jobject) {
|
||||
__android_log_print(ANDROID_LOG_INFO, TAG, "%s", __func__);
|
||||
Result result = sPlayer.open();
|
||||
if (result == Result::OK) {
|
||||
result = sPlayer.start();
|
||||
}
|
||||
return (jint) result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Native (JNI) implementation of AudioPlayer.stopAudioStreamNative()
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_example_minimaloboe_AudioPlayer_stopAudioStreamNative(
|
||||
JNIEnv * /* env */, jobject) {
|
||||
__android_log_print(ANDROID_LOG_INFO, TAG, "%s", __func__);
|
||||
// We need to close() even if the stop() fails because we need to delete the resources.
|
||||
Result result1 = sPlayer.stop();
|
||||
Result result2 = sPlayer.close();
|
||||
// Return first failure code.
|
||||
return (jint) ((result1 != Result::OK) ? result1 : result2);
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
92
externals/oboe/samples/minimaloboe/src/main/cpp/SimpleNoiseMaker.cpp
vendored
Normal file
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* Copyright 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
static const char *TAG = "SimpleNoiseMaker";
|
||||
|
||||
#include <android/log.h>
|
||||
|
||||
#include <SimpleNoiseMaker.h>
|
||||
|
||||
using namespace oboe;
|
||||
|
||||
oboe::Result SimpleNoiseMaker::open() {
|
||||
// Use shared_ptr to prevent use of a deleted callback.
|
||||
mDataCallback = std::make_shared<MyDataCallback>();
|
||||
mErrorCallback = std::make_shared<MyErrorCallback>(this);
|
||||
|
||||
AudioStreamBuilder builder;
|
||||
oboe::Result result = builder.setSharingMode(oboe::SharingMode::Exclusive)
|
||||
->setPerformanceMode(oboe::PerformanceMode::LowLatency)
|
||||
->setFormat(oboe::AudioFormat::Float)
|
||||
->setChannelCount(kChannelCount)
|
||||
->setDataCallback(mDataCallback)
|
||||
->setErrorCallback(mErrorCallback)
|
||||
// Open using a shared_ptr.
|
||||
->openStream(mStream);
|
||||
return result;
|
||||
}
|
||||
|
||||
oboe::Result SimpleNoiseMaker::start() {
|
||||
return mStream->requestStart();
|
||||
}
|
||||
|
||||
oboe::Result SimpleNoiseMaker::stop() {
|
||||
return mStream->requestStop();
|
||||
}
|
||||
|
||||
oboe::Result SimpleNoiseMaker::close() {
|
||||
return mStream->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* This callback method will be called from a high priority audio thread.
|
||||
* It should only do math and not do any blocking operations like
|
||||
* reading or writing files, memory allocation, or networking.
|
||||
* @param audioStream
|
||||
* @param audioData pointer to an array of samples to be filled
|
||||
* @param numFrames number of frames needed
|
||||
* @return
|
||||
*/
|
||||
DataCallbackResult SimpleNoiseMaker::MyDataCallback::onAudioReady(
|
||||
AudioStream *audioStream,
|
||||
void *audioData,
|
||||
int32_t numFrames) {
|
||||
// We requested float when we built the stream.
|
||||
float *output = (float *) audioData;
|
||||
// Fill buffer with random numbers to create "white noise".
|
||||
int numSamples = numFrames * kChannelCount;
|
||||
for (int i = 0; i < numSamples; i++) {
|
||||
// drand48() returns a random number between 0.0 and 1.0.
|
||||
// Center and scale it to a reasonable value.
|
||||
*output++ = (float) ((drand48() - 0.5) * 0.6);
|
||||
}
|
||||
return oboe::DataCallbackResult::Continue;
|
||||
}
|
||||
|
||||
void SimpleNoiseMaker::MyErrorCallback::onErrorAfterClose(oboe::AudioStream *oboeStream,
|
||||
oboe::Result error) {
|
||||
__android_log_print(ANDROID_LOG_INFO, TAG,
|
||||
"%s() - error = %s",
|
||||
__func__,
|
||||
oboe::convertToText(error)
|
||||
);
|
||||
// Try to open and start a new stream after a disconnect.
|
||||
if (mParent->open() == Result::OK) {
|
||||
mParent->start();
|
||||
}
|
||||
}
|
71
externals/oboe/samples/minimaloboe/src/main/cpp/SimpleNoiseMaker.h
vendored
Normal file
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef SIMPLE_NOISE_MAKER_H
|
||||
#define SIMPLE_NOISE_MAKER_H
|
||||
|
||||
#include "oboe/Oboe.h"
|
||||
|
||||
/**
|
||||
* Play white noise using Oboe.
|
||||
*/
|
||||
class SimpleNoiseMaker {
|
||||
public:
|
||||
|
||||
/**
|
||||
* Open an Oboe stream.
|
||||
* @return OK or negative error code.
|
||||
*/
|
||||
oboe::Result open();
|
||||
|
||||
oboe::Result start();
|
||||
|
||||
oboe::Result stop();
|
||||
|
||||
oboe::Result close();
|
||||
|
||||
private:
|
||||
|
||||
class MyDataCallback : public oboe::AudioStreamDataCallback {
|
||||
public:
|
||||
oboe::DataCallbackResult onAudioReady(
|
||||
oboe::AudioStream *audioStream,
|
||||
void *audioData,
|
||||
int32_t numFrames) override;
|
||||
|
||||
};
|
||||
|
||||
class MyErrorCallback : public oboe::AudioStreamErrorCallback {
|
||||
public:
|
||||
MyErrorCallback(SimpleNoiseMaker *parent) : mParent(parent) {}
|
||||
|
||||
virtual ~MyErrorCallback() {
|
||||
}
|
||||
|
||||
void onErrorAfterClose(oboe::AudioStream *oboeStream, oboe::Result error) override;
|
||||
|
||||
private:
|
||||
SimpleNoiseMaker *mParent;
|
||||
};
|
||||
|
||||
std::shared_ptr<oboe::AudioStream> mStream;
|
||||
std::shared_ptr<MyDataCallback> mDataCallback;
|
||||
std::shared_ptr<MyErrorCallback> mErrorCallback;
|
||||
|
||||
static constexpr int kChannelCount = 2;
|
||||
};
|
||||
|
||||
#endif //SIMPLE_NOISE_MAKER_H
|
84
externals/oboe/samples/minimaloboe/src/main/kotlin/com/example/minimaloboe/AudioPlayer.kt
vendored
Normal file
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Copyright 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.minimaloboe
|
||||
|
||||
import androidx.lifecycle.DefaultLifecycleObserver
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.plus
|
||||
|
||||
object AudioPlayer : DefaultLifecycleObserver {
|
||||
|
||||
// Create a coroutine scope which we can launch coroutines from. This way, if our
|
||||
// player is ever destroyed (for example, if it was no longer a singleton and had multiple
|
||||
// instances) any jobs would also be cancelled.
|
||||
private val coroutineScope = CoroutineScope(Dispatchers.Default) + Job()
|
||||
private var _playerState = MutableStateFlow<PlayerState>(PlayerState.NoResultYet)
|
||||
val playerState = _playerState.asStateFlow()
|
||||
|
||||
init {
|
||||
// Load the library containing the native code including the JNI functions.
|
||||
System.loadLibrary("minimaloboe")
|
||||
}
|
||||
|
||||
fun setPlaybackEnabled(isEnabled: Boolean) {
|
||||
// Start (and stop) Oboe from a coroutine in case it blocks for too long.
|
||||
// If the AudioServer has died it may take several seconds to recover.
|
||||
// That can cause an ANR if we are starting audio from the main UI thread.
|
||||
coroutineScope.launch {
|
||||
|
||||
val result = if (isEnabled) {
|
||||
startAudioStreamNative()
|
||||
} else {
|
||||
stopAudioStreamNative()
|
||||
}
|
||||
|
||||
val newUiState = if (result == 0) {
|
||||
if (isEnabled){
|
||||
PlayerState.Started
|
||||
} else {
|
||||
PlayerState.Stopped
|
||||
}
|
||||
} else {
|
||||
PlayerState.Unknown(result)
|
||||
}
|
||||
|
||||
_playerState.update { newUiState }
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStop(owner: LifecycleOwner) {
|
||||
setPlaybackEnabled(false)
|
||||
super.onStop(owner)
|
||||
}
|
||||
|
||||
private external fun startAudioStreamNative(): Int
|
||||
private external fun stopAudioStreamNative(): Int
|
||||
}
|
||||
|
||||
sealed interface PlayerState {
|
||||
object NoResultYet : PlayerState
|
||||
object Started : PlayerState
|
||||
object Stopped : PlayerState
|
||||
data class Unknown(val resultCode: Int) : PlayerState
|
||||
}
|
107
externals/oboe/samples/minimaloboe/src/main/kotlin/com/example/minimaloboe/MainActivity.kt
vendored
Normal file
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
* Copyright 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example.minimaloboe
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.material.Button
|
||||
import androidx.compose.material.MaterialTheme
|
||||
import androidx.compose.material.Surface
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.lifecycle.ProcessLifecycleOwner
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.example.minimaloboe.ui.theme.SamplesTheme
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
// Let our AudioPlayer observe lifecycle events for the application so when it goes into the
|
||||
// background we can stop audio playback.
|
||||
ProcessLifecycleOwner.get().lifecycle.addObserver(AudioPlayer)
|
||||
|
||||
setContent {
|
||||
SamplesTheme {
|
||||
// A surface container using the 'background' color from the theme
|
||||
Surface(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
color = MaterialTheme.colors.background
|
||||
) {
|
||||
MainControls()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun MainControls() {
|
||||
val playerState by AudioPlayer.playerState.collectAsStateWithLifecycle()
|
||||
MainControls(playerState, AudioPlayer::setPlaybackEnabled)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun MainControls(playerState: PlayerState, setPlaybackEnabled: (Boolean) -> Unit) {
|
||||
|
||||
Column {
|
||||
val isPlaying = playerState is PlayerState.Started
|
||||
Text(text = "Minimal Oboe!")
|
||||
Row {
|
||||
Button(
|
||||
onClick = { setPlaybackEnabled(true) },
|
||||
enabled = !isPlaying
|
||||
) {
|
||||
Text(text = "Start Audio")
|
||||
}
|
||||
Button(
|
||||
onClick = { setPlaybackEnabled(false) },
|
||||
enabled = isPlaying
|
||||
) {
|
||||
Text(text = "Stop Audio")
|
||||
}
|
||||
}
|
||||
|
||||
// Create a status message for displaying the current playback state.
|
||||
val uiStatusMessage = "Current status: " +
|
||||
when (playerState) {
|
||||
PlayerState.NoResultYet -> "No result yet"
|
||||
PlayerState.Started -> "Started"
|
||||
PlayerState.Stopped -> "Stopped"
|
||||
is PlayerState.Unknown -> {
|
||||
"Unknown. Result = " + playerState.resultCode
|
||||
}
|
||||
}
|
||||
Text(uiStatusMessage)
|
||||
}
|
||||
}
|
||||
|
||||
@Preview(showBackground = true)
|
||||
@Composable
|
||||
fun DefaultPreview() {
|
||||
SamplesTheme {
|
||||
MainControls(PlayerState.Started) { }
|
||||
}
|
||||
}
|
8
externals/oboe/samples/minimaloboe/src/main/kotlin/com/example/minimaloboe/ui/theme/Color.kt
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
package com.example.minimaloboe.ui.theme
|
||||
|
||||
import androidx.compose.ui.graphics.Color
|
||||
|
||||
val Purple200 = Color(0xFFBB86FC)
|
||||
val Purple500 = Color(0xFF6200EE)
|
||||
val Purple700 = Color(0xFF3700B3)
|
||||
val Teal200 = Color(0xFF03DAC5)
|
11
externals/oboe/samples/minimaloboe/src/main/kotlin/com/example/minimaloboe/ui/theme/Shape.kt
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
package com.example.minimaloboe.ui.theme
|
||||
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.Shapes
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
val Shapes = Shapes(
|
||||
small = RoundedCornerShape(4.dp),
|
||||
medium = RoundedCornerShape(4.dp),
|
||||
large = RoundedCornerShape(0.dp)
|
||||
)
|
44
externals/oboe/samples/minimaloboe/src/main/kotlin/com/example/minimaloboe/ui/theme/Theme.kt
vendored
Normal file
|
@ -0,0 +1,44 @@
|
|||
package com.example.minimaloboe.ui.theme
|
||||
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.material.MaterialTheme
|
||||
import androidx.compose.material.darkColors
|
||||
import androidx.compose.material.lightColors
|
||||
import androidx.compose.runtime.Composable
|
||||
|
||||
private val DarkColorPalette = darkColors(
|
||||
primary = Purple200,
|
||||
primaryVariant = Purple700,
|
||||
secondary = Teal200
|
||||
)
|
||||
|
||||
private val LightColorPalette = lightColors(
|
||||
primary = Purple500,
|
||||
primaryVariant = Purple700,
|
||||
secondary = Teal200
|
||||
|
||||
/* Other default colors to override
|
||||
background = Color.White,
|
||||
surface = Color.White,
|
||||
onPrimary = Color.White,
|
||||
onSecondary = Color.Black,
|
||||
onBackground = Color.Black,
|
||||
onSurface = Color.Black,
|
||||
*/
|
||||
)
|
||||
|
||||
@Composable
|
||||
fun SamplesTheme(darkTheme: Boolean = isSystemInDarkTheme(), content: @Composable () -> Unit) {
|
||||
val colors = if (darkTheme) {
|
||||
DarkColorPalette
|
||||
} else {
|
||||
LightColorPalette
|
||||
}
|
||||
|
||||
MaterialTheme(
|
||||
colors = colors,
|
||||
typography = Typography,
|
||||
shapes = Shapes,
|
||||
content = content
|
||||
)
|
||||
}
|
21
externals/oboe/samples/minimaloboe/src/main/kotlin/com/example/minimaloboe/ui/theme/Type.kt
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
package com.example.minimaloboe.ui.theme
|
||||
|
||||
import androidx.compose.material.Typography
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.sp
|
||||
|
||||
// Set of Material typography styles to start with
|
||||
val Typography = Typography(
|
||||
body1 = TextStyle(
|
||||
fontFamily = FontFamily.Default,
|
||||
fontWeight = FontWeight.Normal,
|
||||
fontSize = 24.sp
|
||||
),
|
||||
button = TextStyle(
|
||||
fontFamily = FontFamily.Default,
|
||||
fontWeight = FontWeight.W500,
|
||||
fontSize = 20.sp
|
||||
)
|
||||
)
|
30
externals/oboe/samples/minimaloboe/src/main/res/drawable-v24/ic_launcher_foreground.xml
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="85.84757"
|
||||
android:endY="92.4963"
|
||||
android:startX="42.9492"
|
||||
android:startY="49.59793"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#44000000"
|
||||
android:offset="0.0" />
|
||||
<item
|
||||
android:color="#00000000"
|
||||
android:offset="1.0" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillType="nonZero"
|
||||
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
|
||||
android:strokeWidth="1"
|
||||
android:strokeColor="#00000000" />
|
||||
</vector>
|
170
externals/oboe/samples/minimaloboe/src/main/res/drawable/ic_launcher_background.xml
vendored
Normal file
|
@ -0,0 +1,170 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path
|
||||
android:fillColor="#3DDC84"
|
||||
android:pathData="M0,0h108v108h-108z" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M9,0L9,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,0L19,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,0L29,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,0L39,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,0L49,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,0L59,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,0L69,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,0L79,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M89,0L89,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M99,0L99,108"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,9L108,9"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,19L108,19"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,29L108,29"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,39L108,39"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,49L108,49"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,59L108,59"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,69L108,69"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,79L108,79"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,89L108,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,99L108,99"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,29L89,29"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,39L89,39"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,49L89,49"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,59L89,59"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,69L89,69"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,79L89,79"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,19L29,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,19L39,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,19L49,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,19L59,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,19L69,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,19L79,89"
|
||||
android:strokeWidth="0.8"
|
||||
android:strokeColor="#33FFFFFF" />
|
||||
</vector>
|
5
externals/oboe/samples/minimaloboe/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
5
externals/oboe/samples/minimaloboe/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
BIN
externals/oboe/samples/minimaloboe/src/main/res/mipmap-hdpi/ic_launcher.webp
vendored
Normal file
After Width: | Height: | Size: 1.4 KiB |
BIN
externals/oboe/samples/minimaloboe/src/main/res/mipmap-hdpi/ic_launcher_round.webp
vendored
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
externals/oboe/samples/minimaloboe/src/main/res/mipmap-mdpi/ic_launcher.webp
vendored
Normal file
After Width: | Height: | Size: 982 B |
BIN
externals/oboe/samples/minimaloboe/src/main/res/mipmap-mdpi/ic_launcher_round.webp
vendored
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
externals/oboe/samples/minimaloboe/src/main/res/mipmap-xhdpi/ic_launcher.webp
vendored
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
externals/oboe/samples/minimaloboe/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
vendored
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
externals/oboe/samples/minimaloboe/src/main/res/mipmap-xxhdpi/ic_launcher.webp
vendored
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
externals/oboe/samples/minimaloboe/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
vendored
Normal file
After Width: | Height: | Size: 5.8 KiB |
BIN
externals/oboe/samples/minimaloboe/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
vendored
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
externals/oboe/samples/minimaloboe/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
vendored
Normal file
After Width: | Height: | Size: 7.6 KiB |
10
externals/oboe/samples/minimaloboe/src/main/res/values/colors.xml
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="purple_200">#FFBB86FC</color>
|
||||
<color name="purple_500">#FF6200EE</color>
|
||||
<color name="purple_700">#FF3700B3</color>
|
||||
<color name="teal_200">#FF03DAC5</color>
|
||||
<color name="teal_700">#FF018786</color>
|
||||
<color name="black">#FF000000</color>
|
||||
<color name="white">#FFFFFFFF</color>
|
||||
</resources>
|
3
externals/oboe/samples/minimaloboe/src/main/res/values/strings.xml
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
<resources>
|
||||
<string name="app_name">MinimalOboe</string>
|
||||
</resources>
|
7
externals/oboe/samples/minimaloboe/src/main/res/values/themes.xml
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<style name="Theme.Samples" parent="android:Theme.Material.Light.NoActionBar">
|
||||
<item name="android:statusBarColor">@color/purple_700</item>
|
||||
</style>
|
||||
</resources>
|