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


Java AudioFileIO.write方法代碼示例

本文整理匯總了Java中org.jaudiotagger.audio.AudioFileIO.write方法的典型用法代碼示例。如果您正苦於以下問題:Java AudioFileIO.write方法的具體用法?Java AudioFileIO.write怎麽用?Java AudioFileIO.write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jaudiotagger.audio.AudioFileIO的用法示例。


在下文中一共展示了AudioFileIO.write方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

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

示例2: 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();
    }
}
 
開發者ID:vanilla-music,項目名稱:vanilla-music-tag-editor,代碼行數:23,代碼來源:PluginService.java

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

示例4: setTitle

import org.jaudiotagger.audio.AudioFileIO; //導入方法依賴的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

示例5: setArtist

import org.jaudiotagger.audio.AudioFileIO; //導入方法依賴的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

示例6: setAlbum

import org.jaudiotagger.audio.AudioFileIO; //導入方法依賴的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

示例7: setGenre

import org.jaudiotagger.audio.AudioFileIO; //導入方法依賴的package包/類
/**
 * Set the genre attribute of this song object and also the genre tag in the metadata
 *
 * @param genre the specified album
 */
public void setGenre(String genre) {
    try {
        //update metadata
        AudioFile file = AudioFileIO.read(m_file);
        Tag tag = file.getTag();
        tag.setField(FieldKey.GENRE, genre);
        AudioFileIO.write(file);
        //update object attr
        m_genre = genre;
    } catch (Exception e) {
        e.printStackTrace(); //for now
    }
}
 
開發者ID:ijh165,項目名稱:Gamma-Music-Manager,代碼行數:19,代碼來源:Song.java

示例8: commit

import org.jaudiotagger.audio.AudioFileIO; //導入方法依賴的package包/類
/**
 * Saves all changes done to the tags
 */
public void commit() {
	try {
		AudioFileIO.write(song);
	} catch (final CannotWriteException e) {
		Logging.log("failed committing audio data", e);
	}
}
 
開發者ID:Zahlii,項目名稱:Advanced-Youtube-Downloader,代碼行數:11,代碼來源:TagEditor.java

示例9: editSongTags

import org.jaudiotagger.audio.AudioFileIO; //導入方法依賴的package包/類
/**
 * Edit Song Tags
 *
 * @param context
 * @param song
 * @return
 */
public static boolean editSongTags(Context context, Song song) {
    File f = new File(song.getmSongPath());
    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;
            }
            String year = song.getYear();
            String title = song.getTitle();
            String album = song.getAlbum();
            String artist = song.getArtist();
            String lyrics = song.getLyrics();
            tag.deleteField(FieldKey.LYRICS);
            tag.setField(FieldKey.LYRICS, Html.fromHtml(lyrics).toString());
            ContentValues values = new ContentValues();
            if (title != null){
                tag.setField(FieldKey.TITLE, title);
                values.put(MediaStore.Audio.Media.TITLE, title);
            }
            if (artist != null){
                tag.setField(FieldKey.ARTIST, artist);
                values.put(MediaStore.Audio.Media.ARTIST, artist);
            }
            if (album != null){
                tag.setField(FieldKey.ALBUM, album);
                Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, new String[]{BaseColumns._ID,
                                MediaStore.Audio.AlbumColumns.ALBUM, MediaStore.Audio.AlbumColumns.ALBUM_KEY,
                                MediaStore.Audio.AlbumColumns.ARTIST}, MediaStore.Audio.AlbumColumns.ALBUM + " = ?",
                        new String[]{album}, MediaStore.Audio.Albums.DEFAULT_SORT_ORDER);

                if (cursor != null && cursor.moveToFirst()) {
                    long id = cursor.getLong(cursor.getColumnIndex(BaseColumns._ID));
                    values.put(MediaStore.Audio.Media.ALBUM_ID, id);
                    cursor.close();
                } else {
                    values.put(MediaStore.Audio.Media.ALBUM, album);
                }
            }
            if (song.getTrackNumber() != -1){
                tag.setField(FieldKey.TRACK, String.valueOf(song.getTrackNumber()));
                values.put(MediaStore.Audio.Media.TRACK, song.getTrackNumber());
            }
            if (year != null && year.length() > 0){
                tag.setField(FieldKey.YEAR,  "" + year);
                values.put(MediaStore.Audio.Media.YEAR, year);
            }
            if (values.size() > 0) {
                context.getContentResolver().update(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, values, android.provider.MediaStore.Audio.Media._ID + "=?", new String[]{String.valueOf(song.getId())});
            }else {
                return false;
            }
            audioFile.setTag(tag);
            AudioFileIO.write(audioFile);
        } catch (CannotReadException | CannotWriteException | InvalidAudioFrameException | TagException | IOException | ReadOnlyFileException e) {
            e.printStackTrace();
        }
        return true;
    } else {
        return false;
    }
}
 
開發者ID:RajneeshSingh007,項目名稱:MusicX-music-player,代碼行數:75,代碼來源:Helper.java


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