Hey there.
Let's now learn how to play audio in our application.
Let's create a new project.
This can be done by closing the current project or it can be done as follows.
While new and here click new project
let's call it plain I will do
press next next next and finish
well now after the project is uploaded let's put the audio file which I attached to the lecture.
This is done in the same way you need to grade the roll folder in the rest folder.
And now put the file in it will attach it to a lecture to the lecture so that you go to can use it.
If you wish.
Let's see the file this place everything is fine.
And now in order to play audio we do not need any interface element that is when we played the video.
We had to put in the video view in which the video was displayed but audio plays without display.
Therefore we just need to write a couple lines of code.
An object of class media play is created let's call it media player also.
And then the following code is written.
Media Player and the create method.
And here we specify the context.
These and then all file are not all
and not stuff.
If you have the URL folder underline in red then you will need to rebuild the project.
I have already done this so it displays character for me.
And here is context.
These these.
This is our main activity class scenes.
We don't have a binding of our meter player to our main activity.
We can indicate here also leave these or we can't specify the context of the entire application which
can be obtained using the get application context method.
Let's leave it there for a change and then we arrive.
Media Player start let's around the app
and everything is wonderful.
Music plays But we can't interact with it anyway.
We need to put in our eye in the user interface.
Some ways to play and stop.
Let's do it.
To do these let's go to activity in Maine in our layout daily.
The full text hello world.
And here we can put two buttons
or change idea of buttons lets one button the play button change also the text that appears on the button.
Play the second button pause button
and the Turks respectively pause
but say it constraints
and now let's go onto text mode and here set the on click methods for their buttons at least method
will play well it's immediately created in main activity and the second pause method respectively.
And so in the play method we need to run our media player with a common media player start respectively.
We put this comment here.
Matt Media Player is displayed a red Android Studio writes cannot resolve symbol media player because
the variable media player was created in the on create method and these variable is not visible from
another method to our media player is visible from another method.
You need to create it in the class.
Class variables are common to all.
While we create a variable inside the method we can use them all inside the method.
In this case let's move the creation of our class a variable of our variable media player to the class.
And here we just bind it all file and now as you can see in the play method this variable media play
has become visible in the post method.
We need to call media player pause method.
Everything is very simple.
Let's try to write
well the buttons are a little incorrectly displayed but nevertheless everything works fine for us.
When you click on play the one you click on false it stops and now the task implement the following
application behavior.
Leave one button on the screen reach when Lord and the application displays the text play and when you
click on the button the audio recording should be displayed and should be played and the text should
change to pause.
And then when they click the button again should stop and the text place should be displayed.