1
00:00:00,180 --> 00:00:00,750
Welcome back.

2
00:00:01,120 --> 00:00:06,030
Now, there's another little feature that I would like to add, and you already heard it, so let started

3
00:00:06,030 --> 00:00:06,390
again.

4
00:00:07,350 --> 00:00:10,930
And here this is the sound to get ready for the next exercise.

5
00:00:10,950 --> 00:00:19,090
So this is also going to be the sound that will be played every single time once we get into the screen

6
00:00:19,090 --> 00:00:21,570
that we just saw also into the screen.

7
00:00:23,050 --> 00:00:29,020
So as you will see in a couple of seconds here, the sound will be played once again, and that's just

8
00:00:29,020 --> 00:00:32,470
an indication for the user that the exercise is done.

9
00:00:35,010 --> 00:00:35,980
All right, so there we are.

10
00:00:36,210 --> 00:00:39,200
So in order to play this, we are going to use a media player.

11
00:00:39,240 --> 00:00:41,070
So it's going to be a rather easy.

12
00:00:41,760 --> 00:00:45,740
So we go ahead and create a new variable called player.

13
00:00:46,020 --> 00:00:54,450
So I'm just going to create private var player, which is going to be a media player.

14
00:00:55,140 --> 00:01:01,380
And here it's going to be a nullable again, because I need to set it somewhere and we need to import

15
00:01:01,380 --> 00:01:02,210
media player.

16
00:01:02,640 --> 00:01:04,080
So let's do that real quick.

17
00:01:05,330 --> 00:01:12,290
Here in the sports media, that media player, then the next thing is we, of course, need to set it

18
00:01:12,290 --> 00:01:12,830
somewhere.

19
00:01:12,830 --> 00:01:15,620
So the best spot for that will be.

20
00:01:16,630 --> 00:01:22,360
In our set up rescue, so let's go to set up rescue.

21
00:01:25,190 --> 00:01:25,820
There we are.

22
00:01:26,240 --> 00:01:33,560
So here we can set the player, so, for example, we can set it as media player, not create.

23
00:01:35,020 --> 00:01:44,080
And here we need to pass the application context, so application context and then we need to pass a

24
00:01:44,080 --> 00:01:44,980
year, I hear.

25
00:01:45,010 --> 00:01:51,910
So I'm going to call this one sound you are I, which is the location where we can find the audio.

26
00:01:52,090 --> 00:01:55,120
So we will need to add the audio to our resources.

27
00:01:55,120 --> 00:01:59,780
And therefore I create a new folder here, new directory, and I'm going to call this one wrong.

28
00:02:00,190 --> 00:02:04,030
So this one is going to contain the audio file.

29
00:02:04,960 --> 00:02:12,340
So this file here, you can just go ahead and copy this one and then put it into your folder.

30
00:02:15,010 --> 00:02:21,370
All right, so this is the one that I want to use, so now we can directly access it, I can just go

31
00:02:21,370 --> 00:02:25,840
ahead and say our dot roll, dot press start.

32
00:02:26,530 --> 00:02:29,620
So this is the file that we just dragged in.

33
00:02:29,620 --> 00:02:29,860
Right.

34
00:02:29,890 --> 00:02:31,630
So this press that three.

35
00:02:32,230 --> 00:02:38,170
I want to add a little side note, however, so an alternative way and this is an old fashioned way,

36
00:02:38,170 --> 00:02:40,720
but you will still find it when you look at it.

37
00:02:40,720 --> 00:02:47,860
Oriels sometimes is to create a your eye and do it the following way so your eye don't pass.

38
00:02:47,860 --> 00:02:56,200
And then you have Android, Kolon Resource, Kolon, forward slash, forward slash, then the package

39
00:02:56,200 --> 00:03:02,410
name of your application forward slash and then plus our roll press start.

40
00:03:02,440 --> 00:03:06,810
So this is an alternative way and then you could go ahead and use sound.

41
00:03:06,820 --> 00:03:08,800
You are I in here.

42
00:03:09,040 --> 00:03:09,390
All right.

43
00:03:09,400 --> 00:03:14,950
So this is also going to work, but it can cause a lot of issues because this is a magic string.

