本文整理匯總了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;
}
示例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();
}
}
示例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;
}
示例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
}
}
示例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
}
}
示例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
}
}
示例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
}
}
示例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);
}
}
示例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;
}
}