0

I have the following code

val filePath = context.filesDir.path.toString() + "/hello_world.mp3"
val inputStream = WaveUtils.reWriteWaveHeader(response.result)
val size = File(filePath).outputStream().use { inputStream.copyTo(it) }
val file = File (filePath)

Log.i("AMIRA00000" , "size : " + size)
Log.i("AMIRA00000" , "filePath : " + filePath)


val player = MediaPlayer()
player.setDataSource(context , Uri.parse(file.path))
player.prepare()
player.start()

the file size has value and the filePath is as following

/data/user/0/com.sbs16.ensofia/files/hello_world.mp3

which means that the file saved correctly, but the player does not work and give this error

java.io.IOException: Prepare failed.: status=0x1

can anyone please help ?

Amira Elsayed Ismail
  • 9,216
  • 30
  • 92
  • 175
  • did you check this: https://stackoverflow.com/a/11977292/2553984 – y.allam Sep 17 '19 at 22:35
  • I have tried two files : https://watson-developer-cloud.github.io/doc-tutorial-downloads/text-to-speech/reference/hello_world.wav , this file does not work, and I have tried this : http://www.music.helsinki.fi/tmt/opetus/uusmedia/esim/a2002011001-e02.wav and it is working, I do not know what is the problem of first file – Amira Elsayed Ismail Sep 17 '19 at 22:37
  • maybe it's not encoded correctly or something! – y.allam Sep 17 '19 at 22:41
  • but it is already working in web , so it should work just like any other wav file – Amira Elsayed Ismail Sep 17 '19 at 22:42
  • @y.allam : it seems problem in this format, the file is not running on default music player, put the problem that I have to make it run because I got this encoding from watson api, do you know any alternative to media player or how to open this encoding in android – Amira Elsayed Ismail Sep 17 '19 at 23:13
  • did you try https://github.com/google/ExoPlayer? i didn't try it before, but it may help – y.allam Sep 18 '19 at 10:44

0 Answers0