當前位置: 首頁>>代碼示例>>Java>>正文


Java AudioFileIO.read方法代碼示例

本文整理匯總了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;
	}
}
 
開發者ID:jakemanning,項目名稱:boomer-tuner,代碼行數:23,代碼來源:Song.java

示例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;
}
 
開發者ID:RajneeshSingh007,項目名稱:MusicX-music-player,代碼行數:32,代碼來源:LyricsHelper.java

示例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);
        }
    }
}
 
開發者ID:openaudible,項目名稱:openaudible,代碼行數:29,代碼來源:TestAudioTagger.java

示例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();
        }
    }
}
 
開發者ID:daothanhduy305,項目名稱:MusicHub,代碼行數:20,代碼來源:MainPlayerController.java

示例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
    }
}
 
開發者ID:ijh165,項目名稱:Gamma-Music-Manager,代碼行數:20,代碼來源:Song.java

示例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;
	}

}
 
開發者ID:JhPocket,項目名稱:HubPlayer,代碼行數:19,代碼來源:BasicPlayer.java

示例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;
}
 
開發者ID:nwaldispuehl,項目名稱:interval-music-compositor,代碼行數:23,代碼來源:Mp3BPMReaderWriter.java

示例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;
}
 
開發者ID:nwaldispuehl,項目名稱:interval-music-compositor,代碼行數:18,代碼來源:OggBPMReaderWriter.java

示例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;
}
 
開發者ID:nwaldispuehl,項目名稱:interval-music-compositor,代碼行數:20,代碼來源:FlacBPMReaderWriter.java

示例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
  }

}
 
開發者ID:nwaldispuehl,項目名稱:interval-music-compositor,代碼行數:17,代碼來源:FlacBPMReaderWriter.java

示例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;
}
 
開發者ID:QuickLyric,項目名稱:QuickLyric,代碼行數:24,代碼來源:Id3Writer.java

示例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;
}
 
開發者ID:QuickLyric,項目名稱:QuickLyric,代碼行數:27,代碼來源:Id3Reader.java

示例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);
    }
}
 
開發者ID:edouardhue,項目名稱:comeon,代碼行數:26,代碼來源:AudioReader.java

示例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);
}
 
開發者ID:fhuberts,項目名稱:musicTreePrograms,代碼行數:26,代碼來源:FlacToMp3Impl.java

示例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;
}
 
開發者ID:fhuberts,項目名稱:musicTreePrograms,代碼行數:20,代碼來源:TestFlacToMp3Impl.java


注:本文中的org.jaudiotagger.audio.AudioFileIO.read方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。