-1

I have created a music player for android for my final year project. It has the basic functions like play, next, previous and also a scroll-bar to select songs from the playlist.

I wanted to use a rating bar to allow the user to set ratings for the songs but if i set the rating for 1 song and then choose another song from the playlist, the same rating is set for that song, too.

How do i make it set different ratings for different songs?

Shine
  • 3,788
  • 1
  • 36
  • 59
maestrosan11
  • 71
  • 11

2 Answers2

0

Is there a callback for when a song changes? Basically, we'd need to see some code, but you're going to want to reset the rating back to 2 stars, or whatever the default number of stars is. Then you will want to use the OnRatingBarChange to save the ratings to a database. It appears that the "MediaPlayer" class has an OnCompletionListener to tell when a track is finished.

RatingBar ratingBar = (RatingBar)view.findViewById(R.id.ratingbar);
RatingBar.OnRatingBarChangeListener barListener = 
    new RatingBar.OnRatingBarChangeListener() {
            public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromTouch) {
                // Do your database stuff here
            }

        }               

and then your stuff for the onCompletion

//mp is the reference to your media player
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {           
        public void onCompletion(MediaPlayer mp) {
            // Do what you need to do to reset the rating bar. Might need to make a public reference or create a way for this inner class to access the rating bar.

        }           
    });   
Daniel Lockard
  • 615
  • 3
  • 11
0

I think, set the rate of rating bar to your default value when there is a song change, OnClickListener on previous and next on your activity.

ratingbar.setRating(3); //For three stars

And save the rate of song with OnRatingBarChange.

DaveShaw
  • 52,123
  • 16
  • 112
  • 141
jeremw
  • 1