44
00:03:15,160 --> 00:03:18,270
You can have a typo in there and suddenly the whole thing doesn't work.

45
00:03:18,280 --> 00:03:23,950
So the safer way is definitely to use this raw our raw press start.

46
00:03:24,730 --> 00:03:25,060
All right.

47
00:03:25,060 --> 00:03:26,940
So that's our media player here.

48
00:03:27,190 --> 00:03:31,270
And then we can make sure that our player is not looping.

49
00:03:31,300 --> 00:03:32,710
So there is this.

50
00:03:33,660 --> 00:03:40,380
Verbal or this property called is looping, and that one, if that's true, it will constantly play

51
00:03:40,380 --> 00:03:42,000
the sound over and over again.

52
00:03:42,270 --> 00:03:45,360
But if we said is looping to false, then it will only played once.

53
00:03:46,260 --> 00:03:49,200
And then finally we can go ahead and say player.

54
00:03:50,280 --> 00:03:57,800
Thought start, so now this by itself, as you can see, we don't get an error here, so it's not complaining.

55
00:03:58,140 --> 00:03:59,600
Everything seems to be fine.

56
00:03:59,930 --> 00:04:06,380
But when we do something like this where we access something like the media player, so what we need

57
00:04:06,380 --> 00:04:12,800
to do is in order to make sure that it's not going to crash, we will put a try and catch block around

58
00:04:12,800 --> 00:04:12,970
it.

59
00:04:13,610 --> 00:04:16,940
So I'm just going to say try and then here.

60
00:04:16,950 --> 00:04:19,709
And the exception should be a default exception.

61
00:04:20,120 --> 00:04:21,399
Nothing too fancy here.

62
00:04:23,300 --> 00:04:29,930
And in the exception, I'm just going to say he thought Prince tricked the actress, but all of that

63
00:04:29,930 --> 00:04:35,010
code here should go into the tribe block because this stuff could go wrong.

64
00:04:35,030 --> 00:04:38,020
So starting a media player can always go wrong.

65
00:04:38,750 --> 00:04:44,690
And now we have one thing that we may not forget, and that is, again, our own destroy method.

66
00:04:45,020 --> 00:04:47,090
So on destroy.

67
00:04:47,570 --> 00:04:53,420
You can see here we had the rest timer, Texas sized timer, and it's and now we need to do the same

68
00:04:53,420 --> 00:04:54,460
thing with our player.

69
00:04:54,680 --> 00:05:00,710
So if the player is active, if player not equal now then.

70
00:05:01,930 --> 00:05:04,660
Just go ahead and stop the player.

71
00:05:06,680 --> 00:05:07,790
And of course, there was another.

72
00:05:07,940 --> 00:05:10,160
So we need to double exclamation mark here.

73
00:05:10,550 --> 00:05:10,960
All right.

74
00:05:10,970 --> 00:05:15,110
And now at this point, we can check our application and see if the sound is going to play.

75
00:05:16,980 --> 00:05:17,820
All right, there we are.

76
00:05:21,190 --> 00:05:22,900
And as you can see, I played the sound.

77
00:05:24,740 --> 00:05:29,060
Let's test if it's also playing the sound once the exercise is over.

78
00:05:34,230 --> 00:05:40,410
And we are so it works perfectly fine, as you can see, the South is playing and that's it.

79
00:05:40,410 --> 00:05:45,750
In the next few videos, we are going to add the functionality at the bottom here, which is going to

80
00:05:45,750 --> 00:05:53,290
be a adapter that we will create, which will in the end allow us to see at which exercise we could

81
00:05:53,340 --> 00:05:53,580
do.

82
00:05:54,090 --> 00:05:55,950
So here it is, says Jumping Jacks.

83
00:05:55,950 --> 00:05:59,040
And we have our text in here, our timer.

84
00:05:59,250 --> 00:06:05,460
But here on the neith, I would like to have a bunch of little circles which indicate which exercise

85
00:06:05,460 --> 00:06:08,150
we are and that there are in total 12 exercises.

86
00:06:08,490 --> 00:06:13,380
So that's something that we're going to do in the next video and in the following videos, because one

87
00:06:13,380 --> 00:06:15,390
video is not going to be enough for that.

88
00:06:15,760 --> 00:06:16,650
So see you there.

