| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
package com.android.onemedia.playback; |
| 17 |
|
| 18 |
import android.content.Context; |
| 19 |
import android.media.MediaPlayer; |
| 20 |
import android.os.Bundle; |
| 21 |
|
| 22 |
import java.util.ArrayList; |
| 23 |
import java.util.List; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public abstract class Renderer { |
| 29 |
public static final String FEATURE_SET_CONTENT = "com.android.media.SET_CONTENT"; |
| 30 |
public static final String FEATURE_SET_NEXT_CONTENT = "com.android.media.SET_NEXT_CONTENT"; |
| 31 |
public static final String FEATURE_PLAY = "com.android.media.PLAY"; |
| 32 |
public static final String FEATURE_PAUSE = "com.android.media.PAUSE"; |
| 33 |
public static final String FEATURE_NEXT = "com.android.media.NEXT"; |
| 34 |
public static final String FEATURE_PREVIOUS = "com.android.media.PREVIOUS"; |
| 35 |
public static final String FEATURE_SEEK_TO = "com.android.media.SEEK_TO"; |
| 36 |
public static final String FEATURE_STOP = "com.android.media.STOP"; |
| 37 |
|
| 38 |
public static final int STATE_ERROR = 0; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
public static final int STATE_INIT = 1 << 0; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
public static final int STATE_PREPARING = 1 << 1; |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
public static final int STATE_READY = 1 << 2; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
public static final int STATE_PLAYING = 1 << 3; |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
public static final int STATE_PAUSED = 1 << 4; |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
public static final int STATE_STOPPED = 1 << 5; |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
public static final int STATE_ENDED = 1 << 6; |
| 70 |
|
| 71 |
|
| 72 |
protected List<String> mFeatures = new ArrayList<String>(); |
| 73 |
protected List<Listener> mListeners = new ArrayList<Listener>(); |
| 74 |
|
| 75 |
public Renderer(Context context, Bundle params) { |
| 76 |
onCreate(params); |
| 77 |
initFeatures(params); |
| 78 |
} |
| 79 |
|
| 80 |
abstract public void setContent(Bundle request); |
| 81 |
|
| 82 |
public void onCreate(Bundle params) { |
| 83 |
|
| 84 |
} |
| 85 |
|
| 86 |
public void setNextContent(Bundle request) { |
| 87 |
throw new UnsupportedOperationException("setNextContent() is not supported."); |
| 88 |
} |
| 89 |
|
| 90 |
public List<String> getFeatures() { |
| 91 |
return mFeatures; |
| 92 |
} |
| 93 |
|
| 94 |
public boolean onPlay() { |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
return false; |
| 99 |
} |
| 100 |
|
| 101 |
public boolean onPause() { |
| 102 |
|
| 103 |
return false; |
| 104 |
} |
| 105 |
|
| 106 |
public boolean onNext() { |
| 107 |
|
| 108 |
return false; |
| 109 |
} |
| 110 |
|
| 111 |
public boolean onPrevious() { |
| 112 |
|
| 113 |
|
| 114 |
return false; |
| 115 |
} |
| 116 |
|
| 117 |
public boolean onStop() { |
| 118 |
|
| 119 |
return false; |
| 120 |
} |
| 121 |
|
| 122 |
public boolean onSeekTo(int time) { |
| 123 |
|
| 124 |
return false; |
| 125 |
} |
| 126 |
|
| 127 |
public long getSeekPosition() { |
| 128 |
|
| 129 |
|
| 130 |
return -1; |
| 131 |
} |
| 132 |
|
| 133 |
public long getDuration() { |
| 134 |
|
| 135 |
|
| 136 |
return -1; |
| 137 |
} |
| 138 |
|
| 139 |
public int getPlayState() { |
| 140 |
|
| 141 |
|
| 142 |
return 0; |
| 143 |
} |
| 144 |
|
| 145 |
public void onDestroy() { |
| 146 |
|
| 147 |
} |
| 148 |
|
| 149 |
public void registerListener(Listener listener) { |
| 150 |
if (!mListeners.contains(listener)) { |
| 151 |
mListeners.add(listener); |
| 152 |
} |
| 153 |
} |
| 154 |
|
| 155 |
public void unregisterListener(Listener listener) { |
| 156 |
mListeners.remove(listener); |
| 157 |
} |
| 158 |
|
| 159 |
protected void initFeatures(Bundle params) { |
| 160 |
mFeatures.add(FEATURE_SET_CONTENT); |
| 161 |
} |
| 162 |
|
| 163 |
protected void pushOnError(int type, int extra, Bundle extras, Throwable error) { |
| 164 |
for (Listener listener : mListeners) { |
| 165 |
listener.onError(type, extra, extras, error); |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
protected void pushOnStateChanged(int newState) { |
| 170 |
for (Listener listener : mListeners) { |
| 171 |
listener.onStateChanged(newState); |
| 172 |
} |
| 173 |
} |
| 174 |
|
| 175 |
protected void pushOnBufferingUpdate(int percent) { |
| 176 |
for (Listener listener : mListeners) { |
| 177 |
listener.onBufferingUpdate(percent); |
| 178 |
} |
| 179 |
} |
| 180 |
|
| 181 |
protected void pushOnFocusLost() { |
| 182 |
for (Listener listener : mListeners) { |
| 183 |
listener.onFocusLost(); |
| 184 |
} |
| 185 |
} |
| 186 |
|
| 187 |
protected void pushOnNextStarted() { |
| 188 |
for (Listener listener : mListeners) { |
| 189 |
listener.onNextStarted(); |
| 190 |
} |
| 191 |
} |
| 192 |
|
| 193 |
public interface Listener { |
| 194 |
public static final int ERROR_LOAD_FAILED = 1770; |
| 195 |
public static final int ERROR_PREPARE_ERROR = 1771; |
| 196 |
public static final int ERROR_PLAYBACK_FAILED = 1772; |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
public void onError(int type, int extra, Bundle extras, |
| 204 |
Throwable error); |
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
public void onStateChanged(int newState); |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
public void onBufferingUpdate(int percent); |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
public void onFocusLost(); |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
public void onNextStarted(); |
| 228 |
} |
| 229 |
} |