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


Java AudioFile类代码示例

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


AudioFile类属于org.jaudiotagger.audio包,在下文中一共展示了AudioFile类的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: fileModified

import org.jaudiotagger.audio.AudioFile; //导入依赖的package包/类
/**
 * (overridden)
 *
 * @see org.jaudiotagger.audio.generic.AudioFileModificationListener#fileModified(org.jaudiotagger.audio.AudioFile,
 *File)
 */
public void fileModified(AudioFile original, File temporary) throws ModifyVetoException
{
    for (AudioFileModificationListener listener : this.listeners)
    {
        AudioFileModificationListener current = listener;
        try
        {
            current.fileModified(original, temporary);
        }
        catch (ModifyVetoException e)
        {
            vetoThrown(current, original, e);
            throw e;
        }
    }
}
 
开发者ID:GlennioTech,项目名称:MetadataEditor,代码行数:23,代码来源:ModificationHandler.java

示例3: fileWillBeModified

import org.jaudiotagger.audio.AudioFile; //导入依赖的package包/类
/**
 * (overridden)
 *
 * @see org.jaudiotagger.audio.generic.AudioFileModificationListener#fileWillBeModified(org.jaudiotagger.audio.AudioFile,
 *boolean)
 */
public void fileWillBeModified(AudioFile file, boolean delete) throws ModifyVetoException
{
    for (AudioFileModificationListener listener : this.listeners)
    {
        AudioFileModificationListener current = listener;
        try
        {
            current.fileWillBeModified(file, delete);
        }
        catch (ModifyVetoException e)
        {
            vetoThrown(current, file, e);
            throw e;
        }
    }
}
 
开发者ID:GlennioTech,项目名称:MetadataEditor,代码行数:23,代码来源:ModificationHandler.java

示例4: delete

import org.jaudiotagger.audio.AudioFile; //导入依赖的package包/类
/**
 * Delete the tag (if any) present in the given file
 *
 * @param af The file to process
 *
 * @throws CannotWriteException if anything went wrong
 * @throws org.jaudiotagger.audio.exceptions.CannotReadException
 */
@Override
public void delete(AudioFile af) throws CannotReadException, CannotWriteException
{
    File file = af.getFile();

    if (TagOptionSingleton.getInstance().isCheckIsWritable() && !file.canWrite())
    {
        throw new CannotWriteException(ErrorMessage.GENERAL_DELETE_FAILED
                .getMsg(file.getAbsolutePath()));
    }

    if (af.getFile().length() <= MINIMUM_FILESIZE)
    {
        throw new CannotWriteException(ErrorMessage.GENERAL_DELETE_FAILED_BECAUSE_FILE_IS_TOO_SMALL
                .getMsg(file));
    }
    deleteTag(af.getTag(), file);
}
 
开发者ID:GlennioTech,项目名称:MetadataEditor,代码行数:27,代码来源:AudioFileWriter2.java

示例5: write

import org.jaudiotagger.audio.AudioFile; //导入依赖的package包/类
/**
 * Replace with new tag
 *
 * @param af The file we want to process
 * @throws CannotWriteException
 */
@Override
public void write(AudioFile af) throws CannotWriteException
{
    File file = af.getFile();

    if (TagOptionSingleton.getInstance().isCheckIsWritable() && !file.canWrite())
    {
        logger.severe(ErrorMessage.GENERAL_WRITE_FAILED.getMsg(af.getFile()
                .getPath()));
        throw new CannotWriteException(ErrorMessage.GENERAL_WRITE_FAILED_TO_OPEN_FILE_FOR_EDITING
                .getMsg(file.getAbsolutePath()));
    }

    if (af.getFile().length() <= MINIMUM_FILESIZE)
    {
        throw new CannotWriteException(ErrorMessage.GENERAL_WRITE_FAILED_BECAUSE_FILE_IS_TOO_SMALL
                .getMsg(file));
    }
    writeTag(af.getTag(), file);
}
 
开发者ID:GlennioTech,项目名称:MetadataEditor,代码行数:27,代码来源:AudioFileWriter2.java

示例6: read

