org.jaudiotagger.tag.images.ArtworkFactory Java Examples

The following examples show how to use org.jaudiotagger.tag.images.ArtworkFactory. 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: 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());
}
 
Example #2
Source File: MetadataInjector.java    From Xposed-SoundCloudDownloader with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onReceive(final Context context, Intent intent) {
    XposedBridge.log("[SoundCloud Downloader] Entering album art downloader...");
    context.unregisterReceiver(this);

    XposedBridge.log("[SoundCloud Downloader] Unregistered receiver, starting Picasso...");
    Picasso.with(XposedMod.currentActivity).setLoggingEnabled(true); // enable logging to see why picasso fails to load
    Picasso.with(XposedMod.currentActivity).load(downloadPayload.getImageUrl()).into(new Target() {
        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
            try {
                File downloadedFile = new File(downloadPayload.getSaveDirectory(), downloadPayload.getFileName());
                if (!downloadedFile.exists()) {
                    XposedBridge.log("[SoundCloud Downloader] downloaded file does not exist, exiting...");
                    return;
                }

                TagOptionSingleton.getInstance().setAndroid(true);
                AudioFile audioFile = AudioFileIO.read(downloadedFile);
                Tag tag = audioFile.getTagOrCreateAndSetDefault();
                tag.setField(FieldKey.ARTIST,downloadPayload.getArtistName());
                tag.setField(FieldKey.GENRE, downloadPayload.getGenre());
                tag.setField(FieldKey.TITLE, downloadPayload.getTitle());
                tag.setField(FieldKey.ALBUM, downloadPayload.getTitle());

                ByteArrayOutputStream imgStream = new ByteArrayOutputStream();
                bitmap.compress(Bitmap.CompressFormat.JPEG, 90, imgStream);
                File artworkFile = File.createTempFile(downloadPayload.getTitle(), ".jpg");
                FileOutputStream artworkFileStream = new FileOutputStream(artworkFile);
                artworkFileStream.write(imgStream.toByteArray());
                artworkFileStream.close();
                artworkFile.deleteOnExit();
                imgStream.close();

                Artwork artwork = ArtworkFactory.createArtworkFromFile(artworkFile);
                artwork.setPictureType(3);
                tag.deleteArtworkField();
                tag.addField(artwork);
                tag.setField(artwork);

                audioFile.setTag(tag);
                AudioFileIO.write(audioFile);

                XposedBridge.log("[SoundCloud Downloader] Finished writing metadata...");

                XposedMod.currentActivity.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(audioFile.getFile())));

                XposedBridge.log("[SoundCloud Downloader] Broadcasting update to media scanner...");

            } catch (Exception e) {
                XposedBridge.log("[SoundCloud Downloader] Metadata error: " + e.getMessage());
            }
        }

        @Override
        public void onBitmapFailed(Drawable errorDrawable) {
            XposedBridge.log("[SoundCloud Downloader] Album art fetch failed!");
        }

        @Override
        public void onPrepareLoad(Drawable placeHolderDrawable) {
            XposedBridge.log("[SoundCloud Downloader] Preparing to load picasso...");
        }
    });
}