当前位置: 首页>>代码示例>>Java>>正文


Java AudioFile.getTag方法代码示例

本文整理汇总了Java中org.jaudiotagger.audio.AudioFile.getTag方法的典型用法代码示例。如果您正苦于以下问题:Java AudioFile.getTag方法的具体用法?Java AudioFile.getTag怎么用?Java AudioFile.getTag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jaudiotagger.audio.AudioFile的用法示例。


在下文中一共展示了AudioFile.getTag方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: from

import org.jaudiotagger.audio.AudioFile; //导入方法依赖的package包/类
public static Song from(final URI uri) {
	try {
		AudioFile f = AudioFileIO.read(new File(uri));
		Tag tag = f.getTag();

		String trackStr = tag.getFirst(FieldKey.TRACK);
		if (trackStr.isEmpty()) { return null; }

		Artist artist = new Artist(tag.getFirst(FieldKey.ARTIST));
		Artwork artwork = tag.getFirstArtwork();
		Album album = new Album(tag.getFirst(FieldKey.ALBUM), artwork);
		String title = tag.getFirst(FieldKey.TITLE);
		int track = Integer.parseInt(trackStr);
		Integer seconds = f.getAudioHeader().getTrackLength() + 1;

		return new Song(title, artist, album, track, seconds, uri);
	} catch (CannotReadException | IOException | TagException | InvalidAudioFrameException
			| ReadOnlyFileException e) {
		e.printStackTrace();
		return null;
	}
}
 
开发者ID:jakemanning,项目名称:boomer-tuner,代码行数:23,代码来源:Song.java

示例2: insertLyrics

import org.jaudiotagger.audio.AudioFile; //导入方法依赖的package包/类
/**
 * Insert Lyrics
 *
 * @param path
 * @param lyrics
 * @return
 */
public static boolean insertLyrics(String path, String lyrics) {
    File f = new File(path);
    if (f.exists()) {
        try {
            AudioFile audioFile = AudioFileIO.read(f);
            if (audioFile == null) {
                return false;
            }
            TagOptionSingleton.getInstance().setAndroid(true);
            Tag tag = audioFile.getTag();
            if (tag == null) {
                return false;
            }
            tag.deleteField(FieldKey.LYRICS);
            tag.setField(FieldKey.LYRICS, lyrics);
            audioFile.setTag(tag);
            AudioFileIO.write(audioFile);
            return true;
        } catch (CannotReadException | CannotWriteException | InvalidAudioFrameException | TagException | IOException | ReadOnlyFileException e) {
            e.printStackTrace();
        }
    }
    return false;
}
 
开发者ID:RajneeshSingh007,项目名称:MusicX-music-player,代码行数:32,代码来源:LyricsHelper.java

示例3: readFileData

import org.jaudiotagger.audio.AudioFile; //导入方法依赖的package包/类
/**
 * Read the contents of the file.
 */
private void readFileData() {
    try {
        AudioFile audioFile = AudioFileIO.read(m_file);
        Tag tag = audioFile.getTag();
        if (tag == null) {
            tag = fillEmptyTag(audioFile);
        }
        parseTags(tag);

        MP3File mp3File = new MP3File(m_file);
        m_length = mp3File.getMP3AudioHeader().getPreciseTrackLength();
        m_frames = mp3File.getMP3AudioHeader().getNumberOfFrames();
    } catch (Exception e) {
        e.printStackTrace(); //for now
    }
}
 
开发者ID:ijh165,项目名称:Gamma-Music-Manager,代码行数:20,代码来源:Song.java

示例4: doInBackground

import org.jaudiotagger.audio.AudioFile; //导入方法依赖的package包/类
@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;
}
 
开发者ID:QuickLyric,项目名称:QuickLyric,代码行数:24,代码来源:Id3Writer.java

示例5: getLyrics

import org.jaudiotagger.audio.AudioFile; //导入方法依赖的package包/类
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;
}
 
开发者ID:QuickLyric,项目名称:QuickLyric,代码行数:27,代码来源:Id3Reader.java

示例6: buildMedia

