Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Audio file not saving

 

HI all am trying to save an audio stream locally. The file is creating but when am trying to open it is giving mediaException. Error while intializing.

 

the following is the code snippet of the function am using to save the file locally....

 

kindly have a look over this.... and help me in figuring this out..

 

 

String FileGuideAudio = AppConstants.SDCARD+AppConstants.CONTENT_PATH +URI.getFile(streamURL);
			

fh.WriteTextFile(FileGuideAudio, is, Integer.parseInt(hconn.getHeaderField(HttpProtocolConstants.HEADER_CONTENT_LENGTH)));

 

 

 

public void WriteTextFile(String fName, InputStream is, int bytesize) 
	{
		try
		{
			byte[] imgBytes = null;
			
			if(bytesize >0)
				imgBytes = new byte[bytesize];
			
			if( imgBytes != null)
			{
				is.read(imgBytes);
				WriteTextFile(fName, imgBytes);
			}
		}
		catch (IOException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (Exception e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

 

Help!!!!

 

 

Thanks and Regards,
PraveenGoparaju.
Developer
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Re: Audio file not saving

Just to add to the above...,

 

While debugging i found that... the content length is not matching the num of bytes of the data.

 

The original audio file size is 100,354 bytes and while the content lenght of the response header is 96177 bytes.

 

so clearly the file corrupted and hence it is not opening... but why it is getting corrupted? do i need to add any more parameters to the http connection. the following is my code snippet that establishes remote connection and gets the data.

 

 

hconn = (HttpConnection) Connector.open(streamURL);

Tools.print("XCO: GuideIntroManager: downloadAndSave: ContentLength:" + hconn.getHeaderField(HttpProtocolConstants.HEADER_CONTENT_LENGTH));
is = hconn.openInputStream(); if( is != null) { player = javax.microedition.media.Manager.createPlayer(is, "audio/x-wav"); player.addPlayerListener(this); player.realize(); player.prefetch(); player.start(); }

 

Thanks and Regards,
PraveenGoparaju.
Developer
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Re: Audio file not saving

again back to you......

 

how to save an audio file locally?? am getting teh stream while I play this stream directly in the player it is playing but when i try to save it open it is not opening... the code is posted above.

 

am using the above posted writeFile() function to save the images and text files and they are saving. and able to use them. coming to audio file it is not saving.

 

 

am I missing something?

 

please help!!! am in a trouble....

Thanks and Regards,
PraveenGoparaju.
Developer
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Re: Audio file not saving

hello.... anybody there...

 

i just cant keep on posting replies to myself....

 

plz reply

Thanks and Regards,
PraveenGoparaju.