Skip to content

Commit 71c406f

Browse files
committed
Merge pull request ihrupin#1 from tolbxela/Android-Streaming-Mp3-Player
Thanks
2 parents bf05234 + 70c9efa commit 71c406f

File tree

15 files changed

+182
-400
lines changed

15 files changed

+182
-400
lines changed

android/Mp3_Player/.classpath

-7
This file was deleted.

android/Streaming_Audio_Player/AndroidManifest.xml

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.hrupin.edu.androidEx2" android:versionCode="1" android:versionName="0.0.1-SNAPSHOT">
3-
<uses-permission android:name="android.permission.INTERNET" />
4-
<uses-permission android:name="android.permission.CAMERA" />
5-
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.hrupin.streamingmedia" android:versionCode="1" android:versionName="0.0.1-SNAPSHOT">
3+
<uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.VIBRATE" />
64
<application android:icon="@drawable/icon" android:label="@string/app_name">
7-
<uses-library android:name="com.google.android.maps" android:required="true"></uses-library>
8-
<activity android:name=".HelloAndroidActivity">
5+
<activity android:name="StreamingMp3Player" android:label="@string/app_name">
96
<intent-filter>
10-
<action android:name="android.intent.action.MAIN" />
11-
<category android:name="android.intent.category.LAUNCHER" />
7+
<action android:name="android.intent.action.MAIN"/><category android:name="android.intent.category.LAUNCHER" />
8+
129
</intent-filter>
1310
</activity>
14-
15-
<activity android:name=".video.VideoSample" android:screenOrientation="landscape" android:theme="@android:style/Theme.NoTitleBar"></activity>
1611
</application>
1712

1813
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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 edit
7+
# "ant.properties", and override values to adapt the script to your
8+
# project structure.
9+
#
10+
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11+
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12+
13+
# Project target.
14+
target=Google Inc.:Google APIs:10

android/Streaming_Audio_Player/res/anim/disapearing.xml

-4
This file was deleted.
Loading
Loading
Binary file not shown.

android/Streaming_Audio_Player/res/layout/main.xml

+43-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,43 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent"
3-
android:layout_height="fill_parent">
4-
<Button android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/buttonVideoSample" android:text="Video Sample"></Button>
5-
</LinearLayout>
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+
<EditText
9+
android:id="@+id/EditTextSongURL"
10+
android:layout_width="wrap_content"
11+
android:layout_height="wrap_content"
12+
android:layout_alignParentLeft="true"
13+
android:layout_alignParentRight="true"
14+
android:layout_alignParentTop="true"
15+
android:ems="10"
16+
android:height="100dp"
17+
android:lines="3"
18+
android:maxLines="3"
19+
android:minLines="1" >
20+
21+
<requestFocus />
22+
<requestFocus />
23+
24+
</EditText>
25+
26+
<ImageButton
27+
android:id="@+id/ButtonTestPlayPause"
28+
android:layout_width="match_parent"
29+
android:layout_height="wrap_content"
30+
android:layout_below="@+id/EditTextSongURL"
31+
android:layout_centerHorizontal="true"
32+
android:contentDescription="TestPlayPause"
33+
android:onClick="onClick"
34+
android:src="@drawable/button_play" />
35+
36+
<SeekBar
37+
android:id="@+id/SeekBarTestPlay"
38+
android:layout_width="fill_parent"
39+
android:layout_height="wrap_content"
40+
android:layout_alignParentLeft="true"
41+
android:layout_below="@+id/ButtonTestPlayPause" />
42+
43+
</RelativeLayout>

android/Streaming_Audio_Player/res/layout/videosample.xml

-23
This file was deleted.

