Java Code Examples for org.jaudiotagger.audio.AudioFile#getTagOrCreateAndSetDefault()
The following examples show how to use
org.jaudiotagger.audio.AudioFile#getTagOrCreateAndSetDefault() .
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: AlbumsArtDownloadService.java From Rey-MusicPlayer with Apache License 2.0 | 5 votes |
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 2
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 3
Source File: Id3TagEditorActivity.java From Rey-MusicPlayer with Apache License 2.0 | 4 votes |
private void fetchDetails() { File file = new File(SONG_PATH); try { AudioFile audioFile = AudioFileIO.read(file); Tag tag = audioFile.getTagOrCreateAndSetDefault(); title = tag.getFirst(FieldKey.TITLE); mTitleEditText.setText(title); mTitleEditText.setSelection(title.length()); artist = tag.getFirst(FieldKey.ARTIST); mArtistEditText.setText(artist); mArtistEditText.setSelection(artist.length()); album = tag.getFirst(FieldKey.ALBUM); mAlbumEditText.setText(album); mAlbumEditText.setSelection(album.length()); albumArtist = tag.getFirst(FieldKey.ALBUM_ARTIST); mAlbumArtistEditText.setText(albumArtist); mAlbumArtistEditText.setSelection(albumArtist.length()); genre = tag.getFirst(FieldKey.GENRE); mGenreEditText.setText(genre); mGenreEditText.setSelection(genre.length()); producer = tag.getFirst(FieldKey.PRODUCER); mProducerEditText.setText(producer); mProducerEditText.setSelection(mProducerEditText.length()); year = tag.getFirst(FieldKey.YEAR); mYearEditText.setText(year); mYearEditText.setSelection(year.length()); track = tag.getFirst(FieldKey.TRACK); mTrackEditText.setText(track); mTrackEditText.setSelection(track.length()); totalTrack = tag.getFirst(FieldKey.TRACK_TOTAL); mTotalTrackEditText.setText(totalTrack); mTotalTrackEditText.setSelection(totalTrack.length()); comment = tag.getFirst(FieldKey.COMMENT); mCommentsEditText.setText(comment); mCommentsEditText.setSelection(comment.length()); List<Artwork> artwork = tag.getArtworkList(); if (artwork.size() > 0) { byte[] image = artwork.get(0).getBinaryData(); Bitmap bitmap = BitmapFactory.decodeByteArray(image, 0, image.length); // mCardView.setCardBackgroundColor(Palette.from(bitmap).generate().getC(R.color.deep_purple)); mAlbumArtImage.setImageBitmap(bitmap); } } catch (CannotReadException | IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException e) { e.printStackTrace(); Toast.makeText(this, R.string.track_is_malformed, Toast.LENGTH_SHORT).show(); finish(); } }