1
00:00:00,790 --> 00:00:06,730
Welcome back in this video, we're going to implement a sound or a media player that will run a little

2
00:00:06,730 --> 00:00:11,380
sound once the exercise is done, so we know OK, now we can have a pulse, so it will basically be

3
00:00:11,380 --> 00:00:14,810
the pause media player sound, so to speak, because we have a sound.

4
00:00:14,830 --> 00:00:20,740
Once the exercise starts, but we have no sound to tell the user that it's done because that's usually

5
00:00:20,740 --> 00:00:26,980
what you need when you, well, are in the flow of doing the exercise because you don't want to look

6
00:00:26,980 --> 00:00:32,470
at your phone all the time, whether it's rest time or not, you want to have a audio cue there.

7
00:00:32,740 --> 00:00:34,060
All right, so let's implement it.

8
00:00:35,330 --> 00:00:41,060
Therefore, inside of the exercise activity, because that's where I'm going to play it, I'm going

9
00:00:41,060 --> 00:00:48,740
to require a player which will be a media player object and it will be another ball.

10
00:00:49,340 --> 00:00:54,560
And therefore we need to import media player as well as in import it.

11
00:00:54,560 --> 00:01:00,710
And this will add this import right here and then we can go ahead and use it.

12
00:01:01,040 --> 00:01:06,170
So I'm going to play the sound once we are setting up the rest of you.

13
00:01:06,650 --> 00:01:07,100
OK.

14
00:01:07,160 --> 00:01:10,040
So let me also just quickly get out of this here.

15
00:01:10,370 --> 00:01:10,730
All right.

16
00:01:10,760 --> 00:01:12,470
So set up riskview.

17
00:01:12,530 --> 00:01:18,840
So here we are, setting up all of our bindings, and that's where I'm going to set up a sound.

18
00:01:18,860 --> 00:01:27,020
So here I'm going to try and set up a sound, you or I, which will use a sound that I have in my resources.

19
00:01:27,320 --> 00:01:33,610
OK, so you can use you are either pass here, which will or you're only converted.

20
00:01:33,950 --> 00:01:35,070
And then you are.

21
00:01:35,090 --> 00:01:39,950
I don't pass like so we don't need these extra brackets around it.

22
00:01:40,850 --> 00:01:42,860
You are either pass like this.

23
00:01:43,250 --> 00:01:43,550
All right.

24
00:01:43,550 --> 00:01:48,780
And now we can pass in the string of where we have the you are right.

25
00:01:48,860 --> 00:01:53,720
So where we have the audio file and unfortunately, we cannot just pass an idea here.

26
00:01:54,110 --> 00:01:58,910
We can, however, get the resource from our raw folder.

27
00:01:59,150 --> 00:02:05,060
So let's go ahead and create a roll folder which will contain things such as audio files, for example.

28
00:02:05,360 --> 00:02:11,120
So if you create a new directory and you call it raw and then inside of this raw folder, that's where

29
00:02:11,120 --> 00:02:15,930
I'm going to have this press start MP three audio file.

30
00:02:15,950 --> 00:02:18,460
OK, so it will you can check it out.

31
00:02:18,470 --> 00:02:23,730
You can also use any other audio file that you want to use for the user to you here.

32
00:02:23,750 --> 00:02:25,700
Once the situation comes up.

33
00:02:26,210 --> 00:02:27,770
So what do we need here?

34
00:02:27,800 --> 00:02:34,880
Well, let's also, by the way, add the catch blocks so that we don't get errors here, and I'm going

35
00:02:34,880 --> 00:02:36,350
to add the exception.

36
00:02:36,770 --> 00:02:39,650
And here I'm just going to print it on the stack trace.

37
00:02:40,130 --> 00:02:49,430
OK, so now with the war I pass, we need to use our Your I string, which means the folder where you

38
00:02:49,430 --> 00:02:51,980
can find that so it will be on the resource.

39
00:02:53,760 --> 00:03:00,450
Colon forward slash forward slash and then our directory here.

40
00:03:00,540 --> 00:03:10,230
So the name of this folder, OK, so in my case, it is EU law tutorial start a seven minutes.

41
00:03:11,440 --> 00:03:13,170
Work out app.

42
00:03:14,380 --> 00:03:18,370
OK, so this is going to what is that even containing?

43
00:03:18,700 --> 00:03:21,190
It's just a seven minutes workout.

44
00:03:21,370 --> 00:03:21,790
OK.

45
00:03:22,180 --> 00:03:23,410
And then slash.

46
00:03:24,390 --> 00:03:31,380
And here we can now use the resource directory instead of its under resources.

47
00:03:31,560 --> 00:03:36,330
So our dot roll dot press start.

48
00:03:36,660 --> 00:03:38,250
So that's the file.

