org.jaudiotagger.tag.images.Artwork Java Examples
The following examples show how to use
org.jaudiotagger.tag.images.Artwork.
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: CoverArtController.java From airsonic-advanced with GNU General Public License v3.0 | 6 votes |
/** * Returns an input stream to the image in the given file. If the file is an audio file, * the embedded album art is returned. In addition returns the mime type */ private Pair<InputStream, String> getImageInputStreamWithType(Path file) throws IOException { InputStream is; String mimeType; if (jaudiotaggerParser.isApplicable(file)) { LOG.trace("Using Jaudio Tagger for reading artwork from {}", file); MediaFile mediaFile = mediaFileService.getMediaFile(file); try { LOG.trace("Reading artwork from file {}", mediaFile); Artwork artwork = jaudiotaggerParser.getArtwork(mediaFile); is = new ByteArrayInputStream(artwork.getBinaryData()); mimeType = artwork.getMimeType(); } catch (Exception e) { LOG.debug("Could not read artwork from file {}", mediaFile); throw new RuntimeException(e); } } else { is = new BufferedInputStream(Files.newInputStream(file)); mimeType = StringUtil.getMimeType(MoreFiles.getFileExtension(file)); } return Pair.of(is, mimeType); }
Example #2
Source File: CoverArtController.java From airsonic with GNU General Public License v3.0 | 6 votes |
/** * Returns an input stream to the image in the given file. If the file is an audio file, * the embedded album art is returned. In addition returns the mime type */ private Pair<InputStream, String> getImageInputStreamWithType(File file) throws IOException { InputStream is; String mimeType; if (jaudiotaggerParser.isApplicable(file)) { LOG.trace("Using Jaudio Tagger for reading artwork from {}", file); MediaFile mediaFile = mediaFileService.getMediaFile(file); Artwork artwork; try { LOG.trace("Reading artwork from file {}", mediaFile); artwork = jaudiotaggerParser.getArtwork(mediaFile); is = new ByteArrayInputStream(artwork.getBinaryData()); mimeType = artwork.getMimeType(); } catch (Exception e) { LOG.debug("Could not read artwork from file {}", mediaFile); throw new RuntimeException(e); } } else { is = new FileInputStream(file); mimeType = StringUtil.getMimeType(FilenameUtils.getExtension(file.getName())); } return Pair.of(is, mimeType); }
Example #3
Source File: AbsTagEditorActivity.java From Music-Player with GNU General Public License v3.0 | 5 votes |
@Nullable protected Bitmap getAlbumArt() { try { Artwork artworkTag = getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirstArtwork(); if (artworkTag != null) { byte[] artworkBinaryData = artworkTag.getBinaryData(); return BitmapFactory.decodeByteArray(artworkBinaryData, 0, artworkBinaryData.length); } return null; } catch (Exception ignored) { return null; } }
Example #4
Source File: AbsTagEditorActivity.java From Orin with GNU General Public License v3.0 | 5 votes |
@Nullable protected Bitmap getAlbumArt() { try { Artwork artworkTag = getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirstArtwork(); if (artworkTag != null) { byte[] artworkBinaryData = artworkTag.getBinaryData(); return BitmapFactory.decodeByteArray(artworkBinaryData, 0, artworkBinaryData.length); } return null; } catch (Exception ignored) { return null; } }
Example #5
Source File: JaudiotaggerParser.java From airsonic with GNU General Public License v3.0 | 5 votes |
public static Artwork getArtwork(MediaFile file) { AudioFile audioFile; try { audioFile = AudioFileIO.read(file.getFile()); } catch (Throwable e) { LOG.warn("Failed to find cover art tag in " + file, e); return null; } Tag tag = audioFile.getTag(); return tag == null ? null : tag.getFirstArtwork(); }
Example #6
Source File: AbsTagEditorActivity.java From RetroMusicPlayer with GNU General Public License v3.0 | 5 votes |
@Nullable protected Bitmap getAlbumArt() { try { Artwork artworkTag = getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirstArtwork(); if (artworkTag != null) { byte[] artworkBinaryData = artworkTag.getBinaryData(); return BitmapFactory.decodeByteArray(artworkBinaryData, 0, artworkBinaryData.length); } return null; } catch (Exception ignored) { return null; } }
Example #7
Source File: AbsTagEditorActivity.java From VinylMusicPlayer with GNU General Public License v3.0 | 5 votes |
@Nullable protected Bitmap getAlbumArt() { try { Artwork artworkTag = getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirstArtwork(); if (artworkTag != null) { byte[] artworkBinaryData = artworkTag.getBinaryData(); return BitmapFactory.decodeByteArray(artworkBinaryData, 0, artworkBinaryData.length); } return null; } catch (Exception ignored) { return null; } }
Example #8
Source File: MediaStoreUtil.java From APlayer with GNU General Public License v3.0 | 5 votes |
@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 #9
Source File: AbsTagEditorActivity.java From Phonograph with GNU General Public License v3.0 | 5 votes |
@Nullable protected Bitmap getAlbumArt() { try { Artwork artworkTag = getAudioFile(songPaths.get(0)).getTagOrCreateAndSetDefault().getFirstArtwork(); if (artworkTag != null) { byte[] artworkBinaryData = artworkTag.getBinaryData(); return BitmapFactory.decodeByteArray(artworkBinaryData, 0, artworkBinaryData.length); } return null; } catch (Exception ignored) { return null; } }
Example #10
Source File: JaudiotaggerParser.java From airsonic-advanced with GNU General Public License v3.0 | 4 votes |
public Artwork getArtwork(MediaFile file) throws Exception { AudioFile audioFile = AudioFileIO.read(file.getFile().toFile()); Tag tag = audioFile.getTag(); return tag == null ? null : tag.getFirstArtwork(); }
Example #11
Source File: MetadataInjector.java From Xposed-SoundCloudDownloader with GNU General Public License v3.0 | 4 votes |
@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..."); } }); }