我正在为Flutter开发一个音频处理库,我的一个本地Kotlin类遇到了一个问题。在下面的代码示例中,编译器抱怨调用
copyInto
上
samples
IntArray
Android工作室的Intellisense甚至
作为我键入“samples”时的一个选项。
这是我的班级代码:
package com.----.audio_channels
import kotlin.math.abs
import kotlin.math.min
abstract class AudioTrackBuffer constructor(val loop: Boolean) {
var position: Int = 0
abstract fun getSamples(sampleCount: Int): IntArray
abstract fun isComplete(): Boolean
abstract fun dispose()
}
class RawAudioBuffer constructor(private val samples: IntArray, loop: Boolean, delay: Int): AudioTrackBuffer(loop) {
init {
position = -delay
}
override fun getSamples(sampleCount: Int): IntArray {
val slice: IntArray
if (position < 0) {
slice = IntArray(sampleCount) { 0 }
if (position + sampleCount < 0) {
position += sampleCount
return slice
}
val offset = abs(position)
samples.copyInto(slice, offset, 0, min(sampleCount - offset, samples.size)) // Error
} else {
slice = samples.copyOfRange(position, min(position + sampleCount, samples.size))
position += slice.size
}
return slice
}
override fun isComplete(): Boolean {
return position >= samples.size
}
override fun dispose() {}
}
Launching lib\main.dart on SM N960U in debug mode...
Initializing gradle...
Resolving dependencies...
Running Gradle task 'assembleDebug'...
e: E:\flutter\workspace\audio_channels\android\src\main\kotlin\com\----\audio_channels\AudioTrackBuffer.kt: (33, 21): Unresolved reference: copyInto
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':audio_channels:compileDebugKotlin'.
> Compilation error. See log for more details
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
Finished with error: Gradle task assembleDebug failed with exit code 1