22

I am working to change ID3 tags, the metadata in audio files, such as:

  • Artist
  • Title
  • Album
  • etc.

And the core point,. that edited ID3 tags should be shown only into my app.

Jonik
  • 80,077
  • 70
  • 264
  • 372
Chirag Shah
  • 2,058
  • 2
  • 20
  • 30

4 Answers4

27

I think this is what you are looking for MyID3 library to set and get tags for media file.

Download this jar file MyID3_for_android and add it to your project's build path. here is the sample code. here pathdata is the file path of the audio file.

            File src = new File(pathdata);
            MusicMetadataSet src_set = null;
            try {
                src_set = new MyID3().read(src);
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } // read metadata

            if (src_set == null) // perhaps no metadata
            {
                Log.i("NULL", "NULL");
            }
            else
            {
                try{
                    IMusicMetadata metadata = src_set.getSimplified();
                    String artist = metadata.getArtist();  
                    String album = metadata.getAlbum();  
                    String song_title = metadata.getSongTitle(); 
                    Number track_number = metadata.getTrackNumber(); 
                    Log.i("artist", artist);
                    Log.i("album", album);
                }catch (Exception e) {
                    e.printStackTrace();
                }
                File dst = new File(pathdata);
                MusicMetadata meta = new MusicMetadata("name");
                meta.setAlbum("Chirag");
                meta.setArtist("CS");
                try {
                    new MyID3().write(src, dst, src_set, meta);
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (ID3WriteException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }  // write updated metadata
            }

Happy Coding :)

Community
  • 1
  • 1
MKJParekh
  • 34,073
  • 11
  • 87
  • 98
  • 6
    when i change the id3 tag ,it corrupt the mp3 file and make it not playable as manan said. – Chirag Shah Mar 28 '12 at 05:00
  • @MKJParekh Your answer is helping so many coders and i am one of them But i have different problem , may be you have answer. I want to concatenate multiple mp3 files . Is it possible to achieve with MyID3. If you have answer i can post a question for . Thanx for all your help – Harsh Jul 30 '12 at 10:05
  • Frankly speaking @Harsh , I haven't work on that ID3 library ..just used it to solve this problem of the friend, But I suggest you that you should straight away start a question in SO with complete detail of your problem and I am sure that you will get your answer from the any corner of world. – MKJParekh Jul 30 '12 at 11:14
  • @MKJParekh I did as mentioned in the answer but just like Chirag said, the file gets corrupted and doesn't play. Also the title doesn't change but when I debug this class metadata.getSongTitle() returns the name that I changed. Can you please help ? – varunkr Feb 03 '16 at 14:33
  • I don't have much knowledge on it currently this was years before, please ask a new question with proper issue/code/current result/expected result and others will help. @varunkr – MKJParekh Feb 04 '16 at 05:28
  • Eeven I am getting error, If any1 has any hint, please post it. – AkhilGite Nov 05 '16 at 08:57
  • 2
    Given website doesn't contain downloading link and website also doesn't available – Krishna Vyas Jan 21 '19 at 08:18
18

Actually, FasteKerinns's code is quite good. You should just change

new MyID3().write(src, dst, src_set, meta);

to

new MyID3().update(src, src_set, meta);

which means you don't need dst variable at all.

Additionaly, I have this piece of code which refreshes song that is modified in MediaStore:

 scanner=new MediaScannerConnection(getApplicationContext(),  
            new MediaScannerConnectionClient() {    

      public void onScanCompleted(String path, Uri uri) {
              scanner.disconnect(); 
      }

      public void onMediaScannerConnected() {
              scanner.scanFile(path, "audio/*");    
      }
  });

  scanner.connect();
Daniel Nugent
  • 43,104
  • 15
  • 109
  • 137
shtrule
  • 658
  • 10
  • 23
5

And most important point is that the edited ID3 tags were shown only into the my app.

If you edit the file then anybody will see that. You can create your own database of mediafiles (like Android's database) and just store the modified data there.

zapl
  • 63,179
  • 10
  • 123
  • 154
  • so waht you are saying I should not change the original data, instead place them in sqlite db, and display that stored data – Nixit Patel Mar 15 '12 at 05:43
  • If you don't want that any other app can see your modified ID3 tags then the only way you can do that is by locally storing the information in e.g. a database. If you modify the file, then every app can see that because there is only that one file. The ID3 tag you see in mediaplayers will not immediately change because other apps or Android's mediascanner will have to rescan the files first but it will probably do so at some point in time – zapl Mar 15 '12 at 10:07
  • @zapl yes, but i found beter solution in Soni's answer. – Chirag Shah Mar 19 '12 at 13:03
  • yeh you are right...cause other available library are also doing the same..i think – MKJParekh Mar 19 '12 at 13:18
1

I have created a sample app, based on the above answers, you can download the sample implementation from here https://github.com/mickyarun/AndroidSongMetaDataUpdate.git

arun-r
  • 3,104
  • 2
  • 22
  • 20