Hello again! I've found more problems with my java programm. I want to download a file (a song, .wav) during the java programm but don't know how to do it. I am making an application in which I must download songs from a web site on the phone (in this case I'm still working with the simulator Wireless Toolkit 2.0) and maybe after play them. The problem is that I don't know how to do that. Can anybody help me please? Thanks a lot
I haven't tried this, but you should be able to do it all in one go: check out method 'createPlayer' of class javax.microedition.media.Manager in MIDP 2.0.
Real phones' implementations of this API will probably download the whole WAV file before starting to play it, and if your WAV file is too big for the phone's memory then that might cause you problems. Also, there's no guarantee that real phones will support WAV format in MIDP (even if some other feature of the phone can play WAV files). Check your phone's documentation.
Joined: Sep 21, 2003
I have already tried it, but it doesn't download the song, because it only plays it back. I want to download it to the mobile phone and then, without connection, play it. The quality would be much better! Thanks a lot
Joined: Jan 22, 2003
Well it had to download it temporarily in order to play it back But if you want to download it, save it, then play it back later you'll need to do it like this: Download: open a 'GET' HttpConnection to the song's URL; read the song's bytes into a byte array (e.g. write each byte you read to a ByteArrayOutputStream, then calls its toByteArray() method); then write this byte array to a MIDP 'record store' Play: read the song data from the record store, create a ByteArrayInputStream from it, and call Manager.createPlayer(in, "audio/x-wav") This technique requires you to hold the whole WAV file data in MIDP 'heap memory', which may be a problem on phones with limited heap memory.