本文整理匯總了Java中org.jaudiotagger.audio.AudioFileIO類的典型用法代碼示例。如果您正苦於以下問題:Java AudioFileIO類的具體用法?Java AudioFileIO怎麽用?Java AudioFileIO使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
AudioFileIO類屬於org.jaudiotagger.audio包,在下文中一共展示了AudioFileIO類的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: persistThroughFile
import org.jaudiotagger.audio.AudioFileIO; //導入依賴的package包/類
/**
* Writes changes in tags directly into file and closes activity.
* Call this if you're absolutely sure everything is right with file and tag.
*/
private void persistThroughFile() {
try {
AudioFileIO.write(mAudioFile);
Toast.makeText(this, R.string.file_written_successfully, Toast.LENGTH_SHORT).show();
// update media database
File persisted = mAudioFile.getFile();
MediaScannerConnection.scanFile(this, new String[]{persisted.getAbsolutePath()}, null, null);
} catch (CannotWriteException e) {
Log.e(LOG_TAG,
String.format(getString(R.string.error_audio_file), mAudioFile.getFile().getPath()), e);
Toast.makeText(this,
String.format(getString(R.string.error_audio_file) + ", %s",
mAudioFile.getFile().getPath(),
e.getLocalizedMessage()),
Toast.LENGTH_LONG).show();
}
}
示例5: 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();
}
}
}
示例6: 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
}
}
示例7: runCommit
import org.jaudiotagger.audio.AudioFileIO; //導入依賴的package包/類
@Override
protected void runCommit(TableEntry entry)
{
try
{
Tag tag = AudioFileIO.read(new File(entry.FilePath)).getTag();
tag.setField(FieldKey.TITLE, entry.NewTitle);
tag.setField(FieldKey.TRACK, entry.TrackNumber);
Utils.saveTagToFile(entry.FilePath, tag);
LOG.log(Level.FINE, "Track number removed from name: " + tag.toString());
}
catch (CannotReadException | IOException | TagException
| ReadOnlyFileException| InvalidAudioFrameException e)
{
LOG.log(Level.WARNING, "Failed to write title w/o track num to tag: " + entry.FilePath);
}
}
示例8: 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;
}
}
示例9: getSoundLength
import org.jaudiotagger.audio.AudioFileIO; //導入依賴的package包/類
public static double getSoundLength(File soundFile)
{
try
{
AudioHeader audioHeader = AudioFileIO.read(soundFile).getAudioHeader();
if (soundFile.getName().endsWith(".mp3"))
{
return ((MP3AudioHeader)audioHeader).getPreciseTrackLength();
}
else
{
return ((GenericAudioHeader)audioHeader).getPreciseLength();
}
} catch (Exception e)
{
e.printStackTrace();
}
return 0;
}
示例10: 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;
}
示例11: 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;
}
示例12: 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;
}
示例13: 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
}
}
示例14: 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;
}
示例15: 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;
}