• 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
Jan 24, 2011
2
0
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
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones