Let me clarify the code, the post from last night was in sheer
exhaustion after having looked at it for hours on end.



Now, I have the mediascanner invoked from inside a thread to pick up
the new metadata and art that has been written to the file


                                        Thread thread = new Thread()
{
                                                @Override
                                                public void run() {
                                                        List<String>
mTrackUris = getListOfChangedFiles();

                                                                if
(mTrackUris != null && !mTrackUris.isEmpty()) {
 
final Iterator iter = mTrackUris.iterator();
 
SingleMediaScanner singleFileScanner = new
SingleMediaScanner(FetchResultDetailActivity.this,
mTrackUris.size());

                                                                        
while(iter.hasNext()) {
                                                                                
final String track = (String) iter.next();

                                                                                
if (track != null) {
                                                                                
        if (Consts.DEBUG) {
                                                                                
                Log.i(TAG, String.format("Kicking the mediascanner for
track: %s", track));
                                                                                
        }

                                                                                
        //
This clears off the entry out of the audio_meta, albums and album_art
tables. This is expected, so that is good
                                                                                
        int
rowsUpdated =
getContentResolver().delete(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
"_data = '" + track + "'", null);


                                                                                
        singleFileScanner.setFilepath(track);
                                                                                
        singleFileScanner.startScan();
                                                                                
}
                                                                        }
                                                                 }

And, this is my mediascanner class

        private class SingleMediaScanner implements
MediaScannerConnectionClient {

                private MediaScannerConnection mMediaScanner;
                private String mFilepath;
                private int mNumFilesToScan;

                public SingleMediaScanner(Context context, int numFilesToScan) {
                        mNumFilesToScan = numFilesToScan;
                    mMediaScanner = new MediaScannerConnection(context, this);
                }

                @Override
                public void onMediaScannerConnected() {
                        if (Consts.DEBUG) {
                                Log.i(TAG, String.format("Scan starting for: 
%s", mFilepath));
                        }
                    mMediaScanner.scanFile(mFilepath, null);
                }

                @Override
                public void onScanCompleted(String path, Uri uri) {
                        if (Consts.DEBUG) {
                                Log.i(TAG, String.format("Scan finished for: 
%s, uri: %s", path,
uri.toString()));
                        }
                    mMediaScanner.disconnect();
                    if (--mNumFilesToScan == 0) {
                        h.sendEmptyMessageDelayed(SAVE_ART2, 10);
                    }
                }

                public void startScan() {
                    mMediaScanner.connect();
                }

                /**
                 * @param mFilepath the mFilepath to set
                 */
                public void setFilepath(String filepath) {
                        this.mFilepath = filepath;
                }
        }


Hopefully this is a lot clearer than the earlier post, please share
any ideas you have.

After the scanner runs, if I pull the database file from the phone out
and view it, only the "audio_meta" entry seems recreated, the albums
and album_art entries are not.

Thanks !



On Mar 28, 10:58 pm, androidmediadeveloper <kamathaj...@gmail.com>
wrote:
> I have spent 2 entire days on this but havent been able to figure out,
> if someone has any ideas, please please share.
>
> I am basically trying to update the album_art on a user's music
> collection. So, when a user is playing a track, he/she can make a "get
> art" request. I fetch art from an external source and then actually
> write the art and metadata to the mp3 file. All this is working great,
> the file is accurately written with the new art.
>
> My problem however is this, since the player uses the android
> medialibrary to display metadata and art (MedisStore.Audio.Media),
> this database does not seem to reflect the new art even after a
> mediascannerconnection.scanFile. I found out that behind the content
> provider for media, there is a sqlite database which has 3 tables of
> interest, a "audio_meta" table, an "albums" table and yet another
> "album_art". This never seems to get refreshed after the new art is
> written to the file, even with a scanFile.
>
> So, thinking I have to somehow flush the media cache, I issed a
> follwing delete query into the activity, So, this code runs, and it
> cleans up the tables accurately (blows the entry from audio_meta,
> albums),
>
> Here's the delete code
>
> WinampApp.getInstance().getContentResolver().delete(MediaStore.Audio.Media. 
> EXTERNAL_CONTENT_URI,
> String.[); and this works great
>
> The code that exercises the oceancily
>
>                                         Thread thread = new Thread() {
>                                                 @Override
>                                                 public void run() {
>                                                         // set the 
> appropriate flags based on checkbox selection in the
> UI
>                                                         NError 
> replicantSaveResult = AutoTagAlbum.save(mResultMetadata,
> true, true);
>                                                         if 
> (replicantSaveResult == NError.Success) {
>                                                                 Log.i(TAG, 
> "Successfully applied the metadata to the file");
>                                                                 setResult( 
> FetcherActivity.RESULTS_APPLIED_SUCCESSFULLY );
>                                                                 if 
> (mTrackUris != null && !mTrackUris.isEmpty()) {
>                                                                         // 
> explicitly write the media library database
>                                                                         // 
> not to rely solely on the mediascanner
>                                                                         final 
> Iterator iter = mTrackUris.iterator();
>
>                                                                         
> SingleMediaScanner singleFileScanner = new
> SingleMediaScanner(FetchResultDetailActivity.this, mTrackUris.size());
>
>                                                                               
>   }
>                                                                         }
>
> Please help ! The old art is no matter what '
>
> Thanks
> ego

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to