-
Notifications
You must be signed in to change notification settings - Fork 5
/
IPlayer.java
372 lines (319 loc) · 12.2 KB
/
IPlayer.java
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
/*
* Copyright (c) 2017 K Sun <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jcodeing.kmedia;
import android.Manifest.permission;
import android.content.Intent;
import android.net.Uri;
import android.support.annotation.RequiresPermission;
import com.jcodeing.kmedia.assist.AudioMgrHelper;
import com.jcodeing.kmedia.assist.C;
import com.jcodeing.kmedia.definition.IMediaItem;
import com.jcodeing.kmedia.definition.IMediaQueue;
import com.jcodeing.kmedia.definition.IPositionUnitList;
import java.util.ArrayList;
/**
* Interface Player
*
* @param <P> subClass
* @see Player
* @see PlayerBinding
*/
public interface IPlayer<P extends IPlayer> extends IPlayerBase {
// ============================@Player
/**
* Get a internal mediaPlayer
* <pre>
* Player run core by internal maintaining mediaPlayer.
* In general is not recommended unless you want to operate some special functions.
* * note that internalPlayer and Player
* * at the same time operating possible when the incompatibilities
* </pre>
*/
IMediaPlayer internalPlayer();
/**
* Init internal media player
*/
P init(IMediaPlayer mediaPlayer);
boolean prepare(Uri uri);
boolean prepare(IMediaItem mediaItem);
boolean prepareMediaId(String mediaId);
boolean play();
boolean play(Uri uri);
boolean play(IMediaItem mediaItem);
boolean playMediaId(String mediaId);
/**
* Shut down player (release all resources)
*/
void shutdown();
// ============================@Control
/**
* Support custom processing level of seekTo
*
* @param processingLevel The greater the level with processing the more things<ul> <li>1:
* Callback {@link Listener#onPlayProgress(long, long)}</li> <li>2: Call {@link
* #calibrateCurrentPositionUnitIndex(long)} </li></ul>
*/
boolean seekTo(long ms, int processingLevel);
/**
* internal call {@link #seekTo(long, int)} Max processing level
*/
boolean seekTo(long ms);
/**
* @param ms fastForwardMs/RewindMs <ul> <li>+ms: fastForward <p /> .fastForwardRewind(1000)->fast
* forward 1 second <li>-ms: RewindMs <p /> .fastForwardRewind(-1000)->rewind 1 second<ul/>
*/
boolean fastForwardRewind(long ms);
/**
* Generally used in front of the seekTo...(.) to ensure that seek complete to auto play
* immediately after
* <pre>
* *{@link #start()} method with shouldAutoPlayWhenSeekComplete(true)
* *{@link #pause()} with shouldAutoPlayWhenSeekComplete(false)
* </pre>
*/
P shouldAutoPlayWhenSeekComplete(boolean shouldAutoPlayWhenSeekComplete);
/**
* set a pending seekTo in before start() dispose
*/
void seekToPending(long ms);
/**
* Seeks to specified progress
*
* @param progress current progress
* @param progressMax the upper limit of this progress range.
* @return seekTo position (>=0), or -1 if seekTo Failure.
*/
long seekToProgress(int progress, int progressMax);
// ============================@Set/Get/Is
/**
* Sets the updatePlayProgress delay. <p /> More accurate to handle progress type work. <ul>
* <li>{@link #setAB(long, long)} <li>{@link #setABLoop(int, int)} <li>{@link #setAB(long, long,
* int, int)} <li>{@link #setEnabledPositionUnitLoop(boolean, int, int)} <li>{@link
* Listener#onPlayProgress(long, long)} <li>{@link Listener#onABProgress(long, long, int)}
* <li>{@link Listener#onPositionUnitProgress(long, int, int)} <li>...... <ul/>
*
* @param updatePlayProgressDelayMs value>=0?value:default[1000 - (position % 1000)]
*/
P setUpdatePlayProgressDelayMs(long updatePlayProgressDelayMs);
/**
* Returns current media id (custom or default[string representation of this play uri])
*/
String getCurrentMediaId();
/**
* Set enabled wifi lock, to hold a Wifi lock, which prevents the player from going to sleep while
* the media is playing.
*
* <p /> RequiresPermission(Manifest.permission.WAKE_LOCK) <p /> AndroidManifest.xml add below
* <pre>
* <!--Using a WifiLock For KMedia Player-->
* <uses-permission android:name="android.permission.WAKE_LOCK"/>
* </pre>
*/
@RequiresPermission(permission.WAKE_LOCK)
P setEnabledWifiLock(boolean enabled);
P setEnabledAudioFocusManage(boolean enabled);
AudioMgrHelper getAudioMgrHelper();
// ============================@PositionUnit
/**
* WARNING: must ensure {@link IPositionUnitList#getMediaId()} equals {@link #getCurrentMediaId()}
* can work normally
*
* @param posUnitList [Position Unit] List
*/
P setPositionUnitList(IPositionUnitList posUnitList);
/**
* @return current position unit index OR -1(unset | waiting state)
*/
int getCurrentPositionUnitIndex();
/**
* generally not use(player inside Will automatically maintain current [position unit] index)
* <p>If you want to calibrate,can call {@link #calibrateCurrentPositionUnitIndex(long)}<p/>
*/
void setCurrentPositionUnitIndex(int posUnitIndex);
/**
* Seeks to specified PositionUnitIndex
*
* @return seekTo position (>=0), or -1 if seekTo Failure.
*/
long seekToPositionUnitIndex(int posUnitIndex);
/**
* generally not use(player inside Will automatically maintain current [position unit] index
* calibrate)
*
* @param position currentPosition or -1[position < 0 || position > getDuration()] (auto
* getCurrentPosition())
* @return calibrated PositionUnitIndex or -1(not calibrate or calibrate result not present)
*/
int calibrateCurrentPositionUnitIndex(long position);
// =========@Loop
/**
* Set the enabled,loopMode,loopInterval of this position unit loop, with reset position unit
* looped count tag <p /> *param loopMode,loopInterval can use {@link C#PARAM_ORIGINAL} keeping
* the original values <p /> *param loopMode,loopInterval can use {@link C#PARAM_UNSET}/{@link
* C#PARAM_RESET} unset/reset values
*
* @param enabled True [position unit] loop is enabled, false otherwise.
* @param loopMode [Position unit] loop mode <ul> <li>-1 disable <li>-8 infinity loop <li>0++
* specified loop<ul/>
* @param loopInterval [Position unit] loop interval
* @see #setUpdatePlayProgressDelayMs(long)
*/
P setEnabledPositionUnitLoop(boolean enabled, int loopMode, int loopInterval);
/**
* WARNING: media source change with specify to loop of [position unit] index list will be reset
*
* @param posUnitLoopIndexList specify to loop of [position unit] index list
*/
P setPositionUnitLoopIndexList(ArrayList<Integer> posUnitLoopIndexList);
// ============================@AB
/**
* Set A-B start position and end position with reset ab all tag
*
* @param startPos [A-B] start position (Ms)
* @param endPos [A-B] end position (Ms)
* @return {@link IPlayer} !setAB but does not play. You must call play(?) to play.
* @see #play()
* @see #play(Uri)
*/
P setAB(long startPos, long endPos);
/**
* Set A-B loop <p /> *param loopMode,loopInterval can use {@link C#PARAM_ORIGINAL} keeping the
* original values <p /> *param loopMode,loopInterval can use {@link C#PARAM_UNSET}/{@link
* C#PARAM_RESET} unset/reset values
*
* @param loopMode [A-B] loop mode <ul> <li>-1 disable <li>-8 infinity loop <li>0++ specified
* loop<ul/>
* @param loopInterval [A-B] loop interval (S)
* @return {@link IPlayer} !setAB but does not play. You must call play(?) to play.
* @see #play()
* @see #play(Uri)
*/
P setABLoop(int loopMode, int loopInterval);
/**
* Set A-B internal call {@link #setAB(long, long)}, {@link #setABLoop(int, int)}
*
* <p /> *param loopMode,loopInterval can use {@link C#PARAM_ORIGINAL} keeping the original values
* <p /> *param loopMode,loopInterval can use {@link C#PARAM_UNSET}/{@link C#PARAM_RESET}
* unset/reset values
*
* @param startPos [A-B] start position (Ms)
* @param endPos [A-B] end position (Ms)
* @param loopMode [A-B] loop mode <ul> <li>-1 disable <li>-8 infinity loop <li>0++ specified
* loop<ul/>
* @param loopInterval [A-B] loop interval (S)
* @return {@link IPlayer} !setAB but does not play. You must call play(?) to play.
* @see #play()
* @see #play(Uri)
*/
P setAB(long startPos, long endPos, int loopMode, int loopInterval);
/**
* Set auto clear A-B all tag(when A-B finish) <p /> WARNING: If for special reasons cause A-B is
* not finish, will don't auto clear.
*
* @see #clearAB()
*/
P setClearAB(boolean autoClear);
/**
* Clear A-B all tag <p /> Tips: setClearAB(false) also don't manual invoke clearAB(), will save
* all tag. invoke again play(?) continue play A-B for specified ab tag.
*
* @see #setClearAB(boolean)
*/
void clearAB();
// ============================@MediaQueue
/**
* set a new media queue for player
*
* @param mediaQueue {@link IMediaQueue}
*/
void setMediaQueue(IMediaQueue mediaQueue);
/**
* get a media queue, if not {@link #setMediaQueue(IMediaQueue)}, it return default media queue
*
* @return {@link IMediaQueue}
*/
IMediaQueue getMediaQueue();
// ============================@Listener
/**
* @param listener {@link Listener} <ul> <li>new {@link PlayerListener}( ) <li>custom implements
* {@link Listener} <ul/>
*/
void addListener(Listener listener);
/**
* @param listener param==null -> clear()
*/
void removeListener(Listener listener);
interface Listener extends IPlayerBase.Listener {
void onAdded();//Lifecycle
/**
* Some need long term stationed, can be add again when on removed.
*/
void onRemoved();//Lifecycle
/**
* @return intent != null
*/
boolean onIntent(Intent intent);
/**
* @param position current play position
* @param duration play duration
* @return whether someone was handled
* @see #setUpdatePlayProgressDelayMs(long)
*/
boolean onPlayProgress(long position, long duration);
/**
* WARNING: use position|posUnitIndex in {@link C#STATE_PROGRESS_POS_UNIT_FINISH}, remember to
* do the judgment(position>=0) | (posUnitIndex>=0)
*
* @param position current play position
* @param posUnitIndex current position unit index
* @param posUnitState <ul> <li>{@link C#STATE_PROGRESS_POS_UNIT_START} <li>{@link
* C#STATE_PROGRESS_POS_UNIT_MID} <li>{@link C#STATE_PROGRESS_POS_UNIT_END} <li>{@link
* C#STATE_PROGRESS_POS_UNIT_FINISH} <ul/>
* @see #setUpdatePlayProgressDelayMs(long)
*/
void onPositionUnitProgress(long position, int posUnitIndex, int posUnitState);
/**
* WARNING: use position,duration in {@link C#STATE_PROGRESS_AB_FINISH}, remember to do the
* judgment(position>=0 && duration>position)
*
* @param position current play ab position (position - abStartPosition)
* @param duration ab duration (abEndPosition - abStartPosition)
* @param abState <ul> <li>{@link C#STATE_PROGRESS_AB_START} <li>{@link C#STATE_PROGRESS_AB_MID}
* <li>{@link C#STATE_PROGRESS_AB_END} <li>{@link C#STATE_PROGRESS_AB_FINISH} <ul/>
* @see #setUpdatePlayProgressDelayMs(long)
*/
void onABProgress(long position, long duration, int abState);
/**
* Notification request(by PlayerService and Notifier maintain) <p>If you have a custom
* condition to control whether or not the request notification -> override</p>
* <pre>
* @Override
* public void onNotificationRequired(int order) {
* if (request conditions) {
* super.onNotificationRequired(order);
* } else {
* super.onNotificationRequired(0);
* }
* }
* </pre>
*
* @param order <ul> <li>0: stopNotification <li>1: startNotification <li>2:
* updateNotification<ul/>
*/
void onNotificationRequired(int order);
boolean onAudioFocusChange(int focusChange);
}
}