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

The following examples show how to use org.jaudiotagger.tag.Tag#getFirstArtwork() . 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: JaudiotaggerParser.java    From airsonic with GNU General Public License v3.0 5 votes vote down vote up
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 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: Id3Reader.java    From QuickLyric with GNU General Public License v3.0 5 votes vote down vote up
public static Bitmap getCover(Context context, String artist, String title, boolean requestPermission) {
    try {
        Tag tag = null;
        for (File file : getFiles(context, artist, title, requestPermission)) {
            AudioFile af = AudioFileIO.read(file);
            TagOptionSingleton.getInstance().setAndroid(true);
            tag = af.getTag();
            if (!tag.getArtworkList().isEmpty())
                break;
        }
        if (tag.getFirstArtwork() == null)
            return null;
        byte[] byteArray = tag.getFirstArtwork().getBinaryData();
        ByteArrayInputStream imageStream = new ByteArrayInputStream(byteArray);

        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(imageStream, null, options);

        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);

        options.inJustDecodeBounds = false;
        options.inSampleSize = options.outWidth / size.x;

        return BitmapFactory.decodeStream(imageStream, null, options);
    } catch (Exception e) {
        return null;
    }
}
 
Example 4
Source File: JaudiotaggerParser.java    From airsonic-advanced with GNU General Public License v3.0 4 votes vote down vote up
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 5
Source File: JaudiotaggerParser.java    From subsonic with GNU General Public License v3.0 4 votes vote down vote up
private Artwork getArtwork(MediaFile file) throws Exception {
    AudioFile audioFile = AudioFileIO.read(file.getFile());
    Tag tag = audioFile.getTag();
    return tag == null ? null : tag.getFirstArtwork();
}