Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9eadd59
Added files via upload
thedude61636 Apr 29, 2016
27ce076
Added files via upload
thedude61636 Apr 29, 2016
f72364c
Added files via upload
thedude61636 Apr 29, 2016
dfa3d35
Added files via upload
thedude61636 Apr 29, 2016
ffa9835
Added files via upload
thedude61636 Apr 29, 2016
a3417dc
Update build.gradle
thedude61636 Apr 29, 2016
4a942a4
Update build.gradle
thedude61636 Apr 29, 2016
e2e21d5
Update README.md
thedude61636 Apr 29, 2016
127300f
Update README.md
thedude61636 Apr 29, 2016
c211fcd
Update README.md
thedude61636 Apr 29, 2016
793aac6
Update strings.xml
thedude61636 Apr 29, 2016
b01b2bd
Update RadioPlayerService.java
thedude61636 Apr 29, 2016
c05d8fe
Update RadioPlayerService.java
thedude61636 Apr 29, 2016
b315478
Update RadioPlayerService.java
thedude61636 Apr 29, 2016
2c22bf4
update gradle version
thedude61636 Apr 30, 2016
487747e
changed notification to notificationcompat
thedude61636 May 11, 2016
a9b67d7
added cancelNotification
thedude61636 May 11, 2016
f92b6c5
added cancelNotification
thedude61636 May 11, 2016
eeeb8cf
changed notification to notificationcompat
thedude61636 May 11, 2016
7f394a9
changed notification to notificationcompat
thedude61636 May 11, 2016
61108a8
Delete btn_notification_collapse.png
thedude61636 May 11, 2016
08acfb2
Delete btn_playback_pause.png
thedude61636 May 11, 2016
301c0cd
Delete btn_playback_play.png
thedude61636 May 11, 2016
9a8e2c1
replaced png with vector
thedude61636 May 11, 2016
a736ac9
Update README.md
thedude61636 May 11, 2016
0a62d99
Update README.md
thedude61636 May 11, 2016
2b0b68c
update compileSdkVersion and targetSdkVersion to 23
thedude61636 May 11, 2016
bce506f
update compileSdkVersion and targetSdkVersion to 23
thedude61636 May 11, 2016
ca16a71
updated buildToolsVersion
thedude61636 May 11, 2016
300e859
Update README.md
thedude61636 Aug 5, 2016
836cfa3
Update RadioManager.java
thedude61636 Aug 5, 2016
8fc8e71
Update RadioPlayerService.java
thedude61636 Aug 5, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# RadioPlayerService
[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-RadioPlayerService-green.svg?style=flat)](http://android-arsenal.com/details/1/2168)


Android service library which uses AAC Player. Ready to use Radio Player Service. (Android Background Player Service)

Expand Down Expand Up @@ -41,7 +41,7 @@ repositories {

```
dependencies {
compile 'com.github.iammert:RadioPlayerService:efe3b5420b'
compile 'com.github.thedude61636:RadioPlayerService:1.5'
}
```

Expand Down Expand Up @@ -69,6 +69,10 @@ mRadioManager.connect();
//Invoke it #onDestroy
mRadioManager.disconnect();
```
```java
//Cancel notification and stop the player
mRadioManager.cancelNotification();
```

Play and pause radio like
```java
Expand Down Expand Up @@ -113,8 +117,6 @@ RadioManager.with(getActivity()).unregisterListener(this);

Demo project will help you to understand implementation.

## Error Case Solutions ##
If you get UnsatisfiedLinkError on some android devices, please go through the [link](https://medium.com/mobiwise-blog/unsatisfiedlinkerror-problem-on-some-android-devices-b77f2f83837d#.c1vlmowal) that I explained how to solve it.


## TODO LIST##
Expand Down
9 changes: 4 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 22
buildToolsVersion "23.0.1"
compileSdkVersion 23
buildToolsVersion "23.0.3"

defaultConfig {
applicationId "co.mobiwise.myapplication"
minSdkVersion 16
targetSdkVersion 22
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"

Expand All @@ -29,5 +29,4 @@ repositories {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':library')
//compile 'com.github.iammert:RadioPlayerService:9a0cc8dc94'
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.android.tools.build:gradle:2.1.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
13 changes: 5 additions & 8 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
compileSdkVersion 23
buildToolsVersion "23.0.3"

defaultConfig {
minSdkVersion 16
targetSdkVersion 22
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"

ndk {
abiFilters "armeabi-v7a", "x86", "armeabi", "mips"
}

}
buildTypes {
Expand All @@ -25,6 +22,6 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:appcompat-v7:23.3.0'
compile files('libs/aacdecoder-android-0.8.jar')
}
Binary file modified library/libs/aacdecoder-android-0.8.jar
Binary file not shown.
289 changes: 149 additions & 140 deletions library/src/main/java/co/mobiwise/library/media/MediaManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,150 +16,159 @@
*/
public class MediaManager {

/**
* Context
*/
private Context mContext;

/**
* MediaPlayerService
*/
private static MediaPlayerService mService;

/**
* Boolean check for service connection
*/
private boolean isServiceConnected = false;

/**
* Listeners wil lbe added here if
* service is not connected yet.
* After service connected, we will empty this queue
* by adding them to service listeners list.
*/
private List<MediaListener> mMediaListenerQueue;

/**
* MediaManager
*/
private static MediaManager instance = null;

/**
* if play requested before service connection, we set this value as true.
*/
private boolean isPlayRequested = false;

/**
* current stream URL
*/
private String mStreamURL;

/**
* private construtor
*/
private MediaManager(Context mContext) {
this.mContext = mContext;
mMediaListenerQueue = new ArrayList<>();
}

/**
* Singleton instance
*
* @return
*/
public static MediaManager with(Context context) {
if (instance == null)
instance = new MediaManager(context);
return instance;
}

public static MediaPlayerService getService() {
return mService;
}

public void play(String mStreamURL) {
this.mStreamURL = mStreamURL;
if (isServiceConnected) {
mService.play(mStreamURL);
} else {
isPlayRequested = true;
/**
* Context
*/
private Context mContext;

/**
* MediaPlayerService
*/
private static MediaPlayerService mService;

/**
* Boolean check for service connection
*/
private boolean isServiceConnected = false;

/**
* Listeners wil lbe added here if
* service is not connected yet.
* After service connected, we will empty this queue
* by adding them to service listeners list.
*/
private List<MediaListener> mMediaListenerQueue;

/**
* MediaManager
*/
private static MediaManager instance = null;

/**
* if play requested before service connection, we set this value as true.
*/
private boolean isPlayRequested = false;

/**
* current stream URL
*/
private String mStreamURL;

/**
* private construtor
*/
private MediaManager(Context mContext) {
this.mContext = mContext;
mMediaListenerQueue = new ArrayList<>();
}
}

public void pause() {
if (isServiceConnected)
mService.pause();
}

public void seekTo(int duration) {
if (isServiceConnected)
mService.seekTo(duration);
}

public boolean isPlaying() {
if (isServiceConnected)
return mService.isPlaying();
return false;
}

public void updateNotification(String singerName, String songName, int smallArt, int bigArt) {
if (mService != null)
mService.updateNotification(singerName, songName, smallArt, bigArt);
}

public void updateNotification(String singerName, String songName, int smallArt, Bitmap bigArt) {
if (mService != null)
mService.updateNotification(singerName, songName, smallArt, bigArt);
}

public void registerListener(MediaListener mediaListener) {
if (isServiceConnected)
mService.registerMediaListener(mediaListener);
else
mMediaListenerQueue.add(mediaListener);
}

/**
* Connect service
*/
public void connect() {
Intent intent = new Intent(mContext, MediaPlayerService.class);
mContext.bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE);
}

/**
* Disconnect service
*/
public void disconnect() {
mContext.unbindService(mServiceConnection);
}

/**
* Connection
*/
private ServiceConnection mServiceConnection = new ServiceConnection() {

@Override
public void onServiceConnected(ComponentName arg0, IBinder binder) {

Log.v("TEST", "SERVICE CONNECTED.");
mService = ((MediaPlayerService.LocalBinder) binder).getService();
isServiceConnected = true;
if (isPlayRequested) {
play(mStreamURL);
isPlayRequested = false;
}

if (!mMediaListenerQueue.isEmpty()) {
for (MediaListener mediaListener : mMediaListenerQueue)
registerListener(mediaListener);
}

/**
* Singleton instance
*
* @return
*/
public static MediaManager with(Context context) {
if (instance == null)
instance = new MediaManager(context);
return instance;
}

public static MediaPlayerService getService() {
return mService;
}

public void play(String mStreamURL) {
this.mStreamURL = mStreamURL;
if (isServiceConnected) {
mService.play(mStreamURL);
} else {
isPlayRequested = true;
}
}

public void pause() {
if (isServiceConnected)
mService.pause();
}

public void seekTo(int duration) {
if (isServiceConnected)
mService.seekTo(duration);
}

public boolean isPlaying() {
if (isServiceConnected)
return mService.isPlaying();
return false;
}

public void updateNotification(String singerName, String songName, int smallArt, int bigArt) {
if (mService != null)
mService.updateNotification(singerName, songName, smallArt, bigArt);
}

public void updateNotification(String singerName, String songName, int smallArt, Bitmap bigArt) {
if (mService != null)
mService.updateNotification(singerName, songName, smallArt, bigArt);
}

@Override
public void onServiceDisconnected(ComponentName arg0) {
public void cancelNotification(){
if (mService!=null){
mService.cancelNotification();
}
}
};

public void registerListener(MediaListener mediaListener) {
if (isServiceConnected)
mService.registerMediaListener(mediaListener);
else
mMediaListenerQueue.add(mediaListener);
}

/**
* Connect service
*/
public void connect() {
Intent intent = new Intent(mContext, MediaPlayerService.class);
mContext.bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE);
}

/**
* Disconnect service
*/
public void disconnect() {
mContext.unbindService(mServiceConnection);
}




/**
* Connection
*/
private ServiceConnection mServiceConnection = new ServiceConnection() {

@Override
public void onServiceConnected(ComponentName arg0, IBinder binder) {

Log.v("TEST", "SERVICE CONNECTED.");
mService = ((MediaPlayerService.LocalBinder) binder).getService();
isServiceConnected = true;
if (isPlayRequested) {
play(mStreamURL);
isPlayRequested = false;
}

if (!mMediaListenerQueue.isEmpty()) {
for (MediaListener mediaListener : mMediaListenerQueue)
registerListener(mediaListener);
}
}

@Override
public void onServiceDisconnected(ComponentName arg0) {
}
};


}
Loading