1

I have the following code. Everything works fine except that the downloded MP3 file does not have any property (metadata) such as Artist, title and etc when I play using the default music player. If tried to download the same mp3 file from the site directly using android browser and play using the default music player, all the metatdata are intact (ie. music player display title, artist and etc).

    @Override
    protected String doInBackground(String... aurl) {
        int count;

        i = Integer.parseInt(aurl[0]);
        try {
            sura = "abc.mp3";
            String addr = "http://www.xyzabc.com/" + sura;

            URL url = new URL(addr);
            HttpURLConnection conexion = (HttpURLConnection) url.openConnection();
              conexion.setRequestMethod("GET");
                conexion.setDoOutput(true);
            conexion.connect();

            int lenghtOfFile = conexion.getContentLength();

            InputStream input = new BufferedInputStream(url.openStream());
            File file = new File(rootDir + "/mysite/" + sura);
            OutputStream output = new FileOutputStream(file);

            byte data[] = new byte[1024];

            long total = 0;

            while ((count = input.read(data)) != -1 & run == true) {
                total += count;
                publishProgress("" + (int) ((total * 100) / lenghtOfFile));
                output.write(data, 0, count);
            }

            output.flush();
            output.close();
            input.close();

        } catch (Exception e) {
        }

        return null;
    }
RiyasMd
  • 35
  • 5

1 Answers1

1

The System content provider didn't update as soon as your downloading complete. Try restart your emulator or install/unstall your sd card, see if the content provider updates.

The uri is MediaStore.Audio.Media.EXTERNAL_CONTENT_URI and you can get details by query MediaStore.Audio.Media.DATA, MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.COMPOSER, MediaStore.Audio.Media.ALBUM, MediaStore.Audio.Media.ARTIST and others (All in MediaStore.Audio.Media.*)

If you want to get the information immediately, maybe you should update the Content Provider manual by yourself.

JohnCookie
  • 661
  • 3
  • 7
  • Thanks JohnCookie. I play the mp3 file immediatly using the default mp3 player and it does not show title, artist and etc. I tried this in phone. (not in emulator). But I tried playing the song after I downlod using android browser, it displays title, artist and etc. – RiyasMd Jan 19 '12 at 07:27
  • It should be the System Database didn't update the details at once. The System MediaPlayer App get the informations through the URI as well, try update it manual? (I'm not sure, I just know that we can get media details by contentProvider and it updates itself when the device restart reboot or sd card is reload) – JohnCookie Jan 19 '12 at 08:23