Otherwise, the message related to not playing is displayed will give.ġ3- After playing, we will see that the music will be played after pressing the button, and its playing time will also be displayed in TextView.ġ4- Then, if we select the jump button, the music will be transferred to 20 seconds in every second and any situation, and from there, it will start playing.ġ5- If we select the status button, the appropriate message will be displayed in TextView after checking.ġ6- If we click the current position button, it will call the getCurrentPosition () method and display the current position of the music player in TextView.ġ7- If we press the pause and stop buttons, they will perform the related operations.
This means it can start again in 20 seconds.įor the status button, we define a condition that checks whether music is playing or not and if after checking the result, it is that the music is playing a message related to it.
#MUSICPLAYER GETCURRENTPOSITION CODE#
In the code above, a value of 20,000 is defined for the SeekTo () method, the jump method. The audioTime () method is then called inside the activity and defined after onCreate ():Īfter inserting the above code, the audio file starts by pressing a button, and then its playback time is displayed in TextView. In the code above, the audio file's duration is taken from medPlayer using GetDuration () and stored in milliseconds at timeInt. To save the audio file's duration and its related items, we define a variable of type int called timeInt. Then I set true to SetLooping () in the code above, repeating until the music stops playing. The first inputs of this method are context and the second inputs are the location of the audio file. Inside the onCreate () method, using MediaPlayer.create (), we introduced an audio file called song to medPlayer.