i'm working on radio streaming application. work decided create library project code refactoring
so in library project have :
- streamingservice.java
- streamingplayermp.java
- streamingplayeraac.java
- streamingcallback.java
- streamingnotification.java
- streamingstate.java
- streamingstation.java
do need define service in both library manifest , application manifest ?
<service android:name=".streamingservice" android:enabled="true" > </service>
do need put permissions in both library manifest , application manifest ?
currently service/players/callback ready use. want manage service serviceconnection , binder main activity :
public void bindtoservice() { intent intent = new intent(getapplicationcontext(), streamingservice.class); if (((testingapplication) getapplication()).mediaplayerservicerunning()) { log.i(tag, "bindtoservice--"); // bind localservice bindservice(intent, _connectionstreaming, context.bind_auto_create); } else { log.i(tag, "bindtoservice--startservice--"); startservice(intent); boolean isbound = bindservice(intent, _connectionstreaming, context.bind_auto_create); log.d(tag, "is service bound--" + isbound); } } private serviceconnection _connectionstreaming = new serviceconnection() { @override public void onserviceconnected(componentname classname, ibinder servicebinder) { log.d(tag, "onserviceconnected--"); // service mediaplayerbinder binder = (mediaplayerbinder) servicebinder; testingapplication._mediaplayerservice = binder.getserviceinstance(); // callback testingapplication._mediaplayerservice.setinitcallback(mainactivity.this); testingapplication._mediaplayerservice.initializeplayer(getstring(r.string.url_podcast_mp3_test)); _bound = true; } @override public void onservicedisconnected(componentname arg0) { log.d(tag, "onservicedisconnected--"); _bound = false; } };
and binder methods (located in service):
private final binder _binder = new mediaplayerbinder(); public class mediaplayerbinder extends binder { public streamingservice getserviceinstance() { log.i(tag, "getserviceinstance--"); return streamingservice.this; } } @override public ibinder onbind(intent arg0) { log.i(tag, "onbind--"); return _binder; }
the service foregroundservice :
@override public int onstartcommand(intent intent, int flags, int startid) { log.i(tag, "onstartcommand--"); _runningcallback.onbufferingstarted(); return start_sticky; }
if have complete solution welcome ! advices welcome too
Comments
Post a Comment