MediaPlayer Example in Android
Definition : 17) Create an application that will play a media file from the memory card.
File Name : E17Activity.java
package bsr.exa;
import bsr.exa.R;
import android.app.Activity;
import android.content.Context;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class E17Activity extends Activity {
/** @author Bipin S Rupadiya , www.bipinrupadiya.com
*
* 17) Create an application that will play a media file from the memory card.
*
* */
MediaPlayer player=null;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button start=(Button)findViewById(R.id.button1);
Button stop=(Button)findViewById(R.id.button2);
getSystemService(Context.AUDIO_SERVICE);
start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0)
{
try
{
player=null;
player=new MediaPlayer();
String audioFilePath="/sdcard/a.mid";
player.setDataSource(audioFilePath);
player.prepare();
player.start();
}
catch(Exception e)
{
Toast.makeText(E17Activity.this,""+e,Toast.LENGTH_LONG).show();
}
}
});
stop.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View arg0)
{
player.stop();
}
});
}
}
import bsr.exa.R;
import android.app.Activity;
import android.content.Context;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class E17Activity extends Activity {
/** @author Bipin S Rupadiya , www.bipinrupadiya.com
*
* 17) Create an application that will play a media file from the memory card.
*
* */
MediaPlayer player=null;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button start=(Button)findViewById(R.id.button1);
Button stop=(Button)findViewById(R.id.button2);
getSystemService(Context.AUDIO_SERVICE);
start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0)
{
try
{
player=null;
player=new MediaPlayer();
String audioFilePath="/sdcard/a.mid";
player.setDataSource(audioFilePath);
player.prepare();
player.start();
}
catch(Exception e)
{
Toast.makeText(E17Activity.this,""+e,Toast.LENGTH_LONG).show();
}
}
});
stop.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View arg0)
{
player.stop();
}
});
}
}
File Name : AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0" package="bsr.exa">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".E17Activity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0" package="bsr.exa">
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".E17Activity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Labels:
Android,
Mobile Computing
Subscribe to:
Post Comments (Atom)
Subjects
- WordPress
- Mobile Computing-4649303 Practical Solution
- Android Programming New Syllabus Theory
- PHP LAMP Question Bank
- PHP LAMP Theory
- Step by Step Android Example
- Android Practical
- Android Theory
- Android Question Bank
- Networking FON Practical
- Networking FON Theory
- OS Practical
- OS Theory
- HTML
- JavaScript
- J2EE WTAD Theory
- J2EE WTAD Question Bank
- J2EE WTAD Quick Guide
- J2EE WTAD GTU Papers
- J2EE WTAD Practical
- Python
- JAVA Theory
- JAVA Practical
- MIS
Categories
- Android (55)
- c (11)
- Configure Tomcat7 (2)
- CSS (3)
- Decryption (16)
- Difference (1)
- Encryption (16)
- Error Detection and Correction Techniques (3)
- FON (27)
- Framing Technic (2)
- install Tomcat (2)
- J2EE (29)
- JAVA (13)
- JavaScript (19)
- linux (8)
- OS (17)
- PHP (11)
- Protocol (3)
- SERVER SOCKET PROGRAMING (7)
- Servlet (13)
- shell script (33)
- unix (22)
- WTAD (34)
Total Pageviews
© BipinRupadiya.com. Powered by Blogger.
0 comments:
Post a Comment