Merge pull request #4591 from ByteHamster/ensure-background-thread
Ensure that first DB query is executed in background thread
This commit is contained in:
commit
a0c604dc86
|
@ -502,16 +502,27 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
||||||
stateManager.stopService();
|
stateManager.stopService();
|
||||||
return Service.START_NOT_STICKY;
|
return Service.START_NOT_STICKY;
|
||||||
}
|
}
|
||||||
if (playable instanceof FeedMedia) {
|
|
||||||
playable = DBReader.getFeedMedia(((FeedMedia) playable).getId());
|
Observable.fromCallable(
|
||||||
}
|
() -> {
|
||||||
if (playable == null) {
|
if (playable instanceof FeedMedia) {
|
||||||
Log.d(TAG, "Playable was not found. Stopping service.");
|
return DBReader.getFeedMedia(((FeedMedia) playable).getId());
|
||||||
stateManager.stopService();
|
} else {
|
||||||
return Service.START_NOT_STICKY;
|
return playable;
|
||||||
}
|
}
|
||||||
mediaPlayer.playMediaObject(playable, stream, startWhenPrepared, prepareImmediately);
|
})
|
||||||
addPlayableToQueue(playable);
|
.subscribeOn(Schedulers.io())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(
|
||||||
|
playableLoaded -> {
|
||||||
|
mediaPlayer.playMediaObject(playable, stream, startWhenPrepared,
|
||||||
|
prepareImmediately);
|
||||||
|
addPlayableToQueue(playable);
|
||||||
|
}, error -> {
|
||||||
|
Log.d(TAG, "Playable was not found. Stopping service.");
|
||||||
|
stateManager.stopService();
|
||||||
|
});
|
||||||
|
return Service.START_NOT_STICKY;
|
||||||
} else {
|
} else {
|
||||||
Log.d(TAG, "Did not handle intent to PlaybackService: " + intent);
|
Log.d(TAG, "Did not handle intent to PlaybackService: " + intent);
|
||||||
Log.d(TAG, "Extras: " + intent.getExtras());
|
Log.d(TAG, "Extras: " + intent.getExtras());
|
||||||
|
@ -680,26 +691,31 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startPlayingFromPreferences() {
|
private void startPlayingFromPreferences() {
|
||||||
Playable playable = Playable.PlayableUtils.createInstanceFromPreferences(getApplicationContext());
|
Observable.fromCallable(() -> Playable.PlayableUtils.createInstanceFromPreferences(getApplicationContext()))
|
||||||
if (playable != null) {
|
.subscribeOn(Schedulers.io())
|
||||||
if (PlaybackPreferences.getCurrentEpisodeIsStream() && !NetworkUtils.isStreamingAllowed()) {
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
displayStreamingNotAllowedNotification(
|
.subscribe(
|
||||||
new PlaybackServiceStarter(this, playable)
|
playable -> {
|
||||||
.prepareImmediately(true)
|
if (PlaybackPreferences.getCurrentEpisodeIsStream() && !NetworkUtils.isStreamingAllowed()) {
|
||||||
.startWhenPrepared(true)
|
displayStreamingNotAllowedNotification(
|
||||||
.shouldStream(true)
|
new PlaybackServiceStarter(this, playable)
|
||||||
.getIntent());
|
.prepareImmediately(true)
|
||||||
PlaybackPreferences.writeNoMediaPlaying();
|
.startWhenPrepared(true)
|
||||||
stateManager.stopService();
|
.shouldStream(true)
|
||||||
return;
|
.getIntent());
|
||||||
}
|
PlaybackPreferences.writeNoMediaPlaying();
|
||||||
mediaPlayer.playMediaObject(playable, PlaybackPreferences.getCurrentEpisodeIsStream(), true, true);
|
stateManager.stopService();
|
||||||
stateManager.validStartCommandWasReceived();
|
return;
|
||||||
PlaybackService.this.updateMediaSessionMetadata(playable);
|
}
|
||||||
addPlayableToQueue(playable);
|
mediaPlayer.playMediaObject(playable, PlaybackPreferences.getCurrentEpisodeIsStream(),
|
||||||
} else {
|
true, true);
|
||||||
stateManager.stopService();
|
stateManager.validStartCommandWasReceived();
|
||||||
}
|
PlaybackService.this.updateMediaSessionMetadata(playable);
|
||||||
|
addPlayableToQueue(playable);
|
||||||
|
}, error -> {
|
||||||
|
Log.d(TAG, "Playable was not loaded from preferences. Stopping service.");
|
||||||
|
stateManager.stopService();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue