Skip to content

Commit 18f1b01

Browse files
committed
added mp3player sample
1 parent 3c0d23e commit 18f1b01

File tree

13 files changed

+226
-0
lines changed

13 files changed

+226
-0
lines changed

android/Mp3player/.classpath

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="src" path="gen"/>
5+
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
6+
<classpathentry kind="output" path="bin"/>
7+
</classpath>

android/Mp3player/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bin
2+
gen

android/Mp3player/.project

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>Mp3player</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.jdt.core.javabuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
<buildCommand>
24+
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
25+
<arguments>
26+
</arguments>
27+
</buildCommand>
28+
</buildSpec>
29+
<natures>
30+
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
31+
<nature>org.eclipse.jdt.core.javanature</nature>
32+
</natures>
33+
</projectDescription>

android/Mp3player/AndroidManifest.xml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.hrupin.mp3player"
4+
android:versionCode="1"
5+
android:versionName="1.0">
6+
<application android:icon="@drawable/icon" android:label="@string/app_name">
7+
<activity android:name=".Mp3player"
8+
android:label="@string/app_name">
9+
<intent-filter>
10+
<action android:name="android.intent.action.MAIN" />
11+
<category android:name="android.intent.category.LAUNCHER" />
12+
</intent-filter>
13+
</activity>
14+
15+
</application>
16+
17+
18+
</manifest>

android/Mp3player/default.properties

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# This file is automatically generated by Android Tools.
2+
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3+
#
4+
# This file must be checked in Version Control Systems.
5+
#
6+
# To customize properties used by the Ant build system use,
7+
# "build.properties", and override values to adapt the script to your
8+
# project structure.
9+
10+
# Project target.
11+
target=android-8

android/Mp3player/proguard.cfg

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
-optimizationpasses 5
2+
-dontusemixedcaseclassnames
3+
-dontskipnonpubliclibraryclasses
4+
-dontpreverify
5+
-verbose
6+
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
7+
8+
-keep public class * extends android.app.Activity
9+
-keep public class * extends android.app.Application
10+
-keep public class * extends android.app.Service
11+
-keep public class * extends android.content.BroadcastReceiver
12+
-keep public class * extends android.content.ContentProvider
13+
-keep public class com.android.vending.licensing.ILicensingService
14+
15+
-keepclasseswithmembernames class * {
16+
native <methods>;
17+
}
18+
19+
-keepclasseswithmembernames class * {
20+
public <init>(android.content.Context, android.util.AttributeSet);
21+
}
22+
23+
-keepclasseswithmembernames class * {
24+
public <init>(android.content.Context, android.util.AttributeSet, int);
25+
}
26+
27+
-keepclassmembers enum * {
28+
public static **[] values();
29+
public static ** valueOf(java.lang.String);
30+
}
31+
32+
-keep class * implements android.os.Parcelable {
33+
public static final android.os.Parcelable$Creator *;
34+
}
4.05 KB
Loading
1.68 KB
Loading
2.51 KB
Loading

android/Mp3player/res/layout/main.xml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout
3+
android:id="@+id/widget31"
4+
android:layout_width="fill_parent"
5+
android:layout_height="fill_parent"
6+
xmlns:android="http://schemas.android.com/apk/res/android"
7+
>
8+
<Button
9+
android:text="@string/play_str"
10+
android:textSize="15pt"
11+
android:textStyle="bold"
12+
android:id="@+id/ButtonPlayStop"
13+
android:layout_width="fill_parent"
14+
android:layout_height="wrap_content"/>
15+
16+
<SeekBar
17+
android:id="@+id/SeekBar01"
18+
android:layout_height="wrap_content"
19+
android:layout_width="fill_parent"
20+
android:layout_below="@id/ButtonPlayStop"/>
21+
</RelativeLayout>
813 KB
Binary file not shown.
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<string name="app_name">Android mp3 player</string>
4+
<string name="play_str">PLAY</string>
5+
<string name="pause_str">PAUSE</string>
6+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package com.hrupin.mp3player;
2+
3+
import com.hrupin.mp3player.R;
4+
5+
import android.app.Activity;
6+
import android.media.MediaPlayer;
7+
import android.os.Bundle;
8+
import android.os.Handler;
9+
import android.view.MotionEvent;
10+
import android.view.View;
11+
import android.view.View.OnClickListener;
12+
import android.view.View.OnTouchListener;
13+
import android.widget.Button;
14+
import android.widget.SeekBar;
15+
16+
public class Mp3player extends Activity {
17+
18+
private Button buttonPlayStop;
19+
private MediaPlayer mediaPlayer;
20+
private SeekBar seekBar;
21+
22+
private final Handler handler = new Handler();
23+
24+
// Here i override onCreate method.
25+
//
26+
// setContentView() method set the layout that you will see then
27+
// the application will starts
28+
//
29+
// initViews() method i create to init views components.
30+
@Override
31+
public void onCreate(Bundle icicle) {
32+
super.onCreate(icicle);
33+
setContentView(R.layout.main);
34+
initViews();
35+
36+
}
37+
38+
// This method set the setOnClickListener and method for it (buttonClick())
39+
private void initViews() {
40+
buttonPlayStop = (Button) findViewById(R.id.ButtonPlayStop);
41+
buttonPlayStop.setOnClickListener(new OnClickListener() {@Override public void onClick(View v) {buttonClick();}});
42+
43+
mediaPlayer = MediaPlayer.create(this, R.raw.testsong_20_sec);
44+
45+
seekBar = (SeekBar) findViewById(R.id.SeekBar01);
46+
seekBar.setMax(mediaPlayer.getDuration());
47+
seekBar.setOnTouchListener(new OnTouchListener() {@Override public boolean onTouch(View v, MotionEvent event) {
48+
seekChange(v);
49+
return false; }
50+
});
51+
52+
}
53+
54+
public void startPlayProgressUpdater() {
55+
seekBar.setProgress(mediaPlayer.getCurrentPosition());
56+
57+
if (mediaPlayer.isPlaying()) {
58+
Runnable notification = new Runnable() {
59+
public void run() {
60+
startPlayProgressUpdater();
61+
}
62+
};
63+
handler.postDelayed(notification,1000);
64+
}else{
65+
mediaPlayer.pause();
66+
buttonPlayStop.setText(getString(R.string.play_str));
67+
seekBar.setProgress(0);
68+
}
69+
}
70+
71+
// This is event handler thumb moving event
72+
private void seekChange(View v){
73+
if(mediaPlayer.isPlaying()){
74+
SeekBar sb = (SeekBar)v;
75+
mediaPlayer.seekTo(sb.getProgress());
76+
}
77+
}
78+
79+
// This is event handler for buttonClick event
80+
private void buttonClick(){
81+
if (buttonPlayStop.getText() == getString(R.string.play_str)) {
82+
buttonPlayStop.setText(getString(R.string.pause_str));
83+
try{
84+
mediaPlayer.start();
85+
startPlayProgressUpdater();
86+
}catch (IllegalStateException e) {
87+
mediaPlayer.pause();
88+
}
89+
}else {
90+
buttonPlayStop.setText(getString(R.string.play_str));
91+
mediaPlayer.pause();
92+
}
93+
}
94+
}

0 commit comments

Comments
 (0)