Strange behavior in android

Issue #122 invalid
Former user created an issue

i have some simple code

TagOptionSingleton.getInstance().setAndroid(true);
MP3File mp3 = (MP3File)AudioFileIO.read(new File("/storage/sdcard0/music.mp3"));
AbstractID3v2Tag tag = mp3.getID3v2Tag();
tag.setField(FieldKey.TITLE,titleE.getText().toString());
tag.setField(FieldKey.ALBUM,albumE.getText().toString());
tag.setField(FieldKey.ARTIST,artistE.getText().toString());
tag.setField(FieldKey.YEAR,yearE.getText().toString());
mp3.commit();

it work but the strange thing is that the media player shows an old tag until you restart the device or save the file on your computer even if the data is read immediately after this editing they have changed other editing programs do not recognize the new tags before rebooting maybe some problem with IO streams closing on Android ?

Comments (5)

  1. IJabz repo owner

    Can you show your reading code as the code above in isolation doesnt really tell us anything

  2. Alex Pol
    public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    
        Button button;
    
        EditText titleE,artistE,yearE,albumE;
        MP3File mp3;
        ID3v24Tag tag;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            button = (Button)findViewById(R.id.button);
    
            titleE = (EditText)findViewById(R.id.editText);
            artistE = (EditText)findViewById(R.id.editText4);
            albumE = (EditText)findViewById(R.id.editText2);
            yearE = (EditText)findViewById(R.id.editText3);
    
           TagOptionSingleton.getInstance().setAndroid(true);
    
            try {
                mp3 = (MP3File)AudioFileIO.read(new File("/storage/sdcard0/music.mp3"));
                tag = mp3.getID3v2TagAsv24();
    
                title.setText(tag.getFirst(FieldKey.TITLE));
                artist.setText(tag.getFirst(FieldKey.ARTIST));
                year.setText(tag.getFirst(FieldKey.YEAR));
                album.setText(tag.getFirst(FieldKey.ALBUM));
    
            } catch (CannotReadException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (TagException e) {
                e.printStackTrace();
            } catch (ReadOnlyFileException e) {
                e.printStackTrace();
            } catch (InvalidAudioFrameException e) {
                e.printStackTrace();
            }
        }
    
        @Override
        public void onClick(View v) {
            if(v.getId()==R.id.button){
                try {
                    tag.setField(FieldKey.TITLE,titleE.getText().toString());
                    tag.setField(FieldKey.ALBUM,albumE.getText().toString());
                    tag.setField(FieldKey.ARTIST,artistE.getText().toString());
                    tag.setField(FieldKey.YEAR,yearE.getText().toString());
                    mp3.commit();
                } catch (FieldDataInvalidException e) {
                    e.printStackTrace();
                } catch (CannotWriteException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    

    its my full code, also i have permissins to r/w external storage, i use 2.2.5 version,same code windows work correctly!also after changing the tags in my code, file manager displays the time when I changed the tags, that is, change the file manager sees

  3. Eric Snell

    Short answer is you probably need to tell the MediaStore to rescan. Here's a link that has some code you can use MediaScanner.

    I'm not sure which media player you're talking about, but no matter which, it needs to know you've made a change. This means the player must rescan the file, or read the results from the MediaStore after Android scans the file. Applications such as the one I'm developing, or Poweramp, have their own scanner and will detect file changes and rescan automatically. If you simply have the MediaScanner run you're pretty much covered.

  4. Log in to comment