LastExceed
12/09/2019, 2:32 PMhttps://i.imgur.com/6kNkSRr.png▾
Sergei Dubrov [JB]
12/09/2019, 2:43 PMimport javax.sound.sampled.AudioInputStream
fun test(ais: AudioInputStream) {
ais.readNBytes(ais.available()) // compiles fine
}
Can you send a code example?LastExceed
12/09/2019, 2:43 PMAlex Crafford
12/09/2019, 2:47 PMLastExceed
12/09/2019, 2:48 PMimport <http://java.io|java.io>.ByteArrayInputStream
import <http://java.io|java.io>.ByteArrayOutputStream
import javax.sound.sampled.*
import kotlin.concurrent.thread
fun main() {
val format = AudioFormat(
192000f,
16,
1,
true,
true
)
val info = <http://DataLine.Info|DataLine.Info>(TargetDataLine::class.java, format)
if (!AudioSystem.isLineSupported(info)) {
error("Line not supported")
}
val line = AudioSystem.getLine(info) as TargetDataLine
line.open(format)
line.start()
println("Start capturing...")
val ais = AudioInputStream(line)
val baos = ByteArrayOutputStream()
var stop = false
thread {
Thread.sleep(3000)
stop = true
}
while (!stop) {
val buffer = ais.readNBytes(ais.available())
//workaround:
//val buffer = ByteArray(ais.available())
//ais.read(buffer)
baos.write(buffer)
}
line.stop()
line.close()
println("done")
val recorded = AudioInputStream(ByteArrayInputStream(baos.toByteArray()), format, baos.size().toLong())
readLine()
val clip = AudioSystem.getClip()
clip.open(recorded)
clip.start()
}
records 3 seconds audio, then plays it back after pressing enter. i found a workaround but i'd still like to understand the errorSergei Dubrov [JB]
12/09/2019, 2:49 PMLastExceed
12/09/2019, 2:50 PMSergei Dubrov [JB]
12/09/2019, 2:53 PMLastExceed
12/09/2019, 2:53 PMplugins {
kotlin("jvm") version "1.3.61"
}
group = "lastexceed"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
implementation(kotlin("stdlib-jdk8"))
compile(files("src/main/resources/jnativehook-2.1.0.jar"))
}
tasks {
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
}
Sergei Dubrov [JB]
12/09/2019, 2:59 PMLastExceed
12/09/2019, 3:00 PMJamie Taylor
12/09/2019, 3:05 PMLastExceed
12/09/2019, 3:05 PMSergei Dubrov [JB]
12/09/2019, 3:23 PMShift+Shift -> Invalidate Caches / Restart...
?LastExceed
12/09/2019, 3:23 PMSergei Dubrov [JB]
12/09/2019, 3:28 PMLastExceed
12/09/2019, 3:30 PMhttps://i.imgur.com/QxiS4wB.png▾
Sergei Dubrov [JB]
12/09/2019, 3:32 PMLastExceed
12/09/2019, 3:37 PMSergei Dubrov [JB]
12/09/2019, 3:47 PMLastExceed
12/09/2019, 3:48 PMSergei Dubrov [JB]
12/09/2019, 3:48 PMLastExceed
12/09/2019, 3:53 PMSergei Dubrov [JB]
12/09/2019, 3:54 PMLastExceed
12/09/2019, 3:55 PMSergei Dubrov [JB]
12/09/2019, 3:59 PMLastExceed
12/09/2019, 4:00 PMimplementation(kotlin("stdlib-jdk8"))
and
kotlinOptions.jvmTarget = "1.8"
in the build.gradle even though the project jdk is 1.13 and not 1.8 ? (not that familiar with this stuff)Sergei Dubrov [JB]
12/09/2019, 4:03 PMLastExceed
12/09/2019, 4:04 PMLeoColman
12/09/2019, 4:05 PM.idea
and Invalidate/Restart
LastExceed
12/09/2019, 4:06 PMSergei Dubrov [JB]
12/09/2019, 4:12 PM.idea
folder?LastExceed
12/09/2019, 4:12 PMSergei Dubrov [JB]
12/09/2019, 4:13 PMLastExceed
12/09/2019, 4:15 PMSergei Dubrov [JB]
12/09/2019, 4:18 PMLastExceed
12/09/2019, 4:20 PMSergei Dubrov [JB]
12/09/2019, 4:26 PMLastExceed
12/09/2019, 4:28 PMSergei Dubrov [JB]
12/10/2019, 8:33 AMLastExceed
12/10/2019, 11:37 AMUsage of API documented as @since 11+
which is strange because my project language level is set to 13 (and setting it to 11 doesn't solve it either). HOWEVER the IDE still gave me the suggestion "set language level to 11" and clicking that solved the problem, but I am now oblivious to what was actually the problem since as i said the the project language level was already high enough and I am now unable to reproduce the error anymore even if i create a whole new project like before.
I'd really like to understand what's going on here especially since there is definitely something on the Kotlin side that needs to be fixed, can you explain? @Sergei Dubrov [JB]Sergei Dubrov [JB]
12/11/2019, 8:11 AM