import org.jaudiotagger.audio.AudioFile; //导入依赖的package包/类
public AudioFile read(File f) throws CannotReadException, IOException, TagException, ReadOnlyFileException, InvalidAudioFrameException
{
    if(logger.isLoggable(Level.CONFIG))
    {
        logger.config(ErrorMessage.GENERAL_READ.getMsg(path));
    }

    if (!f.canRead())
    {
        throw new NoReadPermissionsException(ErrorMessage.GENERAL_READ_FAILED_DO_NOT_HAVE_PERMISSION_TO_READ_FILE.getMsg(f.getAbsolutePath()));
    }

    if (f.length() <= MINIMUM_SIZE_FOR_VALID_AUDIO_FILE)
    {
        throw new CannotReadException(ErrorMessage.GENERAL_READ_FAILED_FILE_TOO_SMALL.getMsg(f.getAbsolutePath()));
    }

    GenericAudioHeader info = getEncodingInfo(f);
    Tag tag = getTag(f);
    return new AudioFile(f, info, tag);
}
 
开发者ID:GlennioTech,项目名称:MetadataEditor,代码行数:22,代码来源:AudioFileReader2.java

示例7: getMinBaseFilenameAllowedForTempFile

import org.jaudiotagger.audio.AudioFile; //导入依赖的package包/类
/**
 * @param file
 * @return filename with audioformat separator stripped of, lengthened to ensure not too small for valid tempfile
 *         creation.
 */
public static String getMinBaseFilenameAllowedForTempFile(final File file)
{
    final String s = AudioFile.getBaseFilename(file);
    if (s.length() >= 3)
    {
        return s;
    }
    if (s.length() == 1)
    {
        return s + "000";
    }
    else if (s.length() == 1)
    {
        return s + "00";
    }
    else if (s.length() == 2)
    {
        return s + "0";
    }
    return s;
}
 
开发者ID:GlennioTech,项目名称:MetadataEditor,代码行数:27,代码来源:Utils.java

示例8: precheckWrite

import org.jaudiotagger.audio.AudioFile; //导入依赖的package包/类
/**
 * Prechecks before normal write
 * <p/>
 * <ul>
 * <li>If the tag is actually empty, remove the tag</li>
 * <li>if the file is not writable, throw exception
 * <li>
 * <li>If the file is too small to be a valid file, throw exception
 * <li>
 * </ul>
 *
 * @param af
 * @throws CannotWriteException
 */
private void precheckWrite(AudioFile af) throws CannotWriteException {
    // Preliminary checks
    try {
        if (af.getTag().isEmpty()) {
            delete(af);
            return;
        }
    } catch (CannotReadException re) {
        throw new CannotWriteException(ErrorMessage.GENERAL_WRITE_FAILED.getMsg(af.getFile().getPath()));
    }

    File file = af.getFile();
    if (TagOptionSingleton.getInstance().isCheckIsWritable() && !file.canWrite()) {
        logger.severe(ErrorMessage.GENERAL_WRITE_FAILED.getMsg(af.getFile().getPath()));
        throw new CannotWriteException(ErrorMessage.GENERAL_WRITE_FAILED_TO_OPEN_FILE_FOR_EDITING.getMsg(file.getAbsolutePath()));
    }

    if (af.getFile().length() <= MINIMUM_FILESIZE) {
        logger.severe(ErrorMessage.GENERAL_WRITE_FAILED_BECAUSE_FILE_IS_TOO_SMALL.getMsg(file.getAbsolutePath()));
        throw new CannotWriteException(ErrorMessage.GENERAL_WRITE_FAILED_BECAUSE_FILE_IS_TOO_SMALL.getMsg(file.getAbsolutePath()));
    }
}
 
开发者ID:GlennioTech,项目名称:MetadataEditor,代码行数:37,代码来源:AudioFileWriter.java

示例9: 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

示例10: playSong

import org.jaudiotagger.audio.AudioFile; //导入依赖的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

示例11: setupForPlayingMusic

import org.jaudiotagger.audio.AudioFile; //导入依赖的package包/类
/**
 * Function name:   setupForPlayingMusic
 * Usage:   this function is called when a song is played, to set up the corresponding info on the player bar to the
 * playing song.
 *
 * @param audioFile the song file of the playing song (since the song data doesn't contain the audio file).
 */
