scala - JAAD cannot read m4a -


what wish generate preview every m4a file. trying java sound , jaad.

here attempt in scala

import java.io.{file, fileoutputstream} import javax.sound.sampled.audiosystem  /**  * created khanguyen on 7/21/15.  */ object main extends app {   val filepath = "audio.m4a"    val file = new file(filepath)    val audio = audiosystem.getaudioinputstream(file)    println(audio.getframelength) // return -1    println(audio.getformat) // return pcm_signed 0.0 hz, 0 bit, 0 channels, 0 bytes/frame,     val output = new fileoutputstream("outputaudio.m4a")    var buffer = array.fill[byte](1024)(0)    (i <- 0 1024) {     audio.read(buffer, * 1024, 1024)     buffer.take(10).map(println)     output.write(buffer)   }    audio.close()   output.flush()   output.close() } 

i cannot read audio input stream. framelength said -1. after read pass, bytes in array[byte] still 0. missing anything?

if getting -1 in audio.getframelength because file format not supported.

val audio = audiosystem.getaudioinputstream(file)                                                   //> javax.sound.sampled.unsupportedaudiofileexception: not audio input                                                   //|  stream input file                                                   //|   @ javax.sound.sampled.audiosystem.getaudioinputstream(audiosystem.java:                                                   //| 1187)                                                   //|   @ forcomp.wc$$anonfun$main$1.apply$mcv$sp(forcomp.wc.scala:15)                                                   //|   @ org.scalaide.worksheet.runtime.library.worksheetsupport$$anonfun$$exe                                                   //| cute$1.apply$mcv$sp(worksheetsupport.scala:76)                                                   //|   @ org.scalaide.worksheet.runtime.library.worksheetsupport$.redirected(w                                                   //| orksheetsupport.scala:65)                                                   //|   @ org.scalaide.worksheet.runtime.library.worksheetsupport$.$execute(wor                                                   //| ksheetsupport.scala:75)                                                   //|   @ forcomp.wc$.main(forcomp.wc.scala:5)                                                   //|   @ forcomp.wc.main(forcomp.wc.scala)        println(audio.getframelength) // return -1  


anyways, i've tested pet m4a example file in javax.sound.audiosystem api (http://docs.oracle.com/javase/7/docs/api/javax/sound/sampled/audiosystem.html) find more information supported file types, aac (m4a extentions part of aac coding) should supported.


Comments