title: textview not updating (shoutcast stream metadata in android 2.2)
body: <p>i have a IcyStreamMeta.class that gets the metadata info of shoutcast Stream i use the method below to update the textview in my main activity and display the current song title playing. the code below works on android 2.1 and android 1.5 somehow it doesnt work on android 2.2 i dont know whats wrong i cant figure it out. i need you help guys :)</p>
  
  <p><strong>here is my IcyStreamMeta class</strong></p>
  
  <pre><code>public class IcyStreamMeta&lt;Message&gt; {
  
  protected URL streamUrl;
  private Map&lt;String, String&gt; metadata;
  private boolean isError;
  
  public IcyStreamMeta(URL streamUrl) {
      setStreamUrl(streamUrl);
  
      isError = false;
  }
  
  /**
   * Get artist using stream's title
   *
   * @return String
   * @throws IOException
   */
  public String getArtist() throws IOException {
      Map&lt;String, String&gt; data = getMetadata();
  
      if (!data.containsKey("StreamTitle"))
          return "";
  
      String streamTitle = data.get("StreamTitle");
      String title = streamTitle.substring(0, streamTitle.indexOf("-"));
      return title.trim();
  }
  
  /**
   * Get title using stream's title
   *
   * @return String
   * @throws IOException
   */
  public String getTitle() throws IOException {
      Map&lt;String, String&gt; data = getMetadata();
  
      if (!data.containsKey("StreamTitle"))
          return "";
  
      String streamTitle = data.get("StreamTitle");
      String artist = streamTitle.substring(streamTitle.indexOf("-")+1);
      return artist.trim();
  }
  
  public Map&lt;String, String&gt; getMetadata() throws IOException {
      if (metadata == null) {
          refreshMeta();
      }
  
      return metadata;
  }
  
  public void refreshMeta() throws IOException {
      retreiveMetadata();
  }
  
  private void retreiveMetadata() throws IOException {
      URLConnection con = streamUrl.openConnection();
      con.setRequestProperty("Icy-MetaData", "1");
      con.setRequestProperty("Connection", "close");
      con.setRequestProperty("Accept", null);
      con.connect();
  
      int metaDataOffset = 0;
      Map&lt;String, List&lt;String&gt;&gt; headers = con.getHeaderFields();
      InputStream stream = con.getInputStream();
  
      if (headers.containsKey("icy-metaint")) {
          // Headers are sent via HTTP
          metaDataOffset = Integer.parseInt(headers.get("icy-metaint").get(0));
      } else {
          // Headers are sent within a stream
          StringBuilder strHeaders = new StringBuilder();
          char c;
          while ((c = (char)stream.read()) != -1) {
              strHeaders.append(c);
              if (strHeaders.length() &gt; 5 &amp;&amp; (strHeaders.substring((strHeaders.length() - 4), strHeaders.length()).equals("\r\n\r\n"))) {
                  // end of headers
                  break;
              }
          }
  
          // Match headers to get metadata offset within a stream
          Pattern p = Pattern.compile("\\r\\n(icy-metaint):\\s*(.*)\\r\\n");
          Matcher m = p.matcher(strHeaders.toString());
          if (m.find()) {
              metaDataOffset = Integer.parseInt(m.group(2));
          }
      }
  
      // In case no data was sent
      if (metaDataOffset == 0) {
          isError = true;
          return;
      }
  
      // Read metadata
      int b;
      int count = 0;
      int metaDataLength = 4080; // 4080 is the max length
      boolean inData = false;
      StringBuilder metaData = new StringBuilder();
      // Stream position should be either at the beginning or right after headers
      while ((b = stream.read()) != -1) {
          count++;
  
          // Length of the metadata
          if (count == metaDataOffset + 1) {
              metaDataLength = b * 16;
          }
  
          if (count &gt; metaDataOffset + 1 &amp;&amp; count &lt; (metaDataOffset + metaDataLength)) {              
              inData = true;
          } else {                
              inData = false;             
          }               
          if (inData) {               
              if (b != 0) {                   
                  metaData.append((char)b);               
              }           
          }               
          if (count &gt; (metaDataOffset + metaDataLength)) {
              break;
          }
  
      }
  
      // Set the data
      metadata = IcyStreamMeta.parseMetadata(metaData.toString());
  
      // Close
      stream.close();
  }
  
  public boolean isError() {
      return isError;
  }
  
  public URL getStreamUrl() {
      return streamUrl;
  }
  
  public void setStreamUrl(URL streamUrl) {
      this.metadata = null;
      this.streamUrl = streamUrl;
      this.isError = false;
  }
  
  public static Map&lt;String, String&gt; parseMetadata(String metaString) {
      Map&lt;String, String&gt; metadata = new HashMap();
      String[] metaParts = metaString.split(";");
      Pattern p = Pattern.compile("^([a-zA-Z]+)=\\'([^\\']*)\\'$");
      Matcher m;
      for (int i = 0; i &lt; metaParts.length; i++) {
          m = p.matcher(metaParts[i]);
          if (m.find()) {
              metadata.put(m.group(1), m.group(2));
          }
      }
  
      return metadata;
  }   
      }
  </code></pre>
  
  <p>here is the method i use in my MAIN ACTIVITY to display the song title in my textview</p>
  
  <pre><code>private void getmeta()
  {
      timer = new Timer();
      timer.schedule(new TimerTask() {
      public void run(){
  
      URL url;
      try{
          url = new URL("http://www.rakista.com:8000/listen.mp3");
          IcyStreamMeta icy = new IcyStreamMeta(url);
          A = icy.getArtist();
          Artist.setText(A);
  
      }catch (MalformedURLException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      }
  },0,2000);
  
      //Log.i("Artist: ", A);
  }
  </code></pre>
  
  <p><strong>Update:</strong></p>
  
  <p><strong>my main Activty</strong></p>
  
  <pre><code>private class 
  
  public class RakistaRadio extends Activity
  {
  
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  Artist =(TextView) findViewById(R.id.ARTIST);
  
  }
  }
  </code></pre>