android/Streaming_Audio_Player/res/values/colors.xml

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
3-
<color name="media_controller_text_color">#FFFFFF</color>
4-
<color name="media_controller_bg_color">#5f5f5f</color>
53
<color name="seekbar_bg">#141414</color>
64
<color name="seekbar_progress">#a53130</color>
75
<color name="seekbar_sec_progress">#875e5e</color>
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
3-
<string name="hello">Hello androidEx2!</string>
4-
<string name="app_name">androidEx2</string>
5-
</resources>
3+
<string name="app_name">Android mp3 player</string>
4+
<string name="testsong_20_sec">http://users.skynet.be/fa046054/home/P22/track06.mp3</string>
5+
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
package com.hrupin.streamingmedia;
2+
3+
import android.app.Activity;
4+
import android.media.MediaPlayer;
5+
import android.media.MediaPlayer.OnBufferingUpdateListener;
6+
import android.media.MediaPlayer.OnCompletionListener;
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.EditText;
14+
import android.widget.ImageButton;
15+
import android.widget.SeekBar;
16+
17+
import com.hrupin.streamingmedia.R;
18+
19+
public class StreamingMp3Player extends Activity implements OnClickListener, OnTouchListener, OnCompletionListener, OnBufferingUpdateListener{
20+
21+
private ImageButton buttonPlayPause;
22+
private SeekBar seekBarProgress;
23+
public EditText editTextSongURL;
24+
25+
private MediaPlayer mediaPlayer;
26+
private int mediaFileLengthInMilliseconds; // this value contains the song duration in milliseconds. Look at getDuration() method in MediaPlayer class
27+
28+
private final Handler handler = new Handler();
29+
30+
/** Called when the activity is first created. */
31+
@Override
32+
public void onCreate(Bundle savedInstanceState) {
33+
super.onCreate(savedInstanceState);
34+
setContentView(R.layout.main);
35+
initView();
36+
}
37+
38+
/** This method initialise all the views in project*/
39+
private void initView() {
40+
buttonPlayPause = (ImageButton)findViewById(R.id.ButtonTestPlayPause);
41+
buttonPlayPause.setOnClickListener(this);
42+
43+
seekBarProgress = (SeekBar)findViewById(R.id.SeekBarTestPlay);
44+
seekBarProgress.setMax(99); // It means 100% .0-99
45+
seekBarProgress.setOnTouchListener(this);
46+
editTextSongURL = (EditText)findViewById(R.id.EditTextSongURL);
47+
editTextSongURL.setText(R.string.testsong_20_sec);
48+
49+
mediaPlayer = new MediaPlayer();
50+
mediaPlayer.setOnBufferingUpdateListener(this);
51+
mediaPlayer.setOnCompletionListener(this);
52+
}
53+
54+
/** Method which updates the SeekBar primary progress by current song playing position*/
55+
private void primarySeekBarProgressUpdater() {
56+
seekBarProgress.setProgress((int)(((float)mediaPlayer.getCurrentPosition()/mediaFileLengthInMilliseconds)*100)); // This math construction give a percentage of "was playing"/"song length"
57+
if (mediaPlayer.isPlaying()) {
58+
Runnable notification = new Runnable() {
59+
public void run() {
60+
primarySeekBarProgressUpdater();
61+
}
62+
};
63+
handler.postDelayed(notification,1000);
64+
}
65+
}
66+
67+
@Override
68+
public void onClick(View v) {
69+
if(v.getId() == R.id.ButtonTestPlayPause){
70+
/** ImageButton onClick event handler. Method which start/pause mediaplayer playing */
71+
try {
72+
mediaPlayer.setDataSource(editTextSongURL.getText().toString()); // setup song from http://www.hrupin.com/wp-content/uploads/mp3/testsong_20_sec.mp3 URL to mediaplayer data source
73+
mediaPlayer.prepare(); // you must call this method after setup the datasource in setDataSource method. After calling prepare() the instance of MediaPlayer starts load data from URL to internal buffer.
74+
} catch (Exception e) {
75+
e.printStackTrace();
76+
}
77+
78+
mediaFileLengthInMilliseconds = mediaPlayer.getDuration(); // gets the song length in milliseconds from URL
79+
80+
if(!mediaPlayer.isPlaying()){
81+
mediaPlayer.start();
82+
buttonPlayPause.setImageResource(R.drawable.button_pause);
83+
}else {
84+
mediaPlayer.pause();
85+
buttonPlayPause.setImageResource(R.drawable.button_play);
86+
}
87+
88+
primarySeekBarProgressUpdater();
89+
}
90+
}
91+
92+
@Override
93+
public boolean onTouch(View v, MotionEvent event) {
94+
if(v.getId() == R.id.SeekBarTestPlay){
95+
/** Seekbar onTouch event handler. Method which seeks MediaPlayer to seekBar primary progress position*/
96+
if(mediaPlayer.isPlaying()){
97+
SeekBar sb = (SeekBar)v;
98+
int playPositionInMillisecconds = (mediaFileLengthInMilliseconds / 100) * sb.getProgress();
99+
mediaPlayer.seekTo(playPositionInMillisecconds);
100+
}
101+
}
102+
return false;
103+
}
104+
105+
@Override
106+
public void onCompletion(MediaPlayer mp) {
107+
/** MediaPlayer onCompletion event handler. Method which calls then song playing is complete*/
108+
buttonPlayPause.setImageResource(R.drawable.button_play);
109+
}
110+
111+
@Override
112+
public void onBufferingUpdate(MediaPlayer mp, int percent) {
113+
/** Method which updates the SeekBar secondary progress by current song loading from URL position*/
114+
seekBarProgress.setSecondaryProgress(percent);
115+
}
116+
}
117+

android/Streaming_Audio_Player/src/main/java/com/hrupin/edu/androidEx2/HelloAndroidActivity.java

-44
This file was deleted.

android/Streaming_Audio_Player/src/main/java/com/hrupin/edu/androidEx2/video/Utils.java

-13
This file was deleted.

0 commit comments

Comments
 (0)