Skip to content

Commit 8dc5dd7

Browse files
committed
finish project
0 parents  commit 8dc5dd7

File tree

39 files changed

+1395
-0
lines changed

39 files changed

+1395
-0
lines changed

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea
5+
.DS_Store
6+
/build
7+
/captures
8+
.externalNativeBuild
9+
.cxx
10+
local.properties

build.gradle

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2+
buildscript {
3+
ext.kotlin_version = "1.3.72"
4+
repositories {
5+
google()
6+
jcenter()
7+
}
8+
dependencies {
9+
classpath "com.android.tools.build:gradle:4.1.2"
10+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11+
12+
// NOTE: Do not place your application dependencies here; they belong
13+
// in the individual module build.gradle files
14+
}
15+
}
16+
17+
allprojects {
18+
repositories {
19+
google()
20+
jcenter()
21+
maven { url "https://www.jitpack.io" }
22+
}
23+
}
24+
25+
task clean(type: Delete) {
26+
delete rootProject.buildDir
27+
}

demo/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

demo/build.gradle

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
plugins {
2+
id 'com.android.application'
3+
id 'kotlin-android'
4+
}
5+
6+
android {
7+
compileSdkVersion 30
8+
buildToolsVersion "30.0.3"
9+
10+
defaultConfig {
11+
applicationId "x.y.audiovisulizer"
12+
minSdkVersion 21
13+
targetSdkVersion 30
14+
versionCode 1
15+
versionName "1.0"
16+
17+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
18+
}
19+
20+
buildTypes {
21+
release {
22+
minifyEnabled false
23+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
24+
}
25+
}
26+
compileOptions {
27+
sourceCompatibility JavaVersion.VERSION_1_8
28+
targetCompatibility JavaVersion.VERSION_1_8
29+
}
30+
kotlinOptions {
31+
jvmTarget = '1.8'
32+
}
33+
}
34+
35+
dependencies {
36+
37+
def lifecycle_version = "2.3.0"
38+
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
39+
40+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
41+
implementation 'androidx.core:core-ktx:1.3.2'
42+
implementation 'androidx.appcompat:appcompat:1.2.0'
43+
implementation 'com.google.android.material:material:1.3.0'
44+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.2'
45+
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
46+
47+
implementation project(":library")
48+
}

demo/proguard-rules.pro

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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package x.stefanji.audiovisulizer
2+
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
import org.junit.Assert.*
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(AndroidJUnit4::class)
17+
class ExampleInstrumentedTest {
18+
@Test
19+
fun useAppContext() {
20+
// Context of the app under test.
21+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22+
assertEquals("x.y.audiovisulizer", appContext.packageName)
23+
}
24+
}

demo/src/main/AndroidManifest.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="x.stefanji.audiovisulizer">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:supportsRtl="true"
11+
android:theme="@style/Theme.AudioVisulizer">
12+
<activity
13+
android:name="x.stefanji.audiovisulizer.MainActivity"
14+
android:label="@string/app_name"
15+
android:theme="@style/Theme.AudioVisulizer.NoActionBar">
16+
<intent-filter>
17+
<action android:name="android.intent.action.MAIN" />
18+
19+
<category android:name="android.intent.category.LAUNCHER" />
20+
</intent-filter>
21+
</activity>
22+
</application>
23+
24+
</manifest>

demo/src/main/assets/output.mp3

299 KB
Binary file not shown.

demo/src/main/assets/test.m4a

2.49 MB
Binary file not shown.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package x.stefanji.audiovisulizer
2+
3+
import android.os.Bundle
4+
import android.util.Log
5+
import android.widget.Button
6+
import androidx.appcompat.app.AppCompatActivity
7+
import androidx.lifecycle.lifecycleScope
8+
import kotlinx.coroutines.Dispatchers
9+
import kotlinx.coroutines.launch
10+
import kotlinx.coroutines.withContext
11+
import x.stefanji.library.AudioWaveformGenerator
12+
import java.io.File
13+
14+
private const val TAG = "Main"
15+
private const val MP3 = "output.mp3"
16+
private const val M4a = "test.m4a"
17+
private const val INPUT_FILE = M4a
18+
19+
class MainActivity : AppCompatActivity() {
20+
21+
override fun onCreate(savedInstanceState: Bundle?) {
22+
super.onCreate(savedInstanceState)
23+
setContentView(R.layout.activity_main)
24+
25+
findViewById<Button>(R.id.btnStart).setOnClickListener {
26+
lifecycleScope.launch {
27+
withContext(Dispatchers.IO) {
28+
try {
29+
val file = File(cacheDir, INPUT_FILE)
30+
val ins = assets.open(INPUT_FILE)
31+
val ous = file.outputStream()
32+
val buffer = ByteArray(4096)
33+
var len: Int
34+
while (ins.read(buffer).also { read -> len = read } != -1) {
35+
ous.write(buffer, 0, len)
36+
}
37+
ins.close()
38+
ous.close()
39+
40+
val decoder = AudioWaveformGenerator(
41+
file.absolutePath,
42+
100
43+
)
44+
decoder.startDecode()
45+
val samples = decoder.getSampleData()
46+
Log.d(TAG, "onFinish ${samples.size}")
47+
lifecycleScope.launch {
48+
val values = samples.toList()
49+
withContext(Dispatchers.Main) {
50+
findViewById<Wave>(R.id.wave).setValues(values)
51+
}
52+
}
53+
} catch (e: Exception) {
54+
Log.e(TAG, "copy", e)
55+
}
56+
}
57+
}
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)