Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.3.1
* Upgrade gradle & kotlin version.

## 0.3.0+1

* Update readme.
Expand Down
12 changes: 6 additions & 6 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@ group 'com.codevalop.raw_sound'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.7.20'
repositories {
google()
jcenter()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

rootProject.allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 30
compileSdkVersion 33

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand All @@ -39,7 +39,7 @@ android {
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.2'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2'
implementation 'androidx.annotation:annotation:1.1.0'
Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.media.AudioAttributes
import android.media.AudioFormat
import android.media.AudioManager
import android.media.AudioTrack
import androidx.annotation.NonNull
import io.flutter.Log
import kotlinx.coroutines.*
import kotlinx.coroutines.sync.Mutex
Expand All @@ -26,8 +25,8 @@ enum class PCMType {
}

/** RawSoundPlayer */
class RawSoundPlayer(@NonNull androidContext: Context, @NonNull bufferSize: Int,
@NonNull sampleRate: Int, @NonNull nChannels: Int, @NonNull pcmType: PCMType) {
class RawSoundPlayer(androidContext: Context, bufferSize: Int,
sampleRate: Int, nChannels: Int, pcmType: PCMType) {
companion object {
const val TAG = "RawSoundPlayer"
}
Expand Down Expand Up @@ -81,6 +80,7 @@ class RawSoundPlayer(@NonNull androidContext: Context, @NonNull bufferSize: Int,
}
}

@OptIn(DelicateCoroutinesApi::class)
fun play(): Boolean {
try {
audioTrack.play()
Expand All @@ -90,7 +90,7 @@ class RawSoundPlayer(@NonNull androidContext: Context, @NonNull bufferSize: Int,
}

GlobalScope.launch(Dispatchers.IO) {
Log.d(TAG, "--> queUseBuffer")
Log.d(/* tag = */ TAG, /* message = */ "--> queUseBuffer")
semUseBufferIdled.withPermit {

val n = buffersCacheSize - getBuffersCount()
Expand Down Expand Up @@ -141,8 +141,8 @@ class RawSoundPlayer(@NonNull androidContext: Context, @NonNull bufferSize: Int,
}
runBlocking {
clearBuffers()
resetSemBufferUsed();
resetSemBufferAdded();
resetSemBufferUsed()
resetSemBufferAdded()
}
return r
}
Expand All @@ -168,7 +168,8 @@ class RawSoundPlayer(@NonNull androidContext: Context, @NonNull bufferSize: Int,
}
}

fun feed(@NonNull data: ByteArray, onDone: (r: Boolean) -> Unit) {
@OptIn(DelicateCoroutinesApi::class)
fun feed(data: ByteArray, onDone: (r: Boolean) -> Unit) {
if (audioTrack.playState != AudioTrack.PLAYSTATE_PLAYING) {
Log.e(TAG, "Player is not playing")
onDone(true)
Expand All @@ -195,7 +196,7 @@ class RawSoundPlayer(@NonNull androidContext: Context, @NonNull bufferSize: Int,
// Log.d(TAG, "underrun count: ${audioTrack.underrunCount}")
}

fun setVolume(@NonNull volume: Float): Boolean {
fun setVolume(volume: Float): Boolean {
val r = audioTrack.setVolume(volume)
if (r == AudioTrack.SUCCESS) {
return true
Expand Down
33 changes: 15 additions & 18 deletions android/src/main/kotlin/com/codevalop/raw_sound/RawSoundPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package com.codevalop.raw_sound
import android.content.Context
import android.os.Handler
import android.os.Looper
import androidx.annotation.NonNull
import androidx.annotation.Nullable
import io.flutter.Log
import io.flutter.embedding.engine.plugins.FlutterPlugin
import io.flutter.plugin.common.MethodCall
Expand All @@ -29,13 +27,13 @@ class RawSoundPlugin : FlutterPlugin, MethodCallHandler {

private var players: MutableList<RawSoundPlayer> = mutableListOf()

override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "codevalop.com/raw_sound")
channel.setMethodCallHandler(this)
androidContext = flutterPluginBinding.applicationContext
}

override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
override fun onMethodCall(call: MethodCall, result: Result) {
var playerNo: Int = -1

if (call.method != "initialize") {
Expand Down Expand Up @@ -88,32 +86,31 @@ class RawSoundPlugin : FlutterPlugin, MethodCallHandler {
}
}

override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
channel.setMethodCallHandler(null)
}

private fun sendResultError(@NonNull errorCode: String, @Nullable errorMessage: String,
@Nullable errorDetails: Any?, @NonNull result: Result) {
private fun sendResultError(errorCode: String, errorMessage: String, errorDetails: Any?, result: Result) {
Handler(Looper.getMainLooper()).post {
result.error(errorCode, errorMessage, errorDetails)
}
}

private fun sendResultInt(@NonNull playState: Int, @NonNull result: Result) {
private fun sendResultInt(playState: Int, result: Result) {
Handler(Looper.getMainLooper()).post {
result.success(playState)
}
}

private fun initialize(@NonNull bufferSize: Int, @NonNull sampleRate: Int,
@NonNull nChannels: Int, @NonNull pcmType: PCMType,
@NonNull result: Result) {
private fun initialize(bufferSize: Int, sampleRate: Int,
nChannels: Int, pcmType: PCMType,
result: Result) {
val player = RawSoundPlayer(androidContext, bufferSize, sampleRate, nChannels, pcmType)
players.add(player)
sendResultInt(players.lastIndex, result)
}

private fun release(@NonNull playerNo: Int, @NonNull result: Result) {
private fun release(playerNo: Int, result: Result) {
val player = players[playerNo]
if (player.release()) {
players.removeAt(playerNo)
Expand All @@ -124,7 +121,7 @@ class RawSoundPlugin : FlutterPlugin, MethodCallHandler {
}
}

private fun play(@NonNull playerNo: Int, @NonNull result: Result) {
private fun play(playerNo: Int, result: Result) {
val player = players[playerNo]
if (player.play()) {
sendResultInt(player.getPlayState(), result)
Expand All @@ -134,7 +131,7 @@ class RawSoundPlugin : FlutterPlugin, MethodCallHandler {
}
}

private fun stop(@NonNull playerNo: Int, @NonNull result: Result) {
private fun stop(playerNo: Int, result: Result) {
val player = players[playerNo]
if (player.stop()) {
sendResultInt(player.getPlayState(), result)
Expand All @@ -144,7 +141,7 @@ class RawSoundPlugin : FlutterPlugin, MethodCallHandler {
}
}

private fun resume(@NonNull playerNo: Int, @NonNull result: Result) {
private fun resume(playerNo: Int, result: Result) {
val player = players[playerNo]
if (player.resume()) {
sendResultInt(player.getPlayState(), result)
Expand All @@ -154,7 +151,7 @@ class RawSoundPlugin : FlutterPlugin, MethodCallHandler {
}
}

private fun pause(@NonNull playerNo: Int, @NonNull result: Result) {
private fun pause(playerNo: Int, result: Result) {
val player = players[playerNo]
if (player.pause()) {
sendResultInt(player.getPlayState(), result)
Expand All @@ -164,7 +161,7 @@ class RawSoundPlugin : FlutterPlugin, MethodCallHandler {
}
}

private fun feed(@NonNull playerNo: Int, @NonNull data: ByteArray, @NonNull result: Result) {
private fun feed(playerNo: Int, data: ByteArray, result: Result) {
val player = players[playerNo]
player.feed(
data
Expand All @@ -178,7 +175,7 @@ class RawSoundPlugin : FlutterPlugin, MethodCallHandler {
}
}

private fun setVolume(@NonNull playerNo: Int, @NonNull volume: Float, @NonNull result: Result) {
private fun setVolume(playerNo: Int, volume: Float, result: Result) {
val player = players[playerNo]
if (player.setVolume(volume)) {
sendResultInt(player.getPlayState(), result)
Expand Down
4 changes: 2 additions & 2 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 30
compileSdkVersion 33

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand Down Expand Up @@ -58,5 +58,5 @@ flutter {
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
}
2 changes: 1 addition & 1 deletion example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:name="${applicationName}"
android:label="raw_sound_example"
android:icon="@mipmap/ic_launcher">
<activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package com.codevalop.raw_sound_example
import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() {
}
}
8 changes: 4 additions & 4 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.7.20'
repositories {
google()
jcenter()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.1'
classpath 'com.android.tools.build:gradle:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

Expand Down
3 changes: 1 addition & 2 deletions example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Tue Dec 22 16:27:58 CST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: raw_sound
description: A flutter plugin for playing raw PCM audio data (16-bit integer and 32-bit float).
version: 0.3.0+1
version: 0.3.1
homepage: https://github.com/8fdafs2/flutter_raw_sound
repository: https://github.com/8fdafs2/flutter_raw_sound

Expand Down