Java Code Examples for org.jaudiotagger.tag.Tag#setField()

The following examples show how to use org.jaudiotagger.tag.Tag#setField() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Id3Writer.java    From QuickLyric with GNU General Public License v3.0 6 votes vote down vote up
@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;
}
 
Example 2
Source File: AlbumsArtDownloadService.java    From Rey-MusicPlayer with Apache License 2.0 5 votes vote down vote up
public void setAlbumArt(File file, Bitmap artworkBitmap, Song song) throws IOException, TagException, ReadOnlyFileException, CannotReadException, InvalidAudioFrameException {

        artworkBitmap = Bitmap.createScaledBitmap(artworkBitmap, 500, 500, false);

        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        artworkBitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);

        byte[] byteArray = stream.toByteArray();

        File artworkFile = new File(Environment.getExternalStorageDirectory() + "/artwork.jpg");

        if (!artworkFile.exists())
            artworkFile.createNewFile();

        FileOutputStream out = new FileOutputStream(artworkFile);
        artworkBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);

        Artwork artwork = Artwork.createArtworkFromFile(artworkFile);

        artwork.setBinaryData(byteArray);
        AudioFile audioFile = AudioFileIO.read(file);
        Tag tag = audioFile.getTagOrCreateAndSetDefault();


        if (tag.getFirstArtwork() != null) {
            tag.deleteArtworkField();
            tag.setField(artwork);
        } else {
            tag.addField(artwork);
        }

        Uri uri = MusicUtils.getAlbumArtUri(song._albumId);
        DiskCacheUtils.removeFromCache(uri.toString(), ImageLoader.getInstance().getDiskCache());
        String path = FileUtils.getRealPathFromURI(uri);
        new File(path).delete();
        artworkFile.delete();
    }
 
Example 3
Source File: MediaStoreUtil.java    From APlayer with GNU General Public License v3.0 5 votes vote down vote up
@WorkerThread
public static void saveArtwork(Context context, int albumId, File artFile)
    throws TagException, ReadOnlyFileException, CannotReadException, InvalidAudioFrameException, IOException, CannotWriteException {
  Song song = MediaStoreUtil.getSongByAlbumId(albumId);
  if (song == null) {
    return;
  }
  AudioFile audioFile = AudioFileIO.read(new File(song.getUrl()));
  Tag tag = audioFile.getTagOrCreateAndSetDefault();
  Artwork artwork = ArtworkFactory.createArtworkFromFile(artFile);
  tag.deleteArtworkField();
  tag.setField(artwork);
  audioFile.commit();
  insertAlbumArt(context, albumId, artFile.getAbsolutePath());
}