import org.jaudiotagger.audio.AudioFile; //导入方法依赖的package包/类
@Override
protected Media buildMedia(final MediaUploadBatch context) throws MediaReaderException, IOException {
    final String fileName = getFile().getAbsolutePath();
    try {
        final AudioFile audioFile = AudioFileIO.read(getFile());
        final Tag tag = audioFile.getTag();
        final AudioHeader header = audioFile.getAudioHeader();

        final byte[] thumbnail;
        final List<Artwork> artwork = tag.getArtworkList();
        if (artwork.isEmpty()) {
            thumbnail = new byte[0];
        } else {
            thumbnail = artwork.get(0).getBinaryData();
        }

        final Map<String, Object> metadata = new HashMap<>(2);
        metadata.put("Tags", copyTags(tag));
        metadata.put("Headers", copyHeaders(header));

        return new Media(getFile(), fileName, context.getTemplate(), metadata, thumbnail);
    } catch (final CannotReadException | TagException | ReadOnlyFileException | InvalidAudioFrameException e) {
        throw new MediaReaderException(e);
    }
}
 
开发者ID:edouardhue,项目名称:comeon,代码行数:26,代码来源:AudioReader.java

示例7: readTag

import org.jaudiotagger.audio.AudioFile; //导入方法依赖的package包/类
/**
 * Read the tag information from a flac file
 *
 * @param flacFile the flac file
 * @return the tag information, or null when reading the tag information
 *         failed or the tag is not a flac tag.
 */
TagInformation readTag(File flacFile) {
  AudioFile af;
  try {
    af = AudioFileIO.read(flacFile);
  }
  catch (Throwable e) {
    logger.log(Level.WARNING, String.format(Messages.getString("FlacToMp3Impl.5"), flacFile.getPath()), e); //$NON-NLS-1$
    return null;
  }

  Tag tag = af.getTag();
  if (!(tag instanceof FlacTag)) {
    /* can't be covered by a test */
    return null;
  }

  return new TagInformation((FlacTag) tag);
}
 
开发者ID:fhuberts,项目名称:musicTreePrograms,代码行数:26,代码来源:FlacToMp3Impl.java

示例8: readMp3Tag

import org.jaudiotagger.audio.AudioFile; //导入方法依赖的package包/类
private static AbstractID3Tag readMp3Tag(File flacFile, boolean v24) {
  AudioFile af;
  try {
    af = AudioFileIO.read(flacFile);
  }
  catch (Throwable e) {
    System.err.println(String.format("Failed to read mp3 file", flacFile.getPath()));
    return null;
  }

  Tag tag = af.getTag();
  if (v24) {
    assert (tag instanceof ID3v24Tag);
    return (ID3v24Tag) tag;
  }

  assert (tag instanceof ID3v23Tag);
  return (ID3v23Tag) tag;
}
 
开发者ID:fhuberts,项目名称:musicTreePrograms,代码行数:20,代码来源:TestFlacToMp3Impl.java

示例9: getRawMetaData

import org.jaudiotagger.audio.AudioFile; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:airsonic,项目名称:airsonic,代码行数:44,代码来源:JaudiotaggerParser.java

示例10: getArtwork

import org.jaudiotagger.audio.AudioFile; //导入方法依赖的package包/类
Artwork getArtwork() {
	try {
		AudioFile f = AudioFileIO.read(new File(uri));
		Tag tag = f.getTag();
		return tag.getFirstArtwork();
	} catch (CannotReadException | IOException | TagException | InvalidAudioFrameException
			| ReadOnlyFileException e) {
		e.printStackTrace();
		return null;
	}
}
 
开发者ID:jakemanning,项目名称:boomer-tuner,代码行数:12,代码来源:Song.java

示例11: getInbuiltLyrics

import org.jaudiotagger.audio.AudioFile; //导入方法依赖的package包/类
/**
 * Get Inbuilt Lyrics
 *
 * @param path
 * @return
 */
