私は現在、ラジオストリーミングアプリケーションに取り組んでいます。作業を行うために、コードのリファクタリングを行うライブラリ プロジェクトを作成することにしました。
したがって、私のライブラリプロジェクトには次のものがあります:
- StreamingService.java
- StreamingPlayerMP.java
- StreamingPlayerAAC.java
- StreamingCallback.java
- StreamingNotification.java
- StreamingState.java
- StreamingStation.java
ライブラリ マニフェストとアプリケーション マニフェストの両方でサービスを定義する必要がありますか?
<service
android:name=".StreamingService"
android:enabled="true" >
</service>
ライブラリ マニフェストとアプリケーション マニフェストの両方にアクセス許可を設定する必要がありますか?
現在、Service/players/callbackを使用する準備ができています。ServiceConnectionとメイン アクティビティへのバインダーを使用してサービスを管理したい:
public void bindToService() {
Intent intent = new Intent(getApplicationContext(), StreamingService.class);
if (((TestingApplication) getApplication()).MediaPlayerServiceRunning()) {
Log.i(TAG, "bindToService--");
// Bind to 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;
}
};
そしてバインダーメソッド(サービスにあります):
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;
}
サービスは foregroundservice です:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i(TAG, "onStartCommand--");
_runningCallBack.onBufferingStarted();
return START_STICKY;
}
あなたが完全な解決策を持っているなら、あなたは大歓迎です! アドバイスも大歓迎