I've developing an application that would download a media file (.OGG) and play it.
Here's the code for downloading the file (input is the socket input):
The download seems to run fine, but when I try to play the song using MediaFile, it doesn't shows any error nor plays any sound.
Here is the code for playing the file: (media is a global MediaPlayer object)
I'm still trying to see what might be wrong, but if anyone has come with a similiar problem or knows how to solve it, I'll thankful to hear from you.
Yours,
Colex
Here's the code for downloading the file (input is the socket input):
Code:
private void retrieveSong(DataInputStream input) {
FileOutputStream output;
int file_size;
byte [] buffer;
try {
output = m_parent.openFileOutput("music.ogg", Activity.MODE_PRIVATE);
file_size = input.readInt();
m_parent.showText("File size: " + file_size, 2000);
while (file_size > 0) {
buffer = new byte[file_size];
file_size -= input.read(buffer);
output.write(buffer);
}
output.flush();
output.close();
m_parent.showText("Music downloaded!", 2000);
} catch (FileNotFoundException e) {
m_parent.showText("Could not create file!", 5000);
} catch (IOException e) {
}
}
The download seems to run fine, but when I try to play the song using MediaFile, it doesn't shows any error nor plays any sound.
Here is the code for playing the file: (media is a global MediaPlayer object)
Code:
media = new MediaPlayer();
media.setDataSource(m_parent.openFileInput("music.ogg").getFD());
media.prepare();
media.start();
I'm still trying to see what might be wrong, but if anyone has come with a similiar problem or knows how to solve it, I'll thankful to hear from you.
Yours,
Colex