@NonNull
public static String getInbuiltLyrics(String path) {
    String lyrics;
    if (path != null) {
        File file = new File(path);
        AudioFile audioFile = null;
        Tag tag = null;
        if (file.exists()) {
            try {
                audioFile = AudioFileIO.read(file);
                if (audioFile != null) {
                    tag = audioFile.getTag();
                    if (tag != null) {
                        lyrics = tag.getFirst(FieldKey.LYRICS);
                        //lyrics = lyrics.replaceAll("\n", "</br>");
                        return lyrics;
                    } else {
                        return "No Lyrics found";
                    }
                }
            } catch (CannotReadException | ReadOnlyFileException | InvalidAudioFrameException | TagException | IOException e) {
                e.printStackTrace();
            }
        } else {
            Log.e("LyricsHelper", "file not exists");
        }
    }
    return "No Lyrics found";
}
 
开发者ID:RajneeshSingh007,项目名称:MusicX-music-player,代码行数:36,代码来源:LyricsHelper.java

示例12: Song

import org.jaudiotagger.audio.AudioFile; //导入方法依赖的package包/类
public Song(File file) {
    name = file.getName();
    if(file.exists()){
        fileLocation = file.getAbsolutePath();
        File parent = file.getParentFile();
        if(parent != null){
            directory = parent.getAbsolutePath();
        }
        try {
            AudioFile audioFile = AudioFileIO.read(getFile());
            Tag tag = audioFile.getTag();
            title = tag.getFirst(FieldKey.TITLE);
            album = tag.getFirst(FieldKey.ALBUM);
            artist = tag.getFirst(FieldKey.ARTIST);
            if (title.equals("")) {
                title = name;
            } else {
                name = title;
            }
            if (album.equals("")) {
                album = "Unknown Album";
            }
            if (artist.equals("")) {
                artist = "Uknown Artist";
            }
            Log.d(TAG, "Title: " + title + " album: " + album + " artist: " + artist);
        } catch (Exception exc) {
            Log.d(TAG, "Exception occurred while loading metadata for " + file.getAbsolutePath(), exc);
        }

        //this.hash = Utility.getMD5OfFile(file);
    }
    else{
        Log.d("Song", "File passed to Song constructor doesn't exist for song name " + name);
    }

}
 
开发者ID:chenshuiluke,项目名称:BeatPulse,代码行数:38,代码来源:Song.java

示例13: setTitle

import org.jaudiotagger.audio.AudioFile; //导入方法依赖的package包/类
/**
 * Set the title attribute of this song object and also the title tag in the metadata
 *
 * @param title the specified title
 */
public void setTitle(String title) {
    try {
        //update metadata
        AudioFile file = AudioFileIO.read(m_file);
        Tag tag = file.getTag();
        tag.setField(FieldKey.TITLE, title);
        AudioFileIO.write(file);
        //update object attr
        m_title = title;
    } catch (Exception e) {
        e.printStackTrace(); //for now
    }
}
 
开发者ID:ijh165,项目名称:Gamma-Music-Manager,代码行数:19,代码来源:Song.java

示例14: setArtist

import org.jaudiotagger.audio.AudioFile; //导入方法依赖的package包/类
/**
 * Set the artist attribute of this song object and also the artist tag in the metadata
 *
 * @param artist the specified artist
 */
public void setArtist(String artist) {
    try {
        //update metadata
        AudioFile file = AudioFileIO.read(m_file);
        Tag tag = file.getTag();
        tag.setField(FieldKey.ARTIST, artist);
        AudioFileIO.write(file);
        //update object attr
        m_artist = artist;
    } catch (Exception e) {
        e.printStackTrace(); //for now
    }
}
 
开发者ID:ijh165,项目名称:Gamma-Music-Manager,代码行数:19,代码来源:Song.java

示例15: setAlbum

import org.jaudiotagger.audio.AudioFile; //导入方法依赖的package包/类
/**
 * Set the album attribute of this song object and also the album tag in the metadata
 *
 * @param album the specified album
 */
public void setAlbum(String album) {
    try {
        //update metadata
        AudioFile file = AudioFileIO.read(m_file);
        Tag tag = file.getTag();
        tag.setField(FieldKey.ALBUM, album);
        AudioFileIO.write(file);
        //update object attr
        m_album = album;
    } catch (Exception e) {
        e.printStackTrace(); //for now
    }
}
 
开发者ID:ijh165,项目名称:Gamma-Music-Manager,代码行数:19,代码来源:Song.java


注:本文中的org.jaudiotagger.audio.AudioFile.getTag方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。