blob: 6c70496d006e034d6775b8393e1457a44701c149 (
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
/*
This file is part of Subsonic.
Subsonic is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Subsonic is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
Copyright 2009 (C) Sindre Mehus
*/
package github.daneren2005.dsub.service;
import android.util.Log;
import java.util.Iterator;
import java.util.concurrent.LinkedBlockingQueue;
import github.daneren2005.dsub.domain.RemoteStatus;
import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.util.Util;
import github.daneren2005.serverproxy.WebProxy;
public abstract class RemoteController {
private static final String TAG = RemoteController.class.getSimpleName();
protected DownloadService downloadService;
protected boolean nextSupported = false;
public abstract void create(boolean playing, int seconds);
public abstract void start();
public abstract void stop();
public abstract void shutdown();
public abstract void updatePlaylist();
public abstract void changePosition(int seconds);
public abstract void changeTrack(int index, DownloadFile song);
// Really is abstract, just don't want to require RemoteController's support it
public void changeNextTrack(DownloadFile song) {}
public boolean isNextSupported() {
if(Util.getPreferences(downloadService).getBoolean(Constants.PREFERENCES_KEY_CAST_GAPLESS_PLAYBACK, true)) {
return this.nextSupported;
} else {
return false;
}
}
public abstract void setVolume(int volume);
public abstract void updateVolume(boolean up);
public abstract double getVolume();
public boolean isSeekable() {
return true;
}
public abstract int getRemotePosition();
public int getRemoteDuration() {
return 0;
}
protected abstract class RemoteTask {
abstract RemoteStatus execute() throws Exception;
@Override
public String toString() {
return getClass().getSimpleName();
}
}
protected static class TaskQueue {
private final LinkedBlockingQueue<RemoteTask> queue = new LinkedBlockingQueue<RemoteTask>();
void add(RemoteTask jukeboxTask) {
queue.add(jukeboxTask);
}
RemoteTask take() throws InterruptedException {
return queue.take();
}
void remove(Class<? extends RemoteTask> clazz) {
try {
Iterator<RemoteTask> iterator = queue.iterator();
while (iterator.hasNext()) {
RemoteTask task = iterator.next();
if (clazz.equals(task.getClass())) {
iterator.remove();
}
}
} catch (Throwable x) {
Log.w(TAG, "Failed to clean-up task queue.", x);
}
}
void clear() {
queue.clear();
}
}
protected WebProxy createWebProxy() {
MusicService musicService = MusicServiceFactory.getMusicService(downloadService);
if(musicService instanceof CachedMusicService) {
return new WebProxy(downloadService, ((CachedMusicService)musicService).getMusicService().getHttpClient());
} else {
return new WebProxy(downloadService);
}
}
}
|