use of org.jaudiotagger.audio.exceptions.CannotReadException in project JamsMusicPlayer by psaravan.
the class AsyncDeleteAlbumArtTask method doInBackground.
@Override
protected Void doInBackground(String... params) {
if (params.length == 2) {
artist = params[0];
album = params[1];
}
//Remove the + and replace them back with spaces. Also replace any rogue apostrophes.
try {
if (album.contains("+")) {
album = album.replace("+", " ");
}
if (album.contains("'")) {
album = album.replace("'", "''");
}
if (artist.contains("+")) {
artist = artist.replace("+", " ");
}
if (artist.contains("'")) {
artist = artist.replace("'", "''");
}
} catch (Exception e) {
e.printStackTrace();
}
String selection = DBAccessHelper.SONG_ALBUM + "=" + "'" + album + "'" + " AND " + DBAccessHelper.SONG_ARTIST + "=" + "'" + artist + "'";
String[] projection = { DBAccessHelper._ID, DBAccessHelper.SONG_FILE_PATH, DBAccessHelper.SONG_ALBUM_ART_PATH };
Cursor cursor = mApp.getDBAccessHelper().getWritableDatabase().query(DBAccessHelper.MUSIC_LIBRARY_TABLE, projection, selection, null, null, null, null);
cursor.moveToFirst();
if (cursor.getCount() != 0) {
dataURIsList.add(cursor.getString(1));
albumArtPathsList.add(cursor.getString(2));
}
while (cursor.moveToNext()) {
dataURIsList.add(cursor.getString(1));
albumArtPathsList.add(cursor.getString(2));
}
for (int i = 0; i < dataURIsList.size(); i++) {
File audioFile = new File(dataURIsList.get(i));
AudioFile f = null;
try {
f = AudioFileIO.read(audioFile);
} catch (CannotReadException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TagException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ReadOnlyFileException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidAudioFrameException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Tag tag = null;
if (f != null) {
tag = f.getTag();
} else {
continue;
}
try {
tag.deleteArtworkField();
} catch (KeyNotFoundException e) {
Toast.makeText(mContext, R.string.album_doesnt_have_artwork, Toast.LENGTH_LONG).show();
}
try {
f.commit();
} catch (CannotWriteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//Check if the current song's album art is a JPEG file.
if (albumArtPathsList.get(i).startsWith("/")) {
File file = new File(albumArtPathsList.get(i));
if (file != null) {
if (file.exists()) {
file.delete();
}
}
}
//Remove the album art from the album art database.
String filePath = dataURIsList.get(i);
filePath = filePath.replace("'", "''");
String where = DBAccessHelper.SONG_FILE_PATH + "=" + "'" + filePath + "'";
ContentValues values = new ContentValues();
values.put(DBAccessHelper.SONG_ALBUM_ART_PATH, "");
mApp.getDBAccessHelper().getWritableDatabase().update(DBAccessHelper.MUSIC_LIBRARY_TABLE, values, where, null);
}
//Refresh the memory/disk cache.
mApp.getImageLoader().clearDiscCache();
mApp.getImageLoader().clearMemoryCache();
cursor.close();
cursor = null;
return null;
}
use of org.jaudiotagger.audio.exceptions.CannotReadException in project Shuttle by timusus.
the class TaggerDialog method populateViews.
void populateViews() {
if (originalSongPaths == null || originalSongPaths.isEmpty()) {
return;
}
try {
AudioFile mAudioFile = AudioFileIO.read(new File(originalSongPaths.get(0)));
Tag tag = mAudioFile.getTag();
if (tag == null) {
return;
}
title = tag.getFirst(FieldKey.TITLE);
albumName = tag.getFirst(FieldKey.ALBUM);
artistName = tag.getFirst(FieldKey.ARTIST);
try {
albumArtistName = tag.getFirst(FieldKey.ALBUM_ARTIST);
} catch (UnsupportedOperationException ignored) {
}
genre = tag.getFirst(FieldKey.GENRE);
year = tag.getFirst(FieldKey.YEAR);
track = tag.getFirst(FieldKey.TRACK);
try {
trackTotal = tag.getFirst(FieldKey.TRACK_TOTAL);
} catch (UnsupportedOperationException ignored) {
}
try {
disc = tag.getFirst(FieldKey.DISC_NO);
} catch (UnsupportedOperationException ignored) {
}
try {
discTotal = tag.getFirst(FieldKey.DISC_TOTAL);
} catch (UnsupportedOperationException ignored) {
}
try {
lyrics = tag.getFirst(FieldKey.LYRICS);
} catch (UnsupportedOperationException ignored) {
}
try {
comment = tag.getFirst(FieldKey.COMMENT);
} catch (UnsupportedOperationException ignored) {
}
} catch (IOException | InvalidAudioFrameException | TagException | ReadOnlyFileException | CannotReadException e) {
Log.e(TAG, "Failed to read tags. " + e.toString());
}
titleEditText.setText(title);
titleEditText.setSelection(titleEditText.getText().length());
titleEditText.addTextChangedListener(new CustomTextWatcher(titleEditText, textChangeListener));
albumEditText.setText(albumName);
albumEditText.setSelection(albumEditText.getText().length());
albumEditText.addTextChangedListener(new CustomTextWatcher(titleEditText, textChangeListener));
artistEditText.setText(artistName);
artistEditText.setSelection(artistEditText.getText().length());
artistEditText.addTextChangedListener(new CustomTextWatcher(artistEditText, textChangeListener));
albumArtistEditText.setText(albumArtistName);
albumArtistEditText.setSelection(albumArtistEditText.getText().length());
albumArtistEditText.addTextChangedListener(new CustomTextWatcher(albumArtistEditText, textChangeListener));
genreEditText.setText(genre);
genreEditText.setSelection(genreEditText.getText().length());
genreEditText.addTextChangedListener(new CustomTextWatcher(genreEditText, textChangeListener));
yearEditText.setText(String.valueOf(year));
yearEditText.setSelection(yearEditText.getText().length());
yearEditText.addTextChangedListener(new CustomTextWatcher(yearEditText, textChangeListener));
trackEditText.setText(String.valueOf(track));
trackEditText.setSelection(trackEditText.getText().length());
trackEditText.addTextChangedListener(new CustomTextWatcher(trackEditText, textChangeListener));
trackTotalEditText.setText(String.valueOf(trackTotal));
trackTotalEditText.setSelection(trackTotalEditText.getText().length());
trackTotalEditText.addTextChangedListener(new CustomTextWatcher(trackTotalEditText, textChangeListener));
discEditText.setText(String.valueOf(disc));
discEditText.setSelection(discEditText.getText().length());
discEditText.addTextChangedListener(new CustomTextWatcher(discEditText, textChangeListener));
discTotalEditText.setText(String.valueOf(discTotal));
discTotalEditText.setSelection(discTotalEditText.getText().length());
discTotalEditText.addTextChangedListener(new CustomTextWatcher(discTotalEditText, textChangeListener));
lyricsEditText.setText(lyrics);
lyricsEditText.setSelection(lyricsEditText.getText().length());
lyricsEditText.addTextChangedListener(new CustomTextWatcher(lyricsEditText, textChangeListener));
commentEditText.setText(comment);
commentEditText.setSelection(commentEditText.getText().length());
commentEditText.addTextChangedListener(new CustomTextWatcher(commentEditText, textChangeListener));
}
use of org.jaudiotagger.audio.exceptions.CannotReadException in project Shuttle by timusus.
the class TaggerTask method doInBackground.
@Override
protected Boolean doInBackground(Object... params) {
boolean success = false;
boolean requiresPermission = TaggerUtils.requiresPermission(paths);
for (int i = 0; i < paths.size(); i++) {
final String path = paths.get(i);
try {
File orig = new File(path);
AudioFile audioFile = AudioFileIO.read(orig);
Tag tag = audioFile.getTag();
if (tag == null) {
break;
}
TagUpdate tagUpdate = new TagUpdate(tag);
tagUpdate.softSetArtist(artistText);
tagUpdate.softSetAlbumArtist(albumArtistText);
tagUpdate.softSetGenre(genreText);
tagUpdate.softSetYear(yearText);
if (showAlbum) {
tagUpdate.softSetAlbum(albumText);
tagUpdate.softSetDiscTotal(discTotalText);
}
if (showTrack) {
tagUpdate.softSetTitle(titleText);
tagUpdate.softSetTrack(trackText);
tagUpdate.softSetTrackTotal(trackTotalText);
tagUpdate.softSetDisc(discText);
tagUpdate.softSetLyrics(lyricsText);
tagUpdate.softSetComment(commentText);
}
File temp = null;
if (tagUpdate.hasChanged()) {
if (TaggerUtils.requiresPermission(paths)) {
temp = new File(ShuttleApplication.getInstance().getFilesDir(), orig.getName());
tempFiles.add(temp);
TaggerUtils.copyFile(orig, temp);
audioFile = AudioFileIO.read(temp);
tag = audioFile.getTag();
if (tag == null) {
break;
}
}
tagUpdate.updateTag(tag);
AudioFileIO.write(audioFile);
if (requiresPermission && temp != null) {
DocumentFile documentFile = documentFiles.get(i);
if (documentFile != null) {
ParcelFileDescriptor pfd = ShuttleApplication.getInstance().getContentResolver().openFileDescriptor(documentFile.getUri(), "w");
if (pfd != null) {
FileOutputStream fileOutputStream = new FileOutputStream(pfd.getFileDescriptor());
TaggerUtils.copyFile(temp, fileOutputStream);
pfd.close();
}
if (temp.delete()) {
if (tempFiles.contains(temp)) {
tempFiles.remove(temp);
}
}
}
}
}
publishProgress(i);
success = true;
} catch (CannotWriteException | IOException | CannotReadException | InvalidAudioFrameException | TagException | ReadOnlyFileException e) {
e.printStackTrace();
} finally {
// Try to clean up our temp files
if (tempFiles != null && tempFiles.size() != 0) {
for (int j = tempFiles.size() - 1; j >= 0; j--) {
File file = tempFiles.get(j);
file.delete();
tempFiles.remove(j);
}
}
}
}
return success;
}
use of org.jaudiotagger.audio.exceptions.CannotReadException in project Shuttle by timusus.
the class LyricsPresenter method updateLyrics.
private void updateLyrics() {
addDisposable(Observable.fromCallable(() -> {
String lyrics = "";
String path = MusicUtils.getFilePath();
if (TextUtils.isEmpty(path)) {
return lyrics;
}
if (path.startsWith("content://")) {
Query query = new Query.Builder().uri(Uri.parse(path)).projection(new String[] { MediaStore.Audio.Media.DATA }).build();
Cursor cursor = SqlUtils.createQuery(ShuttleApplication.getInstance(), query);
if (cursor != null) {
try {
int colIndex = cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);
if (cursor.moveToFirst()) {
path = cursor.getString(colIndex);
}
} finally {
cursor.close();
}
}
}
File file = new File(path);
if (file.exists()) {
try {
AudioFile audioFile = AudioFileIO.read(file);
if (audioFile != null) {
Tag tag = audioFile.getTag();
if (tag != null) {
String tagLyrics = tag.getFirst(FieldKey.LYRICS);
if (tagLyrics != null && tagLyrics.length() != 0) {
lyrics = tagLyrics.replace("\r", "\n");
}
}
}
} catch (CannotReadException | IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException | UnsupportedOperationException ignored) {
}
}
return lyrics;
}).subscribe(lyrics -> {
LyricsView lyricsView = getView();
if (lyricsView != null) {
lyricsView.updateLyrics(lyrics);
lyricsView.showNoLyricsView(TextUtils.isEmpty(lyrics));
lyricsView.showQuickLyricInfoButton(!QuickLyricUtils.isQLInstalled());
}
}, error -> LogUtils.logException(TAG, "Error getting lyrics", error)));
}
Aggregations