iammert / InteractivePlayerView

Custom android music player view.
742 stars 161 forks source link

music progress time shows random numbers #8

Open rubinnellikunnathu opened 8 years ago

rubinnellikunnathu commented 8 years ago

First of all i liked your player view very much, but when i tried to implement it, im getting some problems. In my player when i tried to to the music progress time , when the music starts ,player shows some random numbers as time. Can you pls help me to fix this : \ this is my screenshot** screenshot_2016-09-24-13-29-41

my code used is :

  ipv = (InteractivePlayerView) v.findViewById(R.id.ipv);
        mPlayer = MediaPlayer.create(getContext(), R.raw.music);//Create MediaPlayer object with MP3 file under res/raw folder
        ipv.setMax(mPlayer.getDuration());
        ipv.setOnActionClickedListener(this);

        final ImageView control = (ImageView) v.findViewById(R.id.control);
        control.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mPlayer != null && !ipv.isPlaying()) {
                    ipv.start();
                    mPlayer.start();//Start playing the music
                   final Handler handler = new Handler();
                    Runnable runnable = new Runnable() {

                        @Override
                        public void run() {
//                            while (mPlayer != null && currentPosition < total) {
                            try{
                                ipv.setProgress(mPlayer.getCurrentPosition());
                                //do your code here
                            }
                            catch (Exception e) {
                                // TODO: handle exception
                            }
                            finally{
                                //also call the same runnable to call it at regular interval
                                handler.postDelayed(this, 1000);
//                            }
                        }}
                    };
                    handler.postDelayed(runnable, 1000);
                    control.setBackgroundResource(R.drawable.pause);
                } else {
                    ipv.stop();
                    if (mPlayer != null && mPlayer.isPlaying()) {//If music is playing already
                        mPlayer.pause();//Stop playing the music
                        control.setBackgroundResource(R.drawable.play);
                    }
                }
            }
        });
rubinnellikunnathu commented 8 years ago

Hai now i figured out the my problem by changing the ipv.SetProgress code to ipv.setProgress(mPlayer.getCurrentPosition()/1000);

but now the weird number showing problem solved but now the red seekbar is not updating its view.

screenshot_2016-09-26-11-41-14

rubinnellikunnathu commented 8 years ago

Still no answers..?

DubiousCactus commented 8 years ago

You sure you didn't forget ipv.start(); right after that ?

raju249 commented 7 years ago

Any work around this issue ?