Hey there.
Well now let's get started to implementing the application logic.
Let's start by creating on click methods for these three buttons.
Go to the text step and let's create an on click listener for the image you background team issue why
for background are not for the icon itself because it is larger and it will be more convenient for the
user to click on the entire era including the background.
Well that's great.
And on click listener for background
let's create then method.
Previous
for next background next
and for play background play method
and let's create a role folder in RES folder
and put the audio file and there
so everything is a key file is appeared.
Now let's create a variable of class media player.
Call it Media Player and initialize it in on create method.
We do this using the mass made play a method create here we write get application context to get the
application context and here we specify the audio file are DOT are all folder
and file name stuff.
Since the folder has not yet been displayed in androids to do I will rebuild the project
and next here we check in the play method.
If media player is playing that is if it is playing at the moment then we call a media play a method
pass to stop it.
And now what we need to set for that play bottom.
Another icon.
Pause
let's create an image of your class a variable here and call it play pause because the icon will change
from play to pass
and here let's bind it with all old using find Dubai D as always
boy I can image you
and here play post icon said image resource and we now set a box
and we'll have it called.
I see Paul's orange
are drivable because in the drawer both folder there is an icon and I see Paul's orange ales.
Otherwise if the meter play is not play we need to start it using media player start and again change
the icon to the opposite on the play.
In this case
this one is called I See play
and let's see what happened.
So the music is playing.
Huh.
A little bit wrong.
The opposite is changing.
Of course you unit when post display play and one play display pause.
I confused a little bit let's restart again.
And now everything is correct.
Well then we need to implement the rest of the logic.
Let's implement the behavior of Sieg bar let's make it so that as the audio recording sounded Sig bar
or rather the slider on a sigma moved along with playing the audio let's create a sig bar variable
let's see what I like.
Similar element is called I.D. the same Sig bar lets bind maximal element with variable
and then set maximum
in this case.
We need the maximum to be equal to the duration of the order of file track.
This is done as follows.
Set maximum set maximum method this code.
And here we specify media player get duration which returns the duration of the audio track.
Next we need to update the runner on our Sig bar for example every second so that it is installed in
the place where the track is not allocated to perform some tasks with a certain periodicity.
For example every second error mean at every hour.
Now that time a class is used and in the on create method let's create a new timer.
And then we call their method of this class.
We currently need scare due at fixed rate and further in this method.
We create a new task new time task
and here in this time a task there is the wrong method which runs at a certain frequency which we must
indicate here not first.
We must specify how long we want to start the timer.
In this case we want to start it immediately.
Let us specify a delay of 0 and then the frequency with which the wrong method will be executed.
There is every second for example or 1000 milliseconds means.
And here in the round method we set our Sig bar set.
Progress
and get the current position of media player media player get current position that is said the sig
bar to the current position of audio track.
Let's see what happened.
And as you see it moves.
We can also try to move it but so far it doesn't work for us.
It comes back to its place they would have time
to implement this behavior in order to move the spinner or slider.
Sorry we need to set Sig bar or sig bar changed Lisa and on the in the on progress change method here
is such a parameter US bullying from user.
And if this parameter is true this means that progress changes from user.
And in this case we can set our meet up player position to the progress which is specified in the parameters
too.
That is where I hear it from user.
Then Media Player seek to.
There is such a method in media player that will move it to the desired position and we specify the
progress variable to move it to this position that is now the media player will or will depend on sic
Bob.
And now we can move the slider to wherever we want.
Well it remains to implement the behavior of these two buttons in this application.
They will behave differently from the real music player of course because in the real application when
you click the preview previous Martin the player starts to play the previous track and when you click
next the next track is played.
What we have on here in our simple music player on the one track.
So let's implement the following behavior for these buttons.
Well let's make that.
When you click on the previous button Sig bought bar and a media player were set to the beginning and
when you click next to set to the end of the track Sigma and then meet up later.
Also when these bottles are pressed the icons should change from player to post and the track should
stop trying to implement it yourself.