Jump to content

Fastest/best method to update Poweramp with "sync" info


eric.alva

Recommended Posts

I have an app that copies tracks to a device and I would like to know the best way to update Poweramp. Currently I just copy the files and let the scan run. I'd prefer to somehow get these files into the Poweramp DB as quickly as possible so that I can update information there - namely the rating.

 

    public boolean setTrackRating(long trackID, int rating) {
        final Uri uri = PowerampAPI.ROOT_URI.buildUpon().appendEncodedPath("files").build();
        ContentValues values = new ContentValues();
        values.put("rating", rating);
        try {
            return (context.getContentResolver().update(uri, values, "_id = " + trackID, null) == 1);
        } catch (Throwable e) {
            Log.e(TAG, e.getMessage(), e);
        }
 
        return false;
    }

 

Can I insert the appropriate records using Poweramp's content provider and, if so, are there foreign key constraints I need know? Is it better to somehow send an intent to ask Poweramp to run it's scanner? If I can insert into the DB, or be notified when this occurs, I can implement a clean solution. If I can get this working I'll have sync/reverse sync working without the need for some intermediate widget for ratings.

 

As an aside, by listening for the various Poweramp intents, I'm able to record and reverse sync ratings chosen via the Poweramp UI back to the source of the tracks. BTW, getting the rating change via an intent would be much cleaner.

 

Thanks.

 

Link to comment
Share on other sites

Inserting some values into db generally won't work (and will fail when we change schema/db approaches).

 

Poweramp listens to MediaStore.Audio.Media.EXTERNAL_CONTENT_URI content provider changes, but with added delay of 5000ms (you should send change event to MediaStore to force android to notice changes to tracks). Also, ACTION_MEDIA_MOUNTED and USB_STATE intents trigger scan.

 

 

Poweramp also internally uses ACTION_SCAN_DIRS/ACTION_SCAN_TAGS with various options, like fast scan, but those are not exported at this moment.

 

So there is no any related command in PowerampAPI. If you describe a bit a use case for this - we can add it to the next Poweramp builds.

 

Thanks!

Link to comment
Share on other sites

I'm implementing a syncing application that supports 2 way "sync". The server could be iTunes or another media management application. I need to update the server with play, skip, and rating information. I gather this info from Poweramp now and can update the server. As I said, it would be nice if Poweramp included rating in a broadcast, but I can query that information during a track change.

 

What I really need is to be able to update ratings in your database when I copy a new song to the device. The cleanest way would be for me to know when it's inserted (when it's actually inserted, when a scan is complete, ???). 

 

I update the media store with a piece of code that looks like this:

MediaScannerConnection.scanFile(context.getApplicationContext(),
                                new String[]{filePath},
                                new String[]{getMimeType(filePath)},
                                new MediaScannerConnection.OnScanCompletedListener() {
                                    @Override
                                    public void onScanCompleted(String path, Uri uri) {
                                        Log.d(TAG, path + " was scanned successfully: " + uri);
                                    }
                                });

 

However, I don't see Poweramp recognize this track until it Poweramp does it's own scan. Even if I just knew when Poweramp completed it's scan, I could check all ratings to ensure they are "correct".

 

One way I briefly tested, was just to update the rating when it's played, but the Poweramp UI doesn't reflect the change. For example:

- User updates rating in iTunes

- Track is synced to device

- User plays track in Poweramp

- I see track is being played and update rating

- User still sees no rating or old rating

- User changes track in Poweramp, then returns to "new" track and then sees the new rating

 

One other thing, I haven't seen a Poweramp widget that contains rating. I assume that's because that info is not broadcast which makes it a little more difficult for the widget implementor. When I get the time I'm going to knock out a widget based on your examples that shows track rating and allows edit. I heavily rely on ratings for various playlists, so keeping them in sync is important. As of now, I have to bring up the player and can't change the rating right from a widget.

Link to comment
Share on other sites

I see. We have a planned ratings tag support which is on route already and under active development, so in couple of weeks it will be much easier to track ratings. We'll include it into PowerampAPI. I will also expose Poweramp scan intents in the next 551 build.

Thanks!

Link to comment
Share on other sites

Thank you. Any idea when these changes will be in a release version of Poweramp?

 

 

BTW, I'm also including code on the server side of my app to embed missing ratings and artwork into files before they are copied to the device. That should alleviate some common problems I've seen other people have. 

Link to comment
Share on other sites

A mea culpa, the tracks are indeed showing up in Poweramp very quickly after I invoke MediaScannerConnection.scanFile

 

I've not finished testing but I assume the same will be the case for deletes and file based play lists. I now anxiously await the ability to see this programmatically. 

 

Thank you.

Link to comment
Share on other sites

  • 2 weeks later...

Thank you!

 

I tested with your latest release. After I download the file and notify the media scanner, in a short amount of time Poweramp has notified tag scan complete and I can make further updates. Very responsive on your part.

Link to comment
Share on other sites

Thanks for the feedback. Poweramp listens to system media scanner, but Poweramp also listens to those own API intents. System media scanner intent processing is always delayed for about 5-10 seconds (depending on Poweramp state), while API intents are processed ASAP.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...