blob: 62d981b55674cd6fe086f075c56af35eb9a8b212 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
package de.danoeh.antennapod.core.util.playback;
import android.content.Context;
import android.content.Intent;
import android.os.Parcelable;
import androidx.core.content.ContextCompat;
import de.danoeh.antennapod.core.service.playback.PlaybackService;
import de.danoeh.antennapod.model.playback.Playable;
public class PlaybackServiceStarter {
private final Context context;
private final Playable media;
private boolean shouldStreamThisTime = false;
private boolean callEvenIfRunning = false;
public PlaybackServiceStarter(Context context, Playable media) {
this.context = context;
this.media = media;
}
/**
* Default value: false
*/
public PlaybackServiceStarter callEvenIfRunning(boolean callEvenIfRunning) {
this.callEvenIfRunning = callEvenIfRunning;
return this;
}
public PlaybackServiceStarter shouldStreamThisTime(boolean shouldStreamThisTime) {
this.shouldStreamThisTime = shouldStreamThisTime;
return this;
}
public Intent getIntent() {
Intent launchIntent = new Intent(context, PlaybackService.class);
launchIntent.putExtra(PlaybackService.EXTRA_PLAYABLE, (Parcelable) media);
launchIntent.putExtra(PlaybackService.EXTRA_ALLOW_STREAM_THIS_TIME, shouldStreamThisTime);
return launchIntent;
}
public void start() {
if (PlaybackService.isRunning && !callEvenIfRunning) {
return;
}
ContextCompat.startForegroundService(context, getIntent());
}
}
|