Welcome back.
Now, there's another little feature that I would like to add, and you already heard it, so let started
again.
And here this is the sound to get ready for the next exercise.
So this is also going to be the sound that will be played every single time once we get into the screen
that we just saw also into the screen.
So as you will see in a couple of seconds here, the sound will be played once again, and that's just
an indication for the user that the exercise is done.
All right, so there we are.
So in order to play this, we are going to use a media player.
So it's going to be a rather easy.
So we go ahead and create a new variable called player.
So I'm just going to create private var player, which is going to be a media player.
And here it's going to be a nullable again, because I need to set it somewhere and we need to import
media player.
So let's do that real quick.
Here in the sports media, that media player, then the next thing is we, of course, need to set it
somewhere.
So the best spot for that will be.
In our set up rescue, so let's go to set up rescue.
There we are.
So here we can set the player, so, for example, we can set it as media player, not create.
And here we need to pass the application context, so application context and then we need to pass a
year, I hear.
So I'm going to call this one sound you are I, which is the location where we can find the audio.
So we will need to add the audio to our resources.
And therefore I create a new folder here, new directory, and I'm going to call this one wrong.
So this one is going to contain the audio file.
So this file here, you can just go ahead and copy this one and then put it into your folder.
All right, so this is the one that I want to use, so now we can directly access it, I can just go
ahead and say our dot roll, dot press start.
So this is the file that we just dragged in.
Right.
So this press that three.
I want to add a little side note, however, so an alternative way and this is an old fashioned way,
but you will still find it when you look at it.
Oriels sometimes is to create a your eye and do it the following way so your eye don't pass.
And then you have Android, Kolon Resource, Kolon, forward slash, forward slash, then the package
name of your application forward slash and then plus our roll press start.
So this is an alternative way and then you could go ahead and use sound.
You are I in here.
All right.
So this is also going to work, but it can cause a lot of issues because this is a magic string.
You can have a typo in there and suddenly the whole thing doesn't work.
So the safer way is definitely to use this raw our raw press start.
All right.
So that's our media player here.
And then we can make sure that our player is not looping.
So there is this.
Verbal or this property called is looping, and that one, if that's true, it will constantly play
the sound over and over again.
But if we said is looping to false, then it will only played once.
And then finally we can go ahead and say player.
Thought start, so now this by itself, as you can see, we don't get an error here, so it's not complaining.
Everything seems to be fine.
But when we do something like this where we access something like the media player, so what we need
to do is in order to make sure that it's not going to crash, we will put a try and catch block around
it.
So I'm just going to say try and then here.
And the exception should be a default exception.
Nothing too fancy here.
And in the exception, I'm just going to say he thought Prince tricked the actress, but all of that
code here should go into the tribe block because this stuff could go wrong.
So starting a media player can always go wrong.
And now we have one thing that we may not forget, and that is, again, our own destroy method.
So on destroy.
You can see here we had the rest timer, Texas sized timer, and it's and now we need to do the same
thing with our player.
So if the player is active, if player not equal now then.
Just go ahead and stop the player.
And of course, there was another.
So we need to double exclamation mark here.
All right.
And now at this point, we can check our application and see if the sound is going to play.
All right, there we are.
And as you can see, I played the sound.
Let's test if it's also playing the sound once the exercise is over.
And we are so it works perfectly fine, as you can see, the South is playing and that's it.
In the next few videos, we are going to add the functionality at the bottom here, which is going to
be a adapter that we will create, which will in the end allow us to see at which exercise we could
do.
So here it is, says Jumping Jacks.
And we have our text in here, our timer.
But here on the neith, I would like to have a bunch of little circles which indicate which exercise
we are and that there are in total 12 exercises.
So that's something that we're going to do in the next video and in the following videos, because one
video is not going to be enough for that.
So see you there.