Om Chant – Android Application

In this post, I am going to discuss about how to create ‘Om Chant’ application. Let me give you an overview of ‘Om Chant’ application:

Om Chant – Android Application

  1. The Om Chant application chants the universal mantra – ‘Om‘ continuously. Om is one of the most powerful mantra which brings inner peace to whoever listens to it.
  2. Application chants Om continuously once you press play button.
  3. One can stop playing it by pressing pause button.


Quick Links

Project Structure

Create layout XML

  • Create new android project [File >> New >> Android Project] with project name OmChant
  • Click next and select target android device version [I chose version 2.2]
  • Click next and enter package name – ‘’
  • Click finish

Code Listings

Open main.xml, now you can view the layout as either XML or in graphical view and just replace the XML with below one:

<RelativeLayout xmlns:android=""
    android:orientation="vertical" >

        android:contentDescription="@string/ImageName" />



Make sure you placed below media files in the respective folders.[Right click and save]

Om.mp3 – Under res/raw
– Under res/drawable-mdpi
– Under res/drawable-mdpi
Here is MainActivity code. Each line has comment to make it self explanatory:

package com.prgguru.example;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MusicAndroidActivity extends Activity {
	//MediaPlayer object
	static MediaPlayer mPlayer;
	//Play button object
	Button buttonPlayStop;

	public void onCreate(Bundle savedInstanceState) {
		//Find the play button view using its ID
		buttonPlayStop = (Button) findViewById(;
		//Register a method to be invoked when play button is clicked
		buttonPlayStop.setOnClickListener(new OnClickListener() {
			//When play button is clicked
			public void onClick(View v) {
				// TODO Auto-generated method stub
				try {
					//When Om chant is not playing
					if (mPlayer==null || !mPlayer.isPlaying()) {
						//Set button background image as 'Pause'
						//Create MediaPlayer object with raw resource 'om.mp3'
						mPlayer = MediaPlayer.create(getApplicationContext(),;
						//Start playing mp3
						//Set player to be looping to continuously play om.mp3
					} else {
						//When Om chant is playing
						if (mPlayer != null && mPlayer.isPlaying()) {
							//Set button background image as 'Play'
							//Stop playing om.mp3
				} catch (IllegalStateException e) {
					// TODO Auto-generated catch block
					Toast.makeText(getApplicationContext(), "Something went wrong", Toast.LENGTH_SHORT).show();
				} catch (Exception e) {
					// TODO Auto-generated catch block
					Toast.makeText(getApplicationContext(), "Something went wrong", Toast.LENGTH_SHORT).show();

	//When Activity is destroyed
	protected void onDestroy() {
		// TODO Auto-generated method stub
		if (mPlayer != null) {
			//Release media player
			mPlayer = null;




Let us test the application:
Right click on the project >> Run as >> Android application
You could see following screen:

Download Source Code

Entire project is zipped and is available for download. Unzip the downloaded project and to import the project into eclipse, launch eclipse >> File >> Import.. >> Choose downloaded project(How to import android project in eclipse). If you just want to run the application in your mobile and see the output but don’t want to hit your head with source code, download application(apk) file and install it in your mobile device.

Download Source Code Download Application(apk)

*apk in Android is the installation file simliar to exe in windows.


I hope you enjoyed the post!! 🙂
Keep us posted with your valuable comments below 🙂

Related Articles

Author: Udhay

Share This Post On
468 ad
Join now to get more access to our Android Tutorials

Join now to get more access to our Android Tutorials

Once you Join, you will receive Mail containing latest Android Tutorials once a month !!

I promise I wont spam you !!

You have Successfully Subscribed!

Pin It on Pinterest