public void setupForPlayingMusic(AudioFile audioFile) {
    SongData currentPlayingSong = mainPlayerController.getCurrentPlayingSong();

    songTitleLabel.setText(currentPlayingSong.getTitle().substring(4, currentPlayingSong.getTitle().length()));
    songArtistLabel.setText(currentPlayingSong.getArtist());
    lengthCountLabel.setText("0:00");
    songProgressBar.setProgress(0f);
    songSeekBar.setValue(0f);
    songSeekBar.setMax((double) currentPlayingSong.getLength());
    lengthTotalLabel.setText(currentPlayingSong.getLengthStr());
    playButton.setOnMouseClicked(event -> mainPlayerController.pausePlaying());
    playButton.replaceButName("pause");
    this.setAlbumArtView(audioFile);
    this.timeStart = System.currentTimeMillis();
    this.timeTrack();
}
 
开发者ID:daothanhduy305,项目名称:MusicHub,代码行数:24,代码来源:SongPlayerBarController.java

示例12: setAlbumArtView

import org.jaudiotagger.audio.AudioFile; //导入依赖的package包/类
/**
 * Function name:   setAlbumArtView
 * Usage:   this function is called when a song is played, to set up the corresponding album art.
 * The loading job would be done in background instead.
 *
 * @param audioFile the song file of the playing song (since the song data doesn't contain the audio file).
 */
private void setAlbumArtView(AudioFile audioFile) {
    new Thread(new Task<Void>() {
        @Override
        protected Void call() throws Exception {
            try {
                Artwork artwork = audioFile.getTag().getFirstArtwork();
                byte[] rawAlbumArt = artwork != null ? artwork.getBinaryData() : Constants.getDefaultArtworkRaw();
                Platform.runLater(() -> {
                    Image albumArtImage = new Image(
                            new ByteArrayInputStream(rawAlbumArt),
                            sizeCalculator.getPlayerBarHeight() * 1.5,
                            sizeCalculator.getPlayerBarHeight() * 1.5,
                            true, true
                    );
                    albumArtHolder.setVisible(true);
                    albumArtView.setImage(albumArtImage);
                });
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
    }).start();
}
 
开发者ID:daothanhduy305,项目名称:MusicHub,代码行数:32,代码来源:SongPlayerBarController.java

示例13: write

import org.jaudiotagger.audio.AudioFile; //导入依赖的package包/类
@Override
public void write(final AudioFile af, final Tag tag, final RandomAccessFile raf, final RandomAccessFile rafTemp) throws CannotWriteException, IOException {
    logger.info("Writing tag to file");

    WavSaveOptions wso = TagOptionSingleton.getInstance().getWavSaveOptions();
    final WavTag existingTag = getExistingMetadata(raf);

    try {
        final WavTag wavTag = (WavTag) tag;
        if (wso == WavSaveOptions.SAVE_BOTH) {
            saveBoth(wavTag, raf, existingTag);
        } else if (wso == WavSaveOptions.SAVE_ACTIVE) {
            saveActive(wavTag, raf, existingTag);
        } else if (wso == WavSaveOptions.SAVE_EXISTING_AND_ACTIVE) {
            saveActiveExisting(wavTag, raf, existingTag);
        }
        //Invalid Option, should never happen
        else {
            throw new RuntimeException("No setting for:WavSaveOptions");
        }
        rewriteRiffHeaderSize(raf);
    } finally {
        raf.close();
    }
}
 
开发者ID:Old-Geek,项目名称:Musique,代码行数:26,代码来源:WavTagWriter.java

示例14: 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

示例15: commitAudio

import org.jaudiotagger.audio.AudioFile; //导入依赖的package包/类
private void commitAudio(Context context, AudioFile f, File file) {
    try {
        f.commit();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Intent mediaScanIntent = new Intent(
                    Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
            Uri contentUri = Uri.fromFile(file);
            mediaScanIntent.setData(contentUri);
            context.sendBroadcast(mediaScanIntent);
        } else {
            context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Utils.getStoragePath(context))));
        }
    } catch (CannotWriteException e) {
        e.printStackTrace();
    }
}
 
开发者ID:AnandChowdhary,项目名称:saga-android,代码行数:17,代码来源:DownloadReceiver.java


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