Skip to content

Commit 8772a29

Browse files
authored
Custom Audio input (#528)
* Custom audio handling * Screen share audio example * Screen Audio Capturer in sdk * spotless * Spotless * fix extraneous logging * changeset * Update webrtc-sdk to 125.6422.06.1 * Test compile fixes
1 parent e451f87 commit 8772a29

File tree

44 files changed

+1262
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1262
-4
lines changed

.changeset/brave-cows-confess.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"client-sdk-android": minor
3+
---
4+
5+
Implement custom audio mixing into audio track

.changeset/modern-phones-stare.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"client-sdk-android": minor
3+
---
4+
5+
Update to webrtc-sdk 125.6422.06.1

.changeset/twelve-ways-itch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"client-sdk-android": minor
3+
---
4+
5+
Implement screen share audio capturer

.idea/compiler.xml

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
plugins {
2+
id 'com.android.application'
3+
id 'org.jetbrains.kotlin.android'
4+
}
5+
6+
android {
7+
namespace 'io.livekit.android.example.screenshareaudio'
8+
compileSdk 34
9+
10+
defaultConfig {
11+
applicationId "io.livekit.android.example.screenshareaudio"
12+
minSdk 29
13+
targetSdk 34
14+
versionCode 1
15+
versionName "1.0"
16+
17+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
18+
vectorDrawables {
19+
useSupportLibrary true
20+
}
21+
}
22+
23+
buildTypes {
24+
release {
25+
minifyEnabled false
26+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
27+
}
28+
}
29+
compileOptions {
30+
sourceCompatibility JavaVersion.VERSION_1_8
31+
targetCompatibility JavaVersion.VERSION_1_8
32+
}
33+
kotlinOptions {
34+
jvmTarget = '1.8'
35+
}
36+
buildFeatures {
37+
compose true
38+
}
39+
composeOptions {
40+
kotlinCompilerExtensionVersion compose_compiler_version
41+
}
42+
packaging {
43+
resources {
44+
excludes += '/META-INF/{AL2.0,LGPL2.1}'
45+
}
46+
}
47+
}
48+
49+
dependencies {
50+
51+
// If building the sample app outside the context of this repo, replace the following with:
52+
// api "io.livekit:livekit-android:<version>"
53+
api project(":livekit-android-sdk")
54+
api project(":sample-app-common")
55+
implementation libs.androidx.core.ktx
56+
implementation libs.androidx.lifecycle.runtime.ktx
57+
implementation libs.androidx.activity.compose
58+
implementation platform(libs.compose.bom)
59+
implementation libs.androidx.ui
60+
implementation libs.androidx.ui.graphics
61+
implementation libs.androidx.ui.tooling.preview
62+
implementation libs.androidx.material3
63+
implementation libs.timber
64+
testImplementation libs.junit
65+
androidTestImplementation libs.androidx.test.junit
66+
androidTestImplementation libs.espresso
67+
androidTestImplementation platform(libs.compose.bom)
68+
androidTestImplementation libs.androidx.ui.test.junit4
69+
debugImplementation libs.androidx.ui.tooling
70+
debugImplementation libs.androidx.ui.test.manifest
71+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2024 LiveKit, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.livekit.android.example.screenshareaudio
18+
19+
import androidx.test.ext.junit.runners.AndroidJUnit4
20+
import androidx.test.platform.app.InstrumentationRegistry
21+
import org.junit.Assert.*
22+
import org.junit.Test
23+
import org.junit.runner.RunWith
24+
25+
/**
26+
* Instrumented test, which will execute on an Android device.
27+
*
28+
* See [testing documentation](http://d.android.com/tools/testing).
29+
*/
30+
@RunWith(AndroidJUnit4::class)
31+
class ExampleInstrumentedTest {
32+
@Test
33+
fun useAppContext() {
34+
// Context of the app under test.
35+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
36+
assertEquals("io.livekit.android.example.screenshareaudio", appContext.packageName)
37+
}
38+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<application
5+
android:allowBackup="true"
6+
android:icon="@mipmap/ic_launcher"
7+
android:label="@string/app_name"
8+
android:roundIcon="@mipmap/ic_launcher_round"
9+
android:supportsRtl="true"
10+
android:theme="@style/Theme.Livekitandroid"
11+
android:usesCleartextTraffic="true">
12+
<activity
13+
android:name=".MainActivity"
14+
android:exported="true"
15+
android:label="@string/app_name"
16+
android:theme="@style/Theme.Livekitandroid">
17+
<intent-filter>
18+
<action android:name="android.intent.action.MAIN" />
19+
20+
<category android:name="android.intent.category.LAUNCHER" />
21+
</intent-filter>
22+
</activity>
23+
</application>
24+
25+
</manifest>
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright 2024 LiveKit, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.livekit.android.example.screenshareaudio
18+
19+
import android.media.projection.MediaProjectionManager
20+
import android.os.Bundle
21+
import androidx.activity.ComponentActivity
22+
import androidx.activity.compose.setContent
23+
import androidx.activity.result.contract.ActivityResultContracts
24+
import androidx.activity.viewModels
25+
import androidx.compose.foundation.layout.fillMaxSize
26+
import androidx.compose.material3.Button
27+
import androidx.compose.material3.MaterialTheme
28+
import androidx.compose.material3.Surface
29+
import androidx.compose.material3.Text
30+
import androidx.compose.runtime.getValue
31+
import androidx.compose.runtime.mutableStateOf
32+
import androidx.compose.runtime.remember
33+
import androidx.compose.runtime.setValue
34+
import androidx.compose.ui.Modifier
35+
import io.livekit.android.LiveKit
36+
import io.livekit.android.example.screenshareaudio.ui.theme.LivekitandroidTheme
37+
import io.livekit.android.util.LoggingLevel
38+
39+
class MainActivity : ComponentActivity() {
40+
41+
private val viewModel: MainViewModel by viewModels<MainViewModel>()
42+
private val screenCaptureIntentLauncher =
43+
registerForActivityResult(
44+
ActivityResultContracts.StartActivityForResult(),
45+
) { result ->
46+
val resultCode = result.resultCode
47+
val data = result.data
48+
if (resultCode != RESULT_OK || data == null) {
49+
return@registerForActivityResult
50+
}
51+
viewModel.startScreenCapture(data)
52+
}
53+
54+
private fun requestMediaProjection() {
55+
val mediaProjectionManager =
56+
getSystemService(MEDIA_PROJECTION_SERVICE) as MediaProjectionManager
57+
screenCaptureIntentLauncher.launch(mediaProjectionManager.createScreenCaptureIntent())
58+
}
59+
60+
override fun onCreate(savedInstanceState: Bundle?) {
61+
super.onCreate(savedInstanceState)
62+
LiveKit.loggingLevel = LoggingLevel.INFO
63+
viewModel
64+
setContent {
65+
LivekitandroidTheme {
66+
// A surface container using the 'background' color from the theme
67+
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
68+
var enableScreenCapture by remember {
69+
mutableStateOf(true)
70+
}
71+
Button(
72+
onClick = {
73+
if (enableScreenCapture) {
74+
requestMediaProjection()
75+
} else {
76+
viewModel.stopScreenCapture()
77+
}
78+
enableScreenCapture = !enableScreenCapture
79+
},
80+
) {
81+
val text = if (enableScreenCapture) {
82+
"enable"
83+
} else {
84+
"disable"
85+
}
86+
Text(text = text)
87+
}
88+
}
89+
}
90+
}
91+
}
92+
}

0 commit comments

Comments
 (0)