Prev Tutorial App Coding a Share Intent with Images
This Tutorial App Coding a Media Player with Audio
Next App Tutorial Making a Video Player
Coding a Media Player With Audio
If you are just arriving at this page; and you are not familiar with with creating Android Apps, we suggest you begin with our tutorials:
Coding Android App Pages
and How To Create a Simple App in Android
From there follow along with each tutorial lesson.
AIDE and ANDROID STUDIO
We are using AIDE(a mobile coding environment using language java/xml), to create these tutorial apps on our
tablet(7" screen) that has android version 5.0.
Once we build and RUN our app; we then install the app on this same tablet; and the app is also installed on a smart phone that has android version 6.
We are using the AIDE coding editor to code our pages; and then to Create - RUN our apps. AIDE is a SDK coding environment for android devices like a tablet or smartphone.
AIDE has a free and paid version.
Once you create your apps code pages, you need to RUN the app to build your apk package; then you INSTALL it on your tablet or smartphone.
For info on using AIDE, gohere
can also create; RUN your apps using the code in these tutorials, with Android Studio. Android Studio is for desktop computers. Choose Java XML as the programming language.
Android Studio is free to install and use for your android app development. Although not as convenient as testing your app on an actual android device; you can test
your newly created app in Android Studio using its' android emulator.
Complete Example Codes are available for each of our tutorials. With these example codes you can make a functioning android app in
either AIDE or Android Studio.
First, create a java/xml android template app using AIDE, (or Android Studio). Then you can get the code for this app from the EXAMPLE CODE section on this page.
Replace the code on the pages you need to(with our tutorial code); in order to create this app.
Sometimes, new pages have to be created.
All the other coded pages in your app
can remain as they are; they don't need to be changed.
This is the App - Media Player Audio
It can play audio files.
There are two buttons; one for play and one for pause.
Where - How To Use Media Player Code Class
Media Player is a code class for adding media to your android apps. You can add audio, video, or streaming content as well. And, many features can be added to a
media player. Some common ones are buttons: Play Stop Rewind Fast-Forward Pause Seek Search.
Additional reading about Media Player code class at android developer website.
Media Player Android
Media Formats Android
For this tutorial app, we will create a media player to play an audio file.
A media player can be added to any page in your app. You just have to add the code that defines the media player class and then define and add your media file(s)
to your res/raw folder in your app project.
Typically, the code is added to the MainActivity.java file(the java class file) that allows the media player to be created(Create method) and play the media file; in this case an audio file.
And, if your adding buttons as we are for this media player; those are defined in the the layout file (main.xml) of your app. We have two buttons; one for
pause and one for play; so we will code two button elements which will hold each of the buttons code and, whatever text you want to add to the buttons.
Then, in the java file(MainActivity.java)
we will add an onclicklistener for each button. The onclicklistener is what allows the button to be clicked and the audio to be played.
We also added a text message(toast message) to each button; so that when it is clicked on a message populates on the app screen indicating that the file is Playing or is Paused.
This code is also added to the java file for the app.
Creating - Naming Your App Using AIDE
When creating your app,(from left menu) choose:
Create New Project;
New Android App(gradle, android Java/xml)
Hello World App Java/xml
if your using the original version of AIDE
You can name your app whatever you like; if your using the name as shown in our example code use;
for the App Name and,
for the package name(next line) use:
If you want to name it differently, you can, just change the app name in the strings.xml file at app_name, and change it on the left menu
in AIDE, just highlight app name, then select rename, type the new name.
You cannot change the app package name.
The Coded Pages
Code for the app - Media Player Audio
For this app you will use these coded pages:
1 layout file, main.xml,(already created, just copy paste this tutorial app code into it and save); located at res/layout/.
1 java page, MainActivity.java,(already created) where we define our layout:
setContentView(R.layout.main); and add the Create method for the Media Player.
Just copy paste the code from this tutorial, into the file MainActivity.java; to replace code that's there and save the file.
1 audio file - sample_audio.wav; You can download it from our Example Code section; then add it to your res/raw folder. You will
have to create the raw folder. Just create the folder using your Tablet File Manager or in AIDE.
Use your tablets File Manager to copy paste the audio file into the AppProjects/MediaPlayerAudio/app/src/main/res/raw/ folder.
1 strings file, strings.xml (already created) - where we define the text we put in the app. Just copy paste code from our Example Code section to replace
code that is in the file now and save the page.
1 manifest file, AndroidManifest.xml (already created) - where we define the app's name, sdk version, launcher icon, and the app's theme. And, where
we define our app's activity page; MainActivity.java. This must be defined in the Activity element in the manifest file.
This page is created automatically each time you create a new Android Java/xml app. The sdk version, launcher icon, app theme, app name attributes are all added
for you when you use an Android Template Java/xml app to create your app project.(we use the template app for our tutorials).
And, you don't need to change code on this page unless:
your adding additional activity pages
to your app;
need to change the SDK version,
need to add Internet permission,
want to change the App's Theme;
or want to add a custom launcher icon
These are some of the most common elements that are coded in the manifest file.
For this app tutorial, MediaPlayerAudio, we don't need to add any additional code to this manifest file; so we leave it as it is.
If you want to add your own audio wav or audio mp3 file to this app you can; just add it to the res/raw folder in your app project. If you are using spacing in your
audio file name you must use the underscore symbol; like sample_audio.wav.
EXAMPLE CODE - Code For This Tutorial
JUST USE YOUR MOUSE to copy the code for this tutorial
App Name is 'MediaPlayerAudio - located at AppProjects/MediaPlayerAudio in AIDE, open the AIDE app, then open App Projects, THEN select the 'MediaPlayerAudio',
app from your files hierachy(left menu); then click on any file from the app, like strings.xml Make sure at top of page, the app name 'MediaPlayerAudio' is there next to
AppProjects like so: AppProjects/MediaPlayerAudio, then you know you have the proper App.
Once a file is in the editor, you can edit, save it, then RUN your APP, Install,
and Open your app.
Make sure you SAVED EACH PAGE,(or choose automatic saving in AIDE settings) before you RUN your code. SAVE, RUN, INSTALL, OPEN, your App. Once it has been
installed on your tablet, you can open it Simply by Clicking on the Android little green App Icon,with the wording 'MediaPlayerAudio' on your tablet. It will
be with your other installed apps.
If you make further changes to this App, you need to SAVE, RUN, UPDATE, INSTALL, OPEN the app.
This free script provided by