49
00:03:38,610 --> 00:03:40,650
And this is just where it is stored.

50
00:03:40,980 --> 00:03:45,200
OK, so we need to pass in the entire string, which is quite a long string.

51
00:03:45,210 --> 00:03:49,080
So let me put that into a second line so we can read it a little better.

52
00:03:49,380 --> 00:03:55,740
So basically, we are saying, OK, parse this, you are a file and store it inside of this variable

53
00:03:55,740 --> 00:03:59,280
called sound your eye, which is just going to be a string.

54
00:04:00,280 --> 00:04:03,220
So unfortunately, jumped over, yet there it is.

55
00:04:03,970 --> 00:04:12,100
OK, so now that we have the audio file that we want to run, we can use it with our player.

56
00:04:12,280 --> 00:04:20,990
So our player will use the media player class to call the create method, which needs to have an context.

57
00:04:21,010 --> 00:04:26,940
And here we're going to use the application context as well as the location so that you are right.

58
00:04:26,950 --> 00:04:27,880
And guess what?

59
00:04:27,880 --> 00:04:32,110
This sound your eye is of tap your eye because we are parsing it.

60
00:04:32,290 --> 00:04:36,130
So we're passing the location and we're can now pass this sound to you.

61
00:04:36,130 --> 00:04:37,120
Are I to it?

62
00:04:37,870 --> 00:04:45,370
OK, so now we can use our player, which is another bow and we can set a couple of settings.

63
00:04:45,370 --> 00:04:47,830
So, for example, I don't want to loop this sample.

64
00:04:48,340 --> 00:04:50,500
That's why I'm going to set it to.

65
00:04:50,710 --> 00:04:54,940
Is looping equals false because otherwise the sampled loop and loop a loop, and we don't want that.

66
00:04:55,540 --> 00:04:59,110
And then I will use that in order to play the sound.

67
00:04:59,110 --> 00:05:01,870
So in order to play it, I'm going to use this start method.

68
00:05:02,440 --> 00:05:04,720
OK, so what is going to happen now?

69
00:05:04,990 --> 00:05:11,080
Each time that we get set up, Crestview, we are going to play that sound.

70
00:05:11,530 --> 00:05:17,590
Even though, of course, you could put this code here into the create method and it would just exist

71
00:05:17,590 --> 00:05:18,100
there.

72
00:05:18,550 --> 00:05:22,900
That would be an alternative way than you would have to create this every single time, and you would

73
00:05:22,900 --> 00:05:24,400
just have to play it in here.

74
00:05:24,640 --> 00:05:28,930
But as this is in the try block and we have this catch statement, let's just leave it there because

75
00:05:28,930 --> 00:05:30,370
even starting could cause errors.

76
00:05:30,700 --> 00:05:39,670
So let's actually try this and see if there will be a sound playing once we are going over to the rest

77
00:05:39,670 --> 00:05:39,970
of you.

78
00:05:41,780 --> 00:05:42,920
So let's run it.

79
00:05:47,990 --> 00:05:53,300
And in your case, I think you will not hear it, let me unplug my headphones.

80
00:05:56,210 --> 00:06:02,070
And there was so let me go again to let it in an OK once again, that it it it.

81
00:06:02,270 --> 00:06:02,660
OK.

82
00:06:03,200 --> 00:06:03,550
All right.

83
00:06:03,560 --> 00:06:09,050
So I'm just doing this because I have a directional microphone in it otherwise would pick up the sound.

84
00:06:09,470 --> 00:06:10,510
OK, but the sound works.

85
00:06:10,520 --> 00:06:13,670
So we have the audio now, and that is amazing.

86
00:06:13,670 --> 00:06:14,990
So we can now use it.

87
00:06:15,350 --> 00:06:17,630
And let me just check.

88
00:06:19,140 --> 00:06:20,950
My own destroy.

89
00:06:21,420 --> 00:06:28,440
Because whenever we create these kind of things, such as media players and everything that can cause

90
00:06:28,440 --> 00:06:37,380
this kind of while leakages, we need to also destroy them in the on destroying method here.

91
00:06:38,010 --> 00:06:46,830
So if it's not moral, let's also get rid of the player so we can do that by just calling the stop method.

92
00:06:47,520 --> 00:06:51,000
OK, so this will stop our player.

93
00:06:55,880 --> 00:06:56,210
All right.

94
00:06:56,450 --> 00:06:59,180
So this will just ensure that we don't have no leakages.

95
00:06:59,600 --> 00:07:02,020
But other than that, I think we're pretty much golden.

96
00:07:02,060 --> 00:07:06,710
So our application is now ready and it plays a sound.

97
00:07:06,710 --> 00:07:10,880
So now you know how to play sounds, but away with a media player, it's pretty useful as well.

98
00:07:11,300 --> 00:07:13,160
And I'd say, see you in the next video.

