• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Playing OGG files

Colex

Lurker
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):
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
 
Thank you, though that's not my real problem, I tested with music.ogg, but before asking here I changed to wav to see if there's any difference about it. Guess I've forgotten to change before copying it here.

I've just updated the topic to correct that.
 
Back
Top Bottom