本文整理汇总了Java中org.jaudiotagger.audio.AudioFileIO.read方法的典型用法代码示例。如果您正苦于以下问题:Java AudioFileIO.read方法的具体用法?Java AudioFileIO.read怎么用?Java AudioFileIO.read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jaudiotagger.audio.AudioFileIO
的用法示例。
在下文中一共展示了AudioFileIO.read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: from
import org.jaudiotagger.audio.AudioFileIO; //导入方法依赖的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;
}
}
示例2: insertLyrics
import org.jaudiotagger.audio.AudioFileIO; //导入方法依赖的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;
}
示例3: scanSingleDir
import org.jaudiotagger.audio.AudioFileIO; //导入方法依赖的package包/类
/**
* Recursive function to scan directory
*
* @param dir
*/
private void scanSingleDir(final File dir) {
final File[] audioFiles = dir.listFiles(new AudioFileFilter(false));
if (audioFiles.length > 0) {
for (File audioFile : audioFiles) {
count++;
try {
AudioFileIO.read(audioFile);
} catch (Throwable t) {
System.err.println("Unable to read record:" + count + ":" + audioFile.getPath());
failed++;
t.printStackTrace();
}
}
}
final File[] audioFileDirs = dir.listFiles(new DirFilter());
if (audioFileDirs.length > 0) {
for (File audioFileDir : audioFileDirs) {
scanSingleDir(audioFileDir);
}
}
}
示例4: playSong
import org.jaudiotagger.audio.AudioFileIO; //导入方法依赖的package包/类
@Override
public void playSong(SongData songData) {
if (songData != null && !songData.getTitle().equals(" ")) {
settingsFactory.setPlayingSong(songData);
this.currentPlayingSong = songData;
this.stopPlaying();
try {
File songFile = new File(songData.getPath());
AudioFile audioFile = AudioFileIO.read(songFile);
isPlaying = true;
player = new MediaPlayer(new Media(songFile.toURI().toURL().toExternalForm()));
songPlayerBarController.setupForPlayingMusic(audioFile);
player.play();
player.setOnEndOfMedia(this::playNextSong);
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例5: readFileData
import org.jaudiotagger.audio.AudioFileIO; //导入方法依赖的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
}
}
示例6: getAudioTrackLength
import org.jaudiotagger.audio.AudioFileIO; //导入方法依赖的package包/类
public int getAudioTrackLength(URL url) {
try {
// 只能获得本地歌曲文件的信息
AudioFile file = AudioFileIO.read(new File(url.toURI()));
// 获取音频文件的头信息
AudioHeader audioHeader = file.getAudioHeader();
// 文件长度 转换成时间
return audioHeader.getTrackLength();
} catch (CannotReadException | IOException | TagException
| ReadOnlyFileException | InvalidAudioFrameException
| URISyntaxException e) {
e.printStackTrace();
return -1;
}
}
示例7: readBPMFrom
import org.jaudiotagger.audio.AudioFileIO; //导入方法依赖的package包/类
@Override
public Integer readBPMFrom(File file) {
try {
MP3File f = (MP3File) AudioFileIO.read(file);
String bpmTag = "";
if (f.hasID3v2Tag()) {
ID3v24Tag tag = f.getID3v2TagAsv24();
bpmTag = tag.getFirst(ID3v24FieldKey.BPM);
if (!bpmTag.equals("")) {
return Integer.valueOf(bpmTag);
}
}
} catch (Exception e) {
// nop
}
return null;
}
示例8: readBPMFrom
import org.jaudiotagger.audio.AudioFileIO; //导入方法依赖的package包/类
@Override
public Integer readBPMFrom(File file) {
try {
org.jaudiotagger.audio.AudioFile f = AudioFileIO.read(file);
VorbisCommentTag ovtag = (VorbisCommentTag) f.getTag();
String bpmTag = ovtag.getFirst(VorbisCommentFieldKey.BPM);
if (!bpmTag.equals("")) {
return Integer.valueOf(bpmTag);
}
} catch (Exception e) {
// nop
}
return null;
}
示例9: readBPMFrom
import org.jaudiotagger.audio.AudioFileIO; //导入方法依赖的package包/类
@Override
public Integer readBPMFrom(File file) {
try {
org.jaudiotagger.audio.AudioFile f = AudioFileIO.read(file);
FlacTag tag = (FlacTag) f.getTag();
VorbisCommentTag ovtag = tag.getVorbisCommentTag();
String bpmTag = ovtag.getFirst(VorbisCommentFieldKey.BPM);
if (!bpmTag.equals("")) {
return Integer.valueOf(bpmTag);
}
} catch (Exception e) {
// nop
}
return null;
}
示例10: writeBPMTo
import org.jaudiotagger.audio.AudioFileIO; //导入方法依赖的package包/类
@Override
public void writeBPMTo(Integer bpm, File file) {
try {
org.jaudiotagger.audio.AudioFile f = AudioFileIO.read(file);
FlacTag tag = (FlacTag) f.getTag();
VorbisCommentTag ovtag = tag.getVorbisCommentTag();
ovtag.setField(ovtag.createField(VorbisCommentFieldKey.BPM, String.valueOf(bpm)));
f.commit();
} catch (Exception e) {
// nop
}
}
示例11: doInBackground
import org.jaudiotagger.audio.AudioFileIO; //导入方法依赖的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;
}
示例12: getLyrics
import org.jaudiotagger.audio.AudioFileIO; //导入方法依赖的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;
}
示例13: buildMedia
import org.jaudiotagger.audio.AudioFileIO; //导入方法依赖的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);
}
}
示例14: readTag
import org.jaudiotagger.audio.AudioFileIO; //导入方法依赖的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);
}
示例15: readMp3Tag
import org.jaudiotagger.audio.AudioFileIO; //导入方法依赖的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;
}