In my media player app (Android based), I want to implement a Thumbs Up/ Thumbs Down rating system. Now, since the framework provides a default android.media.Rating
class to handle different types of ratings, I was figuring out a way to implement Thumbs based rating using the Rating
class.
I have written the following methods to set either Up, Down or Unrated rating.
MediaMetadataCompat metadata; // initial metadata
public void setLiked() {
RatingCompat likedRating = RatingCompat.newThumbRating(true);
metadata = new MediaMetadataCompat
.Builder(metadata)
.putRating(MediaMetadataCompat.METADATA_KEY_USER_RATING, likedRating)
.build();
}
public void setDisliked() {
RatingCompat dislikedRating = RatingCompat.newThumbRating(false);
metadata = new MediaMetadataCompat
.Builder(metadata)
.putRating(MediaMetadataCompat.METADATA_KEY_USER_RATING, dislikedRating)
.build();
}
public void setUnrated() {
RatingCompat unratedRating = RatingCompat.newUnratedRating(RatingCompat.RATING_NONE);
metadata = new MediaMetadataCompat
.Builder(metadata)
.putRating(MediaMetadataCompat.METADATA_KEY_USER_RATING, unratedRating)
.build();
}
Although I haven't tested the methods, since the both app and the module hasn't been finished yet. Is it the right way to apply rating to a song? Also I can't find a way to retrieve the ratings back.
I've rolled through the documentation numerous times without getting much clue; and any examples available online are only based on star based rating. If someone has experience implementing Thumbs based rating in Android using Ratings class, help me out here. Thanks.
TLDR
To make this question not too specific, I'm offering a more generalized explanation so that this question will be more helpful for other people in future.
Basically, I want an explanation/example for the Rating class in context of Thumbs based rating.
Your implementation seems correct to me, you can retrieve ratings with this method: