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
New Developer
Posts: 120
Registered: ‎05-20-2011
My Device: Touch 9800
My Carrier: Vodafone

TCP Time out while fetching MetaData for Radio Streaming

Dear Members,

 

I am creating an Radio app which will stream from the various different URL's.

Now while fetching the stream from the url's we also want the content that is which song is playing on i.e metadata.

 

Now for this i run another thread in a TimerTask that  will create the HTTP connection say like after every 40 seconds.

While using the simulator for OS 5 and above there is no problem but when i run the same thread for two to three iterations the metadata is recieved consistently but afterwards we got the TCP time out exception and this halts the over all system and device even losts the internet connection.

 

Can you please suggets any alternatives which can solve the problem.

 

I am also sharing the code that will get the metaData from the streaming URL.

 

class metaData extends Thread{
         public void run()
            {
         try {
         
             boolean metaDataCheckBit = false;
             StreamConnection streamConnection=null;
             HttpConnection httpConnection = null;
             InputStream inputStream =null;
             streamConnection=(StreamConnection)Connector.open(url);
             httpConnection=(HttpConnection)streamConnection;        
             httpConnection.setRequestProperty("Icy-metadata", "1");                   
             int httpStatus=httpConnection.getResponseCode();
             if(httpStatus==HttpConnection.HTTP_OK){
                   String mint = httpConnection.getHeaderField("icy-metaint");
                   inputStream = streamConnection.openInputStream();     
                   int length= Integer.parseInt(mint);
                   int b = 0;    
                   int count =0;    
                   while(count++ < length){
                     b = inputStream.read();         
                   }          
                   int metalength = ((int)b)*16;
                 
                   if(metalength <= 0)return;
                   byte buf[] = new byte[metalength];               
                   inputStream.read(buf,0,buf.length);              
                   final String metaData = new String(buf);   
                   
                  final String  streamTille = metaData.substring(14, metaData.indexOf("StreamUrl")-2);
                   System.out.println("Stream Title--------"+streamTille);
                   UiApplication.getUiApplication().invokeAndWait(new Runnable(){
                       public void run() {
                           try {
                               titleRf.setText(streamTille);
                           } catch (Exception e) {
                               System.out.println("Exception: " + e.toString());
                           }
                       }
                   });
             }
         }
       catch (Exception e){
            System.out.println("Exception in meta data...."+e);
             }
     }
     }

 

Thanks......

 

Amar