Java Code Examples for org.jaudiotagger.tag.FieldKey

The following examples show how to use org.jaudiotagger.tag.FieldKey. These examples are extracted from open source projects. 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 Project: MusicPlayer   Source File: LyricBottomSheet.java    License: 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 2
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 3
Source Project: subsonic   Source File: JaudiotaggerParser.java    License: 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 4
Source Project: QuickLyric   Source File: Id3Writer.java    License: 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 5
Source Project: QuickLyric   Source File: Id3Reader.java    License: 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 6
private static String getTagField(Tag tag, FieldKey fieldKey) {
    try {
        return StringUtils.trimToNull(tag.getFirst(fieldKey));
    } catch (Exception x) {
        // Ignored.
        return null;
    }
}
 
Example 7
@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, songNumber.getText().toString());
    fieldKeyValueMap.put(FieldKey.LYRICS, lyrics.getText().toString());
    writeValuesToFiles(fieldKeyValueMap, null);
}
 
Example 8
@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 9
@Nullable
protected String getSongTitle() {
    try {
        return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.TITLE);
    } catch (Exception ignored) {
        return null;
    }
}
 
Example 10
@Nullable
protected String getAlbumTitle() {
    try {
        return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.ALBUM);
    } catch (Exception ignored) {
        return null;
    }
}
 
Example 11
@Nullable
protected String getArtistName() {
    try {
        return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.ARTIST);
    } catch (Exception ignored) {
        return null;
    }
}
 
Example 12
@Nullable
protected String getAlbumArtistName() {
    try {
        return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.ALBUM_ARTIST);
    } catch (Exception ignored) {
        return null;
    }
}
 
Example 13
@Nullable
protected String getGenreName() {
    try {
        return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.GENRE);
    } catch (Exception ignored) {
        return null;
    }
}
 
Example 14
@Nullable
protected String getSongYear() {
    try {
        return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.YEAR);
    } catch (Exception ignored) {
        return null;
    }
}
 
Example 15
@Nullable
protected String getSongNumber() {
    try {
        return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.TRACK);
    } catch (Exception ignored) {
        return null;
    }
}
 
Example 16
@Nullable
protected String getLyrics() {
    try {
        return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.LYRICS);
    } catch (Exception ignored) {
        return null;
    }
}
 
Example 17
Source Project: Orin   Source File: SongTagEditorActivity.java    License: 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 18
Source Project: Orin   Source File: AlbumTagEditorActivity.java    License: 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 19
Source Project: Orin   Source File: AbsTagEditorActivity.java    License: 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 Project: Orin   Source File: AbsTagEditorActivity.java    License: 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 21
Source Project: Orin   Source File: AbsTagEditorActivity.java    License: 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 22
Source Project: Orin   Source File: AbsTagEditorActivity.java    License: 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 23
Source Project: Orin   Source File: AbsTagEditorActivity.java    License: 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 24
Source Project: Orin   Source File: AbsTagEditorActivity.java    License: 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 25
Source Project: Orin   Source File: AbsTagEditorActivity.java    License: 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 26
Source Project: Orin   Source File: AbsTagEditorActivity.java    License: 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 27
Source Project: airsonic   Source File: JaudiotaggerParser.java    License: GNU General Public License v3.0 5 votes vote down vote up
private static String getTagField(Tag tag, FieldKey fieldKey) {
    try {
        return StringUtils.trimToNull(tag.getFirst(fieldKey));
    } catch (Exception x) {
        // Ignored.
        return null;
    }
}
 
Example 28
@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, deleteAlbumArt ? new ArtworkInfo(getId(), null) : albumArtBitmap == null ? null : new ArtworkInfo(getId(), albumArtBitmap));

    writeValuesToFiles(fieldKeyValueMap, null);
}
 
Example 29
@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 30
@Nullable
protected String getSongTitle() {
    try {
        return getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirst(FieldKey.TITLE);
    } catch (Exception ignored) {
        return null;
    }
}