Learn how to produce animation and audio recording on Android systems
9 minute(s) read
Published on: Aug 13, 2021
Updated on: Dec 14, 2021
In this part of the tutorial, we want to give you examples of Android Studio applications and tell you what can be done by using Android Studio and writing some code. Android has many applications, including animation display, voice recording, audio management, Bluetooth, etc. Follow this article if you want to get acquainted with these Android applications.
What you will get acquainted within this article is as follows:
- Animation training in Android
- Audio recording training on Android
- Animation training in Android
Tween animation In this part of the tutorial, we teach you how to display animations on objects. Tween animation is one of the animations that have different types of parameters, parameters such as start, end, size, duration, and rotation angle. Tween animation You will receive these parameters, and according to the received parameters, the desired animation will be displayed on the desired object.
1- In this part of the tutorial, to display the animation in the object, we examine the loadAnimation () function from the AnimationUtils group that we call.
In the codes listed above, the second parameter is the name of the animation XML file.
2- In the res path, create a new folder and name its anim.
3- Then, we create an XML file inside the same folder.
4- Below is a list of methods that can be used to create and display animations in objects. Pay attention to them.
- Start () method:
This method is used to start the animation.
- SetDuration (long duration) method:
Used to set the duration of the animation display.
- GetDuration () method This method gets the duration set by the above method:
This method also takes the duration of the animation display obtained using the method listed above.
- End method:
This method is also used to end animations.
- Cancel method:
This method is also used to cancel the animation that was displayed.
5- To display animation in objects, we need to call start animation ().
Zoom in animation 6- To put the Zoom in animation in the desired object and display it, we must create an XML file in the res path inside the anim folder and put the code inserted below inside it.
In the code above, the fromXScale and fromYScale parameters are used to specify the start point, and the toXScale and toYScale parameters are used to identify the end point.
Duration is also used to determine the duration of the animation, and the values and data located in pivotX and pivotY specify the center where the animation is located.
Below are different animations from which you can choose the animation you want.
Below is an example where you must do all the steps mentioned carefully to finally see the result.
1- We will use the Eclipse IDE to create an Android application and name it as animation under the com.example.animation package. Be sure to use the latest versions of Target SDK and Compile With when creating Android applications using this.
2- src / MainActivity.java also changes to add animation codes.
3- You need to change the XML layout file to res/layout / activity_main.xml.
4- In the res path, create a new folder called anim.
5- Right-click on the new folder you created, select new, and click Android XML.
6- The files myanimation.xml, clockwise.xml, fade.xml should be added to the XML code after creating them.
7- You need to modify the res/values / string.xml files and add string components to them.
8- Modify the res/menu / main.xml files and add the required components to them.
9- Then run the program.
10- The codes should be in the src/com.example.animation / MainActivity.java section and have been changed are as follows:
11- The codes that should be in the res/layout / activity_main.xml section and have been changed are as follows:
12- Then, the code that should be in the res / anim / myanimation.xml section is as follows:
13- The codes that should be in the res / anim / clockwise.xml section are as follows:
14- The res / anim / fade.xml section codes are as follows.
15- The codes that should be in the res/menu / main.xml section and have been changed are as follows:
16- The modified code for the res/values / string.xml section is as follows:
After entering the codes listed above, we must run the program. To do this, it is better to open one of the program files first and click the Run icon in the program's toolbar.
After this, you must select the mobile device to display its output.
After selecting your mobile device, you must select a menu.
Then you must select the Zoom in, zoom out options, after which animation will be displayed that can zoom in.
After this, you must select the clockwise option from the menu. By selecting this option, you will see that the animation it displays will rotate from the menu.
If you select the fade in / out option from the menu, the displayed animation will be blurred.
Media Recording tutorial on Android
In Android, there is a microphone inside the system that you can use to record sound and play it. You can easily record your desired sound using the built-in Android microphone and use it using any software Play audio software. There are many ways to do this, which in this part of the tutorial and in this tutorial, we want to tell you to use them, and you can also use the built-in microphone of the Android system.
The most common method that Android uses the most is to use the MediaRecorder group. Using this group, Android can play audio or video files.
17- To use the MediaRecorder group to play audio, files, and videos, we must first set up an example of it. How to set it up is as follows:
1- MediaRecorder myAudioRecorder = new MediaRecorder ().
2- After creating an example of this group by entering the above code, you must also set the source, output, formatting, and output file.
3- Setting the source, output, formatting, and output file is as follows. It should be noted that they are arranged sequentially.
4- After doing this, it is time to record the sound and then play it. Here's how to prepare for audio recording.
5- There are two ways to do this that we call them and get ready to record the sound and play it on Android. The methods are as follows:
- myAudioRecorder.prepare ().
- myAudioRecorder.start ().
In addition to the methods listed above, other methods can be used to record and play audio on Android; Other methods that can be used to record and play audio are as follows.
- setAudioSource method:
This method specifies the audio source to be recorded.
- setVideoSource method:
setVideoSource () method is also used to specify the source of the video file to be recorded.
- SetOutputFormat () method:
We use this method to specify the audio storage format.
- SetAudioEncoder () method:
This method is also used to encrypt the audio file to be recorded.
- setOutputFile () method:
We use this method to save the path of the recorded audio file.
- Stop method:
We use this method to stop the recording process.
- Release method:
This method is also used when the recorded sample of the audio file is required.
To better understand the operation process and function of the recording, we will give you an example.
You can also go through all the steps in this article step by step with us and see the result.
The contents should be in the path and file src/com.example.audiocapture / MainActivity.java are as follows.
You can also go through the path and files listed above to insert the contents listed below into those files and paths.
The contents should be in the path and files src/com.example.audiocapture / MainActivity.java are as follows:
Then you need to put the code below in the activity_main.xml file.
The contents that should be in the Strings.xml section are as follows:
Be sure to include the code and content listed below in the AndroidManifest.xml section.
6- After entering the contents and codes listed above in the mentioned files, you must connect your mobile device to the computer.
7- We run the program through Eclipse.
8- Open one of the activity files and click on the Run icon to run the program.
9- After this, you will face a window where you must select your mobile device.
10- After selecting the mobile device, you will face a window that displays the audio recording icon and has three buttons stop, play, and start.
11- To start an audio recording, you must click on the start button to finally start the audio recording process.
12- After recording the sound, you can stop the sound recording process by pressing the stop button. After the audio recording process stops, the recorded audio will be stored indoors.
In this part of the tutorial, you will get acquainted with creating animation and audio recording. If you carefully follow all the steps listed in this article, you can make and run two separate projects for animation and audio recording in the Android operating system.About our Android and iOS app development services