Search in sources :

Example 11 with InvalidAudioFrameException

use of org.jaudiotagger.audio.exceptions.InvalidAudioFrameException in project JamsMusicPlayer by psaravan.

the class PlaylistPagerFlippedFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_playlist_pager_flipped, container, false);
    mContext = getActivity().getApplicationContext();
    mApp = (Common) mContext;
    ratingBar = (RatingBar) rootView.findViewById(R.id.playlist_pager_flipped_rating_bar);
    lyricsRelativeLayout = (RelativeLayout) rootView.findViewById(R.id.lyricsRelativeLayout);
    lyricsTextView = (TextView) rootView.findViewById(R.id.playlist_pager_flipped_lyrics);
    headerTextView = (TextView) rootView.findViewById(R.id.playlist_pager_flipped_title);
    noLyricsFoundText = (TextView) rootView.findViewById(R.id.no_embedded_lyrics_found_text);
    lyricsTextView.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
    lyricsTextView.setPaintFlags(lyricsTextView.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    headerTextView.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
    headerTextView.setPaintFlags(headerTextView.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    noLyricsFoundText.setTypeface(TypefaceHelper.getTypeface(mContext, "RobotoCondensed-Light"));
    noLyricsFoundText.setPaintFlags(noLyricsFoundText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    lyricsRelativeLayout.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View arg0) {
            //Fire a broadcast that notifies the PlaylistPager to update flip back to the album art.
            Intent intent = new Intent(broadcastMessage);
            intent.putExtra("MESSAGE", broadcastMessage);
            //Initialize the local broadcast manager.
            localBroadcastManager = LocalBroadcastManager.getInstance(mContext);
            localBroadcastManager.sendBroadcast(intent);
            return true;
        }
    });
    //Get the file path of the current song.
    String updatedSongTitle = "";
    String updatedSongArtist = "";
    String songFilePath = "";
    String songId = "";
    MediaMetadataRetriever mmdr = new MediaMetadataRetriever();
    tempCursor = mApp.getService().getCursor();
    tempCursor.moveToPosition(mApp.getService().getPlaybackIndecesList().get(mApp.getService().getCurrentSongIndex()));
    if (tempCursor.getColumnIndex(DBAccessHelper.SONG_FILE_PATH) == -1) {
        //Retrieve the info from the file's metadata.
        songFilePath = tempCursor.getString(tempCursor.getColumnIndex(null));
        mmdr.setDataSource(songFilePath);
        updatedSongTitle = mmdr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
        updatedSongArtist = mmdr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
    } else {
        /* Check if the cursor has the SONG_FILE_PATH column. If it does, we're dealing 
			 * with the SONGS table. If not, we're dealing with the PLAYLISTS table. We'll 
			 * retrieve data from the appropriate columns using this info. */
        if (tempCursor.getColumnIndex(DBAccessHelper.SONG_FILE_PATH) == -1) {
            //We're dealing with the Playlists table.
            songFilePath = tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.PLAYLIST_FILE_PATH));
            mmdr.setDataSource(songFilePath);
            updatedSongTitle = mmdr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
            updatedSongArtist = mmdr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
        } else {
            //We're dealing with the songs table.
            songFilePath = tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_FILE_PATH));
            updatedSongTitle = tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_TITLE));
            updatedSongArtist = tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_ARTIST));
            songId = tempCursor.getString(tempCursor.getColumnIndex(DBAccessHelper.SONG_ID));
        }
    }
    headerTextView.setText(updatedSongTitle + " - " + updatedSongArtist);
    ratingBar.setStepSize(1);
    int rating = mApp.getDBAccessHelper().getSongRating(songId);
    ratingBar.setRating(rating);
    //Get the rating value for the song.
    AudioFile audioFile = null;
    File file = null;
    try {
        audioFile = null;
        file = new File(songFilePath);
        try {
            audioFile = AudioFileIO.read(file);
        } catch (CannotReadException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (org.jaudiotagger.tag.TagException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (ReadOnlyFileException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (InvalidAudioFrameException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        final AudioFile finalizedAudioFile = audioFile;
        final String finalSongFilePath = songFilePath;
        final String finalSongId = songId;
        ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {

            @Override
            public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
                //Change the rating in the DB and the actual audio file itself.
                Log.e("DEBUG", ">>>>>RATING: " + rating);
                try {
                    Tag tag = finalizedAudioFile.getTag();
                    tag.addField(FieldKey.RATING, "" + ((int) rating));
                } catch (KeyNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (FieldDataInvalidException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (Exception e) {
                    e.printStackTrace();
                    Log.e("DEBUG", ">>>>>>>RATING FIELD NOT FOUND");
                }
                try {
                    finalizedAudioFile.commit();
                } catch (CannotWriteException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                mApp.getDBAccessHelper().setSongRating(finalSongId, (int) rating);
            }
        });
        //Check if the audio file has any embedded lyrics.
        String lyrics = null;
        try {
            Tag tag = audioFile.getTag();
            lyrics = tag.getFirst(FieldKey.LYRICS);
            if (lyrics == null || lyrics.isEmpty()) {
                lyricsTextView.setVisibility(View.GONE);
                noLyricsFoundText.setVisibility(View.VISIBLE);
                return rootView;
            }
            //Since the song has embedded lyrics, display them in the layout.
            lyricsTextView.setVisibility(View.VISIBLE);
            noLyricsFoundText.setVisibility(View.GONE);
            lyricsTextView.setText(lyrics);
        } catch (Exception e) {
            e.printStackTrace();
            lyricsTextView.setVisibility(View.GONE);
            noLyricsFoundText.setVisibility(View.VISIBLE);
            return rootView;
        }
    } catch (Exception e) {
        e.printStackTrace();
    //Can't do much here.
    }
    return rootView;
}
Also used : CannotWriteException(org.jaudiotagger.audio.exceptions.CannotWriteException) InvalidAudioFrameException(org.jaudiotagger.audio.exceptions.InvalidAudioFrameException) FieldDataInvalidException(org.jaudiotagger.tag.FieldDataInvalidException) OnLongClickListener(android.view.View.OnLongClickListener) ReadOnlyFileException(org.jaudiotagger.audio.exceptions.ReadOnlyFileException) CannotReadException(org.jaudiotagger.audio.exceptions.CannotReadException) OnRatingBarChangeListener(android.widget.RatingBar.OnRatingBarChangeListener) ViewGroup(android.view.ViewGroup) Intent(android.content.Intent) IOException(java.io.IOException) View(android.view.View) TextView(android.widget.TextView) RatingBar(android.widget.RatingBar) Paint(android.graphics.Paint) ReadOnlyFileException(org.jaudiotagger.audio.exceptions.ReadOnlyFileException) CannotReadException(org.jaudiotagger.audio.exceptions.CannotReadException) FieldDataInvalidException(org.jaudiotagger.tag.FieldDataInvalidException) CannotWriteException(org.jaudiotagger.audio.exceptions.CannotWriteException) KeyNotFoundException(org.jaudiotagger.tag.KeyNotFoundException) IOException(java.io.IOException) InvalidAudioFrameException(org.jaudiotagger.audio.exceptions.InvalidAudioFrameException) AudioFile(org.jaudiotagger.audio.AudioFile) MediaMetadataRetriever(android.media.MediaMetadataRetriever) Tag(org.jaudiotagger.tag.Tag) AudioFile(org.jaudiotagger.audio.AudioFile) File(java.io.File) KeyNotFoundException(org.jaudiotagger.tag.KeyNotFoundException)

Example 12 with InvalidAudioFrameException

use of org.jaudiotagger.audio.exceptions.InvalidAudioFrameException in project Shuttle by timusus.

the class ShuttleApplication method repairMediaStoreYearFromTags.

@NonNull
private Completable repairMediaStoreYearFromTags() {
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        return Completable.complete();
    }
    return DataManager.getInstance().getSongsObservable(value -> value.year < 1).first(Collections.emptyList()).map(songs -> Stream.of(songs).flatMap(song -> {
        if (!TextUtils.isEmpty(song.path)) {
            File file = new File(song.path);
            if (file.exists()) {
                try {
                    AudioFile audioFile = AudioFileIO.read(file);
                    Tag tag = audioFile.getTag();
                    if (tag != null) {
                        String year = tag.getFirst(FieldKey.YEAR);
                        int yearInt = StringUtils.parseInt(year);
                        if (yearInt > 0) {
                            song.year = yearInt;
                            ContentValues contentValues = new ContentValues();
                            contentValues.put(MediaStore.Audio.Media.YEAR, yearInt);
                            return Stream.of(ContentProviderOperation.newUpdate(ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, song.id)).withValues(contentValues).build());
                        }
                    }
                } catch (CannotReadException | IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException e) {
                    e.printStackTrace();
                }
            }
        }
        return Stream.empty();
    }).collect(Collectors.toCollection(ArrayList::new))).doOnSuccess(contentProviderOperations -> getContentResolver().applyBatch(MediaStore.AUTHORITY, contentProviderOperations)).flatMapCompletable(songs -> Completable.complete());
}
Also used : ContentValues(android.content.ContentValues) ContentProviderOperation(android.content.ContentProviderOperation) Genre(com.simplecity.amp_library.model.Genre) PackageManager(android.content.pm.PackageManager) CrashlyticsCore(com.crashlytics.android.core.CrashlyticsCore) Completable(io.reactivex.Completable) PlayCountTable(com.simplecity.amp_library.sql.providers.PlayCountTable) CastConfiguration(com.google.android.libraries.cast.companionlibrary.cast.CastConfiguration) AnalyticsManager(com.simplecity.amp_library.utils.AnalyticsManager) UserSelectedArtwork(com.simplecity.amp_library.model.UserSelectedArtwork) Manifest(android.Manifest) DaggerAppComponent(com.simplecity.amp_library.dagger.component.DaggerAppComponent) AudioFile(org.jaudiotagger.audio.AudioFile) MediaStore(android.provider.MediaStore) Schedulers(io.reactivex.schedulers.Schedulers) Log(android.util.Log) FirebaseAnalytics(com.google.firebase.analytics.FirebaseAnalytics) FieldKey(org.jaudiotagger.tag.FieldKey) LogUtils(com.simplecity.amp_library.utils.LogUtils) ContextCompat(android.support.v4.content.ContextCompat) VideoCastManager(com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager) Logger(java.util.logging.Logger) SettingsManager(com.simplecity.amp_library.utils.SettingsManager) PreferenceManager(android.support.v7.preference.PreferenceManager) Query(com.simplecity.amp_library.model.Query) List(java.util.List) Config(com.simplecity.amp_library.constants.Config) Application(android.app.Application) TagException(org.jaudiotagger.tag.TagException) AudioFileIO(org.jaudiotagger.audio.AudioFileIO) Fabric(io.fabric.sdk.android.Fabric) CompletableTransformer(io.reactivex.CompletableTransformer) InvalidAudioFrameException(org.jaudiotagger.audio.exceptions.InvalidAudioFrameException) ContentValues(android.content.ContentValues) Answers(com.crashlytics.android.answers.Answers) SqlUtils(com.simplecity.amp_library.sql.SqlUtils) AppModule(com.simplecity.amp_library.dagger.module.AppModule) ReadOnlyFileException(org.jaudiotagger.audio.exceptions.ReadOnlyFileException) CannotReadException(org.jaudiotagger.audio.exceptions.CannotReadException) TagOptionSingleton(org.jaudiotagger.tag.TagOptionSingleton) Stream(com.annimon.stream.Stream) Environment(android.os.Environment) RefWatcher(com.squareup.leakcanary.RefWatcher) HashMap(java.util.HashMap) NonNull(android.support.annotation.NonNull) StringUtils(com.simplecity.amp_library.utils.StringUtils) InputMethodManagerLeaks(com.simplecity.amp_library.utils.InputMethodManagerLeaks) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Observable(io.reactivex.Observable) AppComponent(com.simplecity.amp_library.dagger.component.AppComponent) SqlBriteUtils(com.simplecity.amp_library.sql.sqlbrite.SqlBriteUtils) Collectors(com.annimon.stream.Collectors) TextUtils(android.text.TextUtils) IOException(java.io.IOException) Tag(org.jaudiotagger.tag.Tag) CustomArtworkTable(com.simplecity.amp_library.sql.databases.CustomArtworkTable) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Glide(com.bumptech.glide.Glide) SharedPreferences(android.content.SharedPreferences) StrictMode(android.os.StrictMode) Crashlytics(com.crashlytics.android.Crashlytics) DataManager(com.simplecity.amp_library.utils.DataManager) LeakCanary(com.squareup.leakcanary.LeakCanary) LegacyUtils(com.simplecity.amp_library.utils.LegacyUtils) Collections(java.util.Collections) ContentUris(android.content.ContentUris) FirebaseApp(com.google.firebase.FirebaseApp) CannotReadException(org.jaudiotagger.audio.exceptions.CannotReadException) InvalidAudioFrameException(org.jaudiotagger.audio.exceptions.InvalidAudioFrameException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) AudioFile(org.jaudiotagger.audio.AudioFile) TagException(org.jaudiotagger.tag.TagException) ReadOnlyFileException(org.jaudiotagger.audio.exceptions.ReadOnlyFileException) Tag(org.jaudiotagger.tag.Tag) AudioFile(org.jaudiotagger.audio.AudioFile) File(java.io.File) NonNull(android.support.annotation.NonNull)

Example 13 with InvalidAudioFrameException

use of org.jaudiotagger.audio.exceptions.InvalidAudioFrameException in project MusicDNA by harjot-oberai.

the class MP3AudioHeader method seek.

/**
     * Returns true if the first MP3 frame can be found for the MP3 file
     *
     * This is the first byte of  music data and not the ID3 Tag Frame.     *
     *
     * @param seekFile  MP3 file to seek
     * @param startByte if there is an ID3v2tag we dont want to start reading from the start of the tag
     * @return true if the first MP3 frame can be found
     * @throws IOException on any I/O error
     */
public boolean seek(final File seekFile, long startByte) throws IOException {
    //References to Xing/VRbi Header
    ByteBuffer header;
    //This is substantially faster than updating the filechannels position
    long filePointerCount;
    final FileInputStream fis = new FileInputStream(seekFile);
    final FileChannel fc = fis.getChannel();
    //Read into Byte Buffer in Chunks
    ByteBuffer bb = ByteBuffer.allocateDirect(FILE_BUFFER_SIZE);
    //Move FileChannel to the starting position (skipping over tag if any)
    fc.position(startByte);
    //Update filePointerCount
    filePointerCount = startByte;
    //Read from here into the byte buffer , doesn'timer move location of filepointer
    fc.read(bb, startByte);
    bb.flip();
    boolean syncFound = false;
    try {
        do {
            //by increasing FILE_BUFFER_SIZE
            if (bb.remaining() <= MIN_BUFFER_REMAINING_REQUIRED) {
                bb.clear();
                fc.position(filePointerCount);
                fc.read(bb, fc.position());
                bb.flip();
                if (bb.limit() <= MIN_BUFFER_REMAINING_REQUIRED) {
                    //No mp3 exists
                    return false;
                }
            }
            //MP3File.logger.finest("fc:"+fc.position() + "bb"+bb.position());
            if (MPEGFrameHeader.isMPEGFrame(bb)) {
                try {
                    if (MP3AudioHeader.logger.isLoggable(Level.FINEST)) {
                        MP3AudioHeader.logger.finest("Found Possible header at:" + filePointerCount);
                    }
                    mp3FrameHeader = MPEGFrameHeader.parseMPEGHeader(bb);
                    syncFound = true;
                    if ((header = XingFrame.isXingFrame(bb, mp3FrameHeader)) != null) {
                        if (MP3AudioHeader.logger.isLoggable(Level.FINEST)) {
                            MP3AudioHeader.logger.finest("Found Possible XingHeader");
                        }
                        try {
                            //Parses Xing frame without modifying position of main buffer
                            mp3XingFrame = XingFrame.parseXingFrame(header);
                        } catch (InvalidAudioFrameException ex) {
                        // We Ignore because even if Xing Header is corrupted
                        //doesn'timer mean file is corrupted
                        }
                        break;
                    } else if ((header = VbriFrame.isVbriFrame(bb, mp3FrameHeader)) != null) {
                        if (MP3AudioHeader.logger.isLoggable(Level.FINEST)) {
                            MP3AudioHeader.logger.finest("Found Possible VbriHeader");
                        }
                        try {
                            //Parses Vbri frame without modifying position of main buffer
                            mp3VbriFrame = VbriFrame.parseVBRIFrame(header);
                        } catch (InvalidAudioFrameException ex) {
                        // We Ignore because even if Vbri Header is corrupted
                        //doesn'timer mean file is corrupted
                        }
                        break;
                    } else // There is a small but real chance that an unsynchronised ID3 Frame could fool the MPEG
                    // Parser into thinking it was an MPEG Header. If this happens the chances of the next bytes
                    // forming a Xing frame header are very remote. On the basis that  most files these days have
                    // Xing headers we do an additional check for when an apparent frame header has been found
                    // but is not followed by a Xing Header:We check the next header this wont impose a large
                    // overhead because wont apply to most Mpegs anyway ( Most likely to occur if audio
                    // has an  APIC frame which should have been unsynchronised but has not been) , or if the frame
                    // has been encoded with as Unicode LE because these have a BOM of 0xFF 0xFE
                    {
                        syncFound = isNextFrameValid(seekFile, filePointerCount, bb, fc);
                        if (syncFound) {
                            break;
                        }
                    }
                } catch (InvalidAudioFrameException ex) {
                // We Ignore because likely to be incorrect sync bits ,
                // will just continue in loop
                }
            }
            //TODO position() is quite an expensive operation, isn'timer there a way we can work this out without
            //interrogating the bytebuffer
            bb.position(bb.position() + 1);
            filePointerCount++;
        } while (!syncFound);
    } catch (EOFException ex) {
        MP3AudioHeader.logger.log(Level.WARNING, "Reached end of file without finding sync match", ex);
        syncFound = false;
    } catch (IOException iox) {
        MP3AudioHeader.logger.log(Level.SEVERE, "IOException occurred whilst trying to find sync", iox);
        syncFound = false;
        throw iox;
    } finally {
        if (fc != null) {
            fc.close();
        }
        if (fis != null) {
            fis.close();
        }
    }
    //Return to start of audio header
    if (MP3AudioHeader.logger.isLoggable(Level.FINEST)) {
        MP3AudioHeader.logger.finer("Return found matching mp3 header starting at" + filePointerCount);
    }
    setFileSize(seekFile.length());
    setMp3StartByte(filePointerCount);
    setTimePerFrame();
    setNumberOfFrames();
    setTrackLength();
    setBitRate();
    setEncoder();
    /*if((filePointerCount - startByte )>0)
        {
            logger.severe(seekFile.getName()+"length:"+startByte+"Difference:"+(filePointerCount - startByte));
        }
        */
    return syncFound;
}
Also used : FileChannel(java.nio.channels.FileChannel) InvalidAudioFrameException(org.jaudiotagger.audio.exceptions.InvalidAudioFrameException) EOFException(java.io.EOFException) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) FileInputStream(java.io.FileInputStream)

Example 14 with InvalidAudioFrameException

use of org.jaudiotagger.audio.exceptions.InvalidAudioFrameException in project MusicDNA by harjot-oberai.

the class AudioFileReader method read.

/*
      * Reads the given file, and return an AudioFile object containing the Tag
      * and the encoding infos present in the file. If the file has no tag, an
      * empty one is returned. If the encodinginfo is not valid , an exception is thrown.
      *
      * @param f The file to read
      * @exception CannotReadException If anything went bad during the read of this file
      */
public AudioFile read(File f) throws CannotReadException, IOException, TagException, ReadOnlyFileException, InvalidAudioFrameException {
    if (logger.isLoggable(Level.CONFIG)) {
        logger.config(ErrorMessage.GENERAL_READ.getMsg(f.getAbsolutePath()));
    }
    if (!f.canRead()) {
        throw new CannotReadException(ErrorMessage.GENERAL_READ_FAILED_FILE_TOO_SMALL.getMsg(f.getAbsolutePath()));
    }
    if (f.length() <= MINIMUM_SIZE_FOR_VALID_AUDIO_FILE) {
        throw new CannotReadException(ErrorMessage.GENERAL_READ_FAILED_FILE_TOO_SMALL.getMsg(f.getAbsolutePath()));
    }
    RandomAccessFile raf = null;
    try {
        raf = new RandomAccessFile(f, "r");
        raf.seek(0);
        GenericAudioHeader info = getEncodingInfo(raf);
        raf.seek(0);
        Tag tag = getTag(raf);
        return new AudioFile(f, info, tag);
    } catch (CannotReadException cre) {
        throw cre;
    } catch (Exception e) {
        logger.log(Level.SEVERE, ErrorMessage.GENERAL_READ.getMsg(f.getAbsolutePath()), e);
        throw new CannotReadException(f.getAbsolutePath() + ":" + e.getMessage(), e);
    } finally {
        try {
            if (raf != null) {
                raf.close();
            }
        } catch (Exception ex) {
            logger.log(Level.WARNING, ErrorMessage.GENERAL_READ_FAILED_UNABLE_TO_CLOSE_RANDOM_ACCESS_FILE.getMsg(f.getAbsolutePath()));
        }
    }
}
Also used : AudioFile(org.jaudiotagger.audio.AudioFile) RandomAccessFile(java.io.RandomAccessFile) CannotReadException(org.jaudiotagger.audio.exceptions.CannotReadException) Tag(org.jaudiotagger.tag.Tag) ReadOnlyFileException(org.jaudiotagger.audio.exceptions.ReadOnlyFileException) CannotReadException(org.jaudiotagger.audio.exceptions.CannotReadException) TagException(org.jaudiotagger.tag.TagException) InvalidAudioFrameException(org.jaudiotagger.audio.exceptions.InvalidAudioFrameException) IOException(java.io.IOException)

Example 15 with InvalidAudioFrameException

use of org.jaudiotagger.audio.exceptions.InvalidAudioFrameException in project JamsMusicPlayer by psaravan.

the class WriteToM3UPlaylist method getSongTitle.

public String getSongTitle(String songFilePath) {
    String songTitle = "Title";
    //Try to get the song title from the ID3 tag.
    File songFile = new File(songFilePath);
    AudioFile audioFile = null;
    Tag tag = null;
    try {
        audioFile = AudioFileIO.read(songFile);
    } 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 = audioFile.getTag();
    songTitle = tag.getFirst(FieldKey.TITLE);
    //If the ID3 tag doesn't give us the info we need, just use the file name.
    if (songTitle.equals("Title") || songTitle.isEmpty()) {
        int indexOfLastSlash = songTitle.lastIndexOf("/") + 1;
        int indexOfLastDot = songTitle.lastIndexOf(".");
        songTitle = songTitle.substring(indexOfLastSlash, indexOfLastDot);
    }
    return songTitle;
}
Also used : AudioFile(org.jaudiotagger.audio.AudioFile) CannotReadException(org.jaudiotagger.audio.exceptions.CannotReadException) TagException(org.jaudiotagger.tag.TagException) InvalidAudioFrameException(org.jaudiotagger.audio.exceptions.InvalidAudioFrameException) ReadOnlyFileException(org.jaudiotagger.audio.exceptions.ReadOnlyFileException) Tag(org.jaudiotagger.tag.Tag) IOException(java.io.IOException) AudioFile(org.jaudiotagger.audio.AudioFile) File(java.io.File)

Aggregations

InvalidAudioFrameException (org.jaudiotagger.audio.exceptions.InvalidAudioFrameException)22 IOException (java.io.IOException)21 CannotReadException (org.jaudiotagger.audio.exceptions.CannotReadException)21 ReadOnlyFileException (org.jaudiotagger.audio.exceptions.ReadOnlyFileException)21 TagException (org.jaudiotagger.tag.TagException)20 AudioFile (org.jaudiotagger.audio.AudioFile)17 File (java.io.File)14 Tag (org.jaudiotagger.tag.Tag)14 CannotWriteException (org.jaudiotagger.audio.exceptions.CannotWriteException)9 Cursor (android.database.Cursor)6 Paint (android.graphics.Paint)6 FieldDataInvalidException (org.jaudiotagger.tag.FieldDataInvalidException)5 KeyNotFoundException (org.jaudiotagger.tag.KeyNotFoundException)5 ContentValues (android.content.ContentValues)4 AlertDialog (android.app.AlertDialog)3 DialogInterface (android.content.DialogInterface)3 OnClickListener (android.content.DialogInterface.OnClickListener)3 CompoundButton (android.widget.CompoundButton)3 OnCheckedChangeListener (android.widget.CompoundButton.OnCheckedChangeListener)3 Query (com.simplecity.amp_library.model.Query)3