Fundamentals
Introduction
1st Android Application

OOPS Concepts
Class
Object
Abstraction
Encapsulation

Polymorphism
Inheritance
Message Passing
Dynamic Binding

UI Controls
TextView
Button
Toggle Button
CheckBox
Radio Button
Spinner
ProgressBar
SeekBar
RadioGroup
RatingBar
Switch
EditText
AutoComplete
TextView

MultiAutoComplete
TextView

ImageView
ImageButton
Gallery
MediaPlayer
VideoView
MediaController

TimePicker
DatePicker
CalendarView
Chronometer
Analog Clock
Digital Clock

Layouts
LinearLayout
RelativeLayout
GridLayout
TableLayout
FrameLayout
Fragment

Composite
ListView
ExpandableListView
GridView
ScrollView
SearchView
Sliding Drawer
Tab Widget
WebView

Transitions
Image Switcher
StackView
TextSwitcher
ViewAnimator
View Flipper
View Switcher

Advanced
Request Focus
View
View Stub
TextureView
Gesture Overlay View

SurfaceView
NumberPicker
Zoom Button
Zoom Controls
AbsoluteLayout

Database
SharedPreference
SQLite DB
MySQL DB

Webservices
Check HttpURLConnection
Single Webservice Call
Multi Webservice Call
ListView from Webservice
SQLite from Webservice
Data from Database

Telephone Manager
IMEI
IMSI
Phone Type
Sim Type
Network Type

Content Providers
Contact Provider
BookMark Provider
Own Provider


Message & Networking
Send SMS
SMS with Reports
Group SMS

Send E-Mail
Download Binary Data


Location Based Service
Display Google Map
Events with Google Map

Android Services
Create Service
Create Longtime Service

Asynchronous Task
Repeating Services
IntentService

Activity from a Service
Bind Activity to Service


Sample Projects
HMS
CNB
Login Screen
Camera Event
Browse Option
QR Code Events
Accelerometer Sensor
EditText from Spinner

Android Audio & Video Players

  1. MediaPlayer (Audio) Creation in Android
  2. Static VideoView Creation in Android
  3. Dynamic VideoView Creation in Android

Note                     Download ADT Plugin Here.
Here I am using,
OS : Linux (Ubuntu 12.04)
Eclipse : Juno (Version 4.2.0)
Android API Level : 3 to 'n' as per need
Emulator API Level : It will be displayed in output image

A. MediaPlayer (Audio) Creation in Android


Step 1 : Select File -> New -> Project -> Android Application Project (or) Android Project. Fill the forms and click "Finish" button. If you have any doubt regarding create a new project Click Here.

Step 2 : Open res -> layout -> activity_main.xml (or) main.xml and add following code :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
 
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="30dp"
        android:text="Start" />
 
    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="120dp"
        android:text="Stop" />
 
</RelativeLayout>

Step 3 : Open res -> raw and add beep.mp3 file

Step 4 : Open src -> package -> MainActivity.java and add following code :

package balaji.mediaplayer_ex1;
 
import android.media.MediaPlayer;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
 
public class MainActivity extends Activity {
 
	MediaPlayer media;
	Button start, stop;
 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        start = (Button) findViewById(R.id.button1);
        stop = (Button) findViewById(R.id.button2);
        
        media = MediaPlayer.create(getBaseContext(), R.raw.beep);
        
        start.setOnClickListener(new View.OnClickListener() {
			
		public void onClick(View v) {
			// TODO Auto-generated method stub
			
			if(media.isPlaying()==false)
			{
				media.start();
			}
			
			play();
		}
	});
        
        stop.setOnClickListener(new View.OnClickListener() {
			
		public void onClick(View v) {
			// TODO Auto-generated method stub
			
			if(media.isPlaying()==true)
			{
				media.stop();
			}
		
			play();
		}
	});        
    }
    
    public void play()
    {
    	boolean play = media.isPlaying();
    	
    	if(play==true)
	{
		Toast.makeText(getBaseContext(), "Song is Playing", 
				Toast.LENGTH_SHORT).show();
	}
    	
    	else 
    	{
    		Toast.makeText(getBaseContext(), "Song is not Playing", 
    				Toast.LENGTH_SHORT).show();
    	}
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

Step 5 : Open AndroidManifest.xml and add following code :

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="balaji.mediaplayer_ex1"
    android:versionCode="1"
    android:versionName="1.0" >
 
    <uses-sdk
        android:minSdkVersion="3"
        android:targetSdkVersion="15" />
 
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
 
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
 
</manifest>

Step 6 : Open res ->values ->strings.xml and add following code :

<resources>
 
    <string name="app_name">MediaPlayer_Ex1</string>
    <string name="hello_world">Hello world!</string>
    <string name="menu_settings">Settings</string>
    <string name="title_activity_main">MainActivity</string>
 
</resources>

Step 7 : Our output will be like this :


Output


Output









B. Static VideoView Creation in Android


Step 1 : Select File -> New -> Project -> Android Application Project (or) Android Project. Fill the forms and click "Finish" button. If you have any doubt regarding create a new project Click Here.

Step 2 : Open res -> layout -> activity_main.xml (or) main.xml and add following code :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    
    <TextView
        android:id="@+id/textView1"
        android:textSize="18dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:text="Static VideoView" />
    
    <VideoView
        android:id="@+id/videoView1"
        android:layout_marginTop="30dp"
        android:layout_below="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
 
</RelativeLayout>

Step 3 : Open res -> raw and add ss.3gp file

Step 4 : Open src -> package -> MainActivity.java and add following code :

package balaji.videoview_static;
 
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.MediaController;
import android.widget.VideoView;
 
public class MainActivity extends Activity {
	
	VideoView video;
	MediaController controller;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        Uri UriPath = Uri.parse
        		("android.resource://balaji.videoview_static/" + R.raw.ss);  
       		
        video = (VideoView) findViewById(R.id.videoView1);
        controller = new MediaController(MainActivity.this);
        
        video.setMediaController(controller); 
        video.setVideoURI(UriPath);
        
        video.requestFocus();
        video.start();
        
        /*MediaController already has all the features to control the Video.
         * If you want to stop the video in programatically, follow below code :
         * 
         * 		if(video.isPlaying()==true)
         * 		{
         * 			video.stopPlayback();
         * 			video.clearFocus();
         * 		}       	
         * 
         */        
    }
 
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

Step 5 : Open AndroidManifest.xml and add following code :

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="balaji.videoview_static"
    android:versionCode="1"
    android:versionName="1.0" >
 
    <uses-sdk
        android:minSdkVersion="3"
        android:targetSdkVersion="15" />
 
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
 
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
 
</manifest>

Step 6 : Open res ->values ->strings.xml and add following code :

<resources>
 
    <string name="app_name">VideoView_Static</string>
    <string name="hello_world">Hello world!</string>
    <string name="menu_settings">Settings</string>
    <string name="title_activity_main">MainActivity</string>
 
</resources>

Step 7 : Our output will be like this :


Output


Output









C. Dynamic VideoView Creation in Android


Step 1 : Select File -> New -> Project -> Android Application Project (or) Android Project. Fill the forms and click "Finish" button. If you have any doubt regarding create a new project Click Here.

Step 2 : Open res -> layout -> activity_main.xml (or) main.xml and add following code :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/rl"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
 
    <TextView
        android:id="@+id/textView1"
        android:textSize="18dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:text="Dynamic VideoView" />
 
</RelativeLayout>

Step 3 : Open res -> raw and add ss.3gp file

Step 4 : Open src -> package -> MainActivity.java and add following code :

package balaji.videoview_dynamic;
 
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.MediaController;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.VideoView;
 
public class MainActivity extends Activity {
	
	RelativeLayout rl;
	VideoView video;
	MediaController Controller;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        Uri UriPath = Uri.parse
        		("android.resource://balaji.videoview_dynamic/"+R.raw.ss);
        
        rl = (RelativeLayout) findViewById(R.id.rl);
        
        video = new VideoView (MainActivity.this);
        Controller = new MediaController (MainActivity.this);
              
        
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams 
        		((int) LayoutParams.WRAP_CONTENT, (int) LayoutParams.WRAP_CONTENT);
        
        params.topMargin = 80;
        video.setLayoutParams(params);
        
        rl.addView(video);
        
        video.setMediaController(Controller);
        video.setVideoURI(UriPath);
        
        video.requestFocus();
        video.start();
        
        /*MediaController already has all the features to control the Video.
         * If you want to stop the video in programatically, follow below code :
         * 
         * 		if(video.isPlaying()==true)
         * 		{
         * 			video.stopPlayback();
         * 			video.clearFocus();
         * 		}       	
         * 
         */        
    }
 
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

Step 5 : Open AndroidManifest.xml and add following code :

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="balaji.videoview_dynamic"
    android:versionCode="1"
    android:versionName="1.0" >
 
    <uses-sdk
        android:minSdkVersion="3"
        android:targetSdkVersion="15" />
 
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
 
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
 
</manifest>

Step 6 : Open res ->values ->strings.xml and add following code :

<resources>
 
    <string name="app_name">VideoView_Dynamic</string>
    <string name="hello_world">Hello world!</string>
    <string name="menu_settings">Settings</string>
    <string name="title_activity_main">MainActivity</string>
 
</resources>

Step 7 : Our output will be like this :


Output


Output









SHARE THIS PAGE



product 2

product 3

product 4

Feedbacks : balaji.scz@gmail.com