org.jaudiotagger.tag.FieldKey Java Examples

The following examples show how to use org.jaudiotagger.tag.FieldKey. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Id3Reader.java    From QuickLyric with GNU General Public License v3.0 6 votes vote down vote up
public static Lyrics getLyrics(Context context, String artist, String title, boolean requestPermission) {
    String text = null;
    try {
        for (File file : getFiles(context, artist, title, requestPermission)) {
            AudioFile af = AudioFileIO.read(file);
            TagOptionSingleton.getInstance().setAndroid(true);
            Tag tag = af.getTag();
            text = tag.getFirst(FieldKey.LYRICS);
            if (!text.isEmpty()) {
                text = text.replaceAll("\n", "<br/>");
                break;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
    if (TextUtils.isEmpty(text))
        return null;
    Lyrics lyrics = new Lyrics(POSITIVE_RESULT);
    lyrics.setArtist(artist);
    lyrics.setTitle(title);
    lyrics.setText(text);
    lyrics.setSource("Storage");
    return lyrics;
}
 
Example #2
Source File: JaudiotaggerParser.java    From subsonic with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Parses meta data for the given music file. No guessing or reformatting is done.
 *
 *
 * @param file The music file to parse.
 * @return Meta data for the file.
 */
@Override
public MetaData getRawMetaData(File file) {

    MetaData metaData = new MetaData();

    try {
        AudioFile audioFile = AudioFileIO.read(file);
        Tag tag = audioFile.getTag();
        if (tag != null) {
            metaData.setAlbumName(getTagField(tag, FieldKey.ALBUM));
            metaData.setTitle(getTagField(tag, FieldKey.TITLE));
            metaData.setYear(parseYear(getTagField(tag, FieldKey.YEAR)));
            metaData.setGenre(mapGenre(getTagField(tag, FieldKey.GENRE)));
            metaData.setDiscNumber(parseInteger(getTagField(tag, FieldKey.DISC_NO)));
            metaData.setTrackNumber(parseTrackNumber(getTagField(tag, FieldKey.TRACK)));

            String songArtist = getTagField(tag, FieldKey.ARTIST);
            String albumArtist = getTagField(tag, FieldKey.ALBUM_ARTIST);
            metaData.setArtist(StringUtils.isBlank(songArtist) ? albumArtist : songArtist);
            metaData.setAlbumArtist(StringUtils.isBlank(albumArtist) ? songArtist : albumArtist);
        }

        AudioHeader audioHeader = audioFile.getAudioHeader();
        if (audioHeader != null) {
            metaData.setVariableBitRate(audioHeader.isVariableBitRate());
            metaData.setBitRate((int) audioHeader.getBitRateAsNumber());
            metaData.setDurationSeconds(audioHeader.getTrackLength());
        }


    } catch (Throwable x) {
        LOG.warn("Error when parsing tags in " + file, x);
    }

    return metaData;
}
 
Example #3
Source File: LyricBottomSheet.java    From MusicPlayer with GNU General Public License v3.0 6 votes vote down vote up
@OnClick(R.id.save)
void saveLyric() {
    if(getActivity()!=null)
        Util.hideSoftKeyboard(getActivity());

    if(mEditingSong !=null) {
        ArrayList<String> path = new ArrayList<>(1);
        path.add(mEditingSong.data);

        Map<FieldKey, String> fieldKeyValueMap = new EnumMap<>(FieldKey.class);
        /*fieldKeyValueMap.put(FieldKey.TITLE, songTitle.getText().toString());
        fieldKeyValueMap.put(FieldKey.ALBUM, albumTitle.getText().toString());
        fieldKeyValueMap.put(FieldKey.ARTIST, artist.getText().toString());
        fieldKeyValueMap.put(FieldKey.GENRE, genre.getText().toString());
        fieldKeyValueMap.put(FieldKey.YEAR, year.getText().toString());
        fieldKeyValueMap.put(FieldKey.TRACK, trackNumber.getText().toString());*/
        fieldKeyValueMap.put(FieldKey.LYRICS, mEditText.getText().toString());
        writeValuesToFiles(path, fieldKeyValueMap, null);
    }
}
 
Example #4
Source File: AbsTagEditorActivity.java    From VinylMusicPlayer with GNU General Public License v3.0 6 votes vote down vote up
protected void writeValuesToFiles(@NonNull final Map<FieldKey, String> fieldKeyValueMap, @Nullable final ArtworkInfo artworkInfo) {
    Util.hideSoftKeyboard(this);

    hideFab();

    savedSongPaths = getSongPaths();
    savedTags = fieldKeyValueMap;
    savedArtworkInfo = artworkInfo;

    if (!SAFUtil.isSAFRequired(savedSongPaths)) {
        writeTags(savedSongPaths);
    } else {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            if (SAFUtil.isSDCardAccessGranted(this)) {
                writeTags(savedSongPaths);
            } else {
                startActivityForResult(new Intent(this, SAFGuideActivity.class), SAFGuideActivity.REQUEST_CODE_SAF_GUIDE);
            }
        } else {
            writeTagsKitkat();
        }
    }
}
 
Example #5
Source File: Id3Writer.java    From QuickLyric with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected Boolean doInBackground(Object... params) {
    Lyrics editedLyrics = (Lyrics) params[0];
    File musicFile = (File) params[1];
    boolean failed = false;

    if (musicFile != null)
        try {
            AudioFile af = AudioFileIO.read(musicFile);
            TagOptionSingleton.getInstance().setAndroid(true);
            Tag tags = af.getTag();
            tags.setField(FieldKey.ARTIST, editedLyrics.getArtist());
            tags.setField(FieldKey.TITLE, editedLyrics.getTitle());
            tags.setField(FieldKey.LYRICS, Html.fromHtml(editedLyrics.getText()).toString());
            af.setTag(tags);
            AudioFileIO.write(af);
        } catch (CannotReadException | IOException | ReadOnlyFileException | TagException
                | InvalidAudioFrameException | NullPointerException | CannotWriteException e) {
            e.printStackTrace();
            failed = true;
        }
    return failed;
}
 
Example #6
Source File: AbsTagEditorActivity.java    From VinylMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
protected String getAlbumTitle() {
    try {
        return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.ALBUM);
    } catch (Exception ignored) {
        return null;
    }
}
 
Example #7
Source File: AbsTagEditorActivity.java    From VinylMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
protected String getLyrics() {
    try {
        return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.LYRICS);
    } catch (Exception ignored) {
        return null;
    }
}
 
Example #8
Source File: AbsTagEditorActivity.java    From VinylMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
protected String getTrackNumber() {
    try {
        return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.TRACK);
    } catch (Exception ignored) {
        return null;
    }
}
 
Example #9
Source File: AbsTagEditorActivity.java    From Phonograph with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
protected String getAlbumTitle() {
    try {
        return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.ALBUM);
    } catch (Exception ignored) {
        return null;
    }
}
 
Example #10
Source File: AbsTagEditorActivity.java    From Phonograph with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
protected String getArtistName() {
    try {
        return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.ARTIST);
    } catch (Exception ignored) {
        return null;
    }
}
 
Example #11
Source File: AbsTagEditorActivity.java    From Phonograph with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
protected String getAlbumArtistName() {
    try {
        return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.ALBUM_ARTIST);
    } catch (Exception ignored) {
        return null;
    }
}
 
Example #12
Source File: AbsTagEditorActivity.java    From Phonograph with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
protected String getGenreName() {
    try {
        return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.GENRE);
    } catch (Exception ignored) {
        return null;
    }
}
 
Example #13
Source File: AbsTagEditorActivity.java    From Phonograph with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
protected String getSongYear() {
    try {
        return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.YEAR);
    } catch (Exception ignored) {
        return null;
    }
}
 
Example #14
Source File: AbsTagEditorActivity.java    From Phonograph with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
protected String getTrackNumber() {
    try {
        return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.TRACK);
    } catch (Exception ignored) {
        return null;
    }
}
 
Example #15
Source File: AbsTagEditorActivity.java    From Phonograph with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
protected String getLyrics() {
    try {
        return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.LYRICS);
    } catch (Exception ignored) {
        return null;
    }
}
 
Example #16
Source File: AbsTagEditorActivity.java    From Phonograph with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
protected String getSongTitle() {
    try {
        return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.TITLE);
    } catch (Exception ignored) {
        return null;
    }
}
 
Example #17
Source File: AbsTagEditorActivity.java    From VinylMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
protected String getAlbumArtistName() {
    try {
        return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.ALBUM_ARTIST);
    } catch (Exception ignored) {
        return null;
    }
}
 
Example #18
Source File: AbsTagEditorActivity.java    From VinylMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
protected String getArtistName() {
    try {
        return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.ARTIST);
    } catch (Exception ignored) {
        return null;
    }
}
 
Example #19
Source File: AbsTagEditorActivity.java    From RetroMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
protected String getSongTitle() {
    try {
        return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.TITLE);
    } catch (Exception ignored) {
        return null;
    }
}
 
Example #20
Source File: AbsTagEditorActivity.java    From VinylMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
protected String getSongTitle() {
    try {
        return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.TITLE);
    } catch (Exception ignored) {
        return null;
    }
}
 
Example #21
Source File: AlbumTagEditorActivity.java    From RetroMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void save() {
    Map<FieldKey, String> fieldKeyValueMap = new EnumMap<>(FieldKey.class);
    fieldKeyValueMap.put(FieldKey.ALBUM, albumTitle.getText().toString());
    //android seems not to recognize album_artist field so we additionally write the normal artist field
    fieldKeyValueMap.put(FieldKey.ARTIST, albumArtist.getText().toString());
    fieldKeyValueMap.put(FieldKey.ALBUM_ARTIST, albumArtist.getText().toString());
    fieldKeyValueMap.put(FieldKey.GENRE, genre.getText().toString());
    fieldKeyValueMap.put(FieldKey.YEAR, year.getText().toString());

    writeValuesToFiles(fieldKeyValueMap, deleteAlbumArt ? new ArtworkInfo(getId(), null) : albumArtBitmap == null ? null : new ArtworkInfo(getId(), albumArtBitmap));
}
 
Example #22
Source File: AbsTagEditorActivity.java    From RetroMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
protected String getAlbumTitle() {
    try {
        return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.ALBUM);
    } catch (Exception ignored) {
        return null;
    }
}
 
Example #23
Source File: AlbumTagEditorActivity.java    From VinylMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void save() {
    Map<FieldKey, String> fieldKeyValueMap = new EnumMap<>(FieldKey.class);
    fieldKeyValueMap.put(FieldKey.ALBUM, albumTitle.getText().toString());
    //android seems not to recognize album_artist field so we additionally write the normal artist field
    fieldKeyValueMap.put(FieldKey.ARTIST, artist.getText().toString());
    fieldKeyValueMap.put(FieldKey.ALBUM_ARTIST, albumArtist.getText().toString());
    fieldKeyValueMap.put(FieldKey.GENRE, genre.getText().toString());
    fieldKeyValueMap.put(FieldKey.YEAR, year.getText().toString());

    writeValuesToFiles(fieldKeyValueMap, deleteAlbumArt ? new ArtworkInfo(getId(), null) : albumArtBitmap == null ? null : new ArtworkInfo(getId(), albumArtBitmap));
}
 
Example #24
Source File: SongTagEditorActivity.java    From VinylMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void save() {
    Map<FieldKey, String> fieldKeyValueMap = new EnumMap<>(FieldKey.class);
    fieldKeyValueMap.put(FieldKey.TITLE, songTitle.getText().toString());
    fieldKeyValueMap.put(FieldKey.ALBUM, albumTitle.getText().toString());
    fieldKeyValueMap.put(FieldKey.ARTIST, artist.getText().toString());
    fieldKeyValueMap.put(FieldKey.GENRE, genre.getText().toString());
    fieldKeyValueMap.put(FieldKey.YEAR, year.getText().toString());
    fieldKeyValueMap.put(FieldKey.TRACK, trackNumber.getText().toString());
    fieldKeyValueMap.put(FieldKey.LYRICS, lyrics.getText().toString());
    writeValuesToFiles(fieldKeyValueMap, null);
}
 
Example #25
Source File: AbsTagEditorActivity.java    From RetroMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
protected String getLyrics() {
    try {
        return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.LYRICS);
    } catch (Exception ignored) {
        return null;
    }
}
 
Example #26
Source File: AbsTagEditorActivity.java    From RetroMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
protected String getTrackNumber() {
    try {
        return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.TRACK);
    } catch (Exception ignored) {
        return null;
    }
}
 
Example #27
Source File: AbsTagEditorActivity.java    From RetroMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
protected String getSongYear() {
    try {
        return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.YEAR);
    } catch (Exception ignored) {
        return null;
    }
}
 
Example #28
Source File: AbsTagEditorActivity.java    From RetroMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
protected String getGenreName() {
    try {
        return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.GENRE);
    } catch (Exception ignored) {
        return null;
    }
}
 
Example #29
Source File: AbsTagEditorActivity.java    From RetroMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
protected String getAlbumArtistName() {
    try {
        return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.ALBUM_ARTIST);
    } catch (Exception ignored) {
        return null;
    }
}
 
Example #30
Source File: AbsTagEditorActivity.java    From RetroMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
protected String getArtistName() {
    try {
        return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.ARTIST);
    } catch (Exception ignored) {
        return null;
    }
}