Shaka Player Embedded
ShakaPlayer.h
Go to the documentation of this file.
1 // Copyright 2018 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef SHAKA_EMBEDDED_SHAKA_PLAYER_H_
16 #define SHAKA_EMBEDDED_SHAKA_PLAYER_H_
17 
18 #import <AVFoundation/AVFoundation.h>
19 #import <Foundation/Foundation.h>
20 
21 #include "error_objc.h"
22 #include "macros.h"
23 #include "manifest_objc.h"
24 #include "net_objc.h"
25 #include "player_externs_objc.h"
26 #include "stats_objc.h"
27 #include "track_objc.h"
28 
34 @class ShakaPlayer;
35 
36 typedef void (^ShakaPlayerAsyncBlock)(ShakaPlayerError * _Nullable);
37 
38 typedef NS_ENUM(NSInteger, ShakaPlayerLogLevel) {
39  // These have the same values as shaka.log.Level.
40  ShakaPlayerLogLevelNone = 0,
41  ShakaPlayerLogLevelError = 1,
42  ShakaPlayerLogLevelWarning = 2,
43  ShakaPlayerLogLevelInfo = 3,
44  ShakaPlayerLogLevelDebug = 4,
45  ShakaPlayerLogLevelV1 = 5,
46  ShakaPlayerLogLevelV2 = 6
47 };
48 
49 
50 NS_ASSUME_NONNULL_BEGIN
51 
61 NSString *ShakaPlayerLicenseServerConfig(const NSString *key_system);
62 
72 NSString *ShakaPlayerAdvancedDrmConfig(const NSString *key_system, const NSString *config);
73 
74 
79 @protocol ShakaPlayerClient <NSObject>
80 
81 @optional
82 
87 - (void)onPlayer:(ShakaPlayer *)player error:(ShakaPlayerError *)error;
88 
92 - (void)onPlayer:(ShakaPlayer *)player bufferingChange:(BOOL)is_buffering;
93 
94 
98 - (void)onPlayerPlayingEvent:(ShakaPlayer *)player;
99 
103 - (void)onPlayerPauseEvent:(ShakaPlayer *)player;
104 
108 - (void)onPlayerEndedEvent:(ShakaPlayer *)player;
109 
110 
115 - (void)onPlayerSeekingEvent:(ShakaPlayer *)player;
116 
121 - (void)onPlayerSeekedEvent:(ShakaPlayer *)player;
122 
124 - (void)onPlayerAttachMse:(ShakaPlayer *)player;
125 
130 - (void)onPlayerAttachSource:(ShakaPlayer *)player;
131 
135 - (void)onPlayerDetach:(ShakaPlayer *)player;
136 
137 @end
138 
139 
144 @protocol ShakaPlayerNetworkFilter <NSObject>
145 
146 @optional
147 
156 - (void)onPlayer:(ShakaPlayer *)player
157  networkRequest:(ShakaPlayerRequest *)request
158  ofType:(ShakaPlayerRequestType)type
159  withBlock:(ShakaPlayerAsyncBlock)block;
160 
169 - (void)onPlayer:(ShakaPlayer *)player
170  networkResponse:(ShakaPlayerResponse*)response
171  ofType:(ShakaPlayerRequestType)type
172  withBlock:(ShakaPlayerAsyncBlock)block;
173 
174 @end
175 
176 
179 @interface ShakaPlayerUiInfo : NSObject
180 
182 @property(atomic) BOOL paused;
183 
185 @property(atomic) BOOL ended;
186 
188 @property(atomic) BOOL seeking;
189 
191 @property(atomic) double duration;
192 
194 @property(atomic) double playbackRate;
195 
197 @property(atomic) double currentTime;
198 
200 @property(atomic) double volume;
201 
203 @property(atomic) BOOL muted;
204 
206 @property(atomic) BOOL isAudioOnly;
207 
209 @property(atomic) BOOL isLive;
210 
212 @property(atomic) BOOL closedCaptions;
213 
215 @property(atomic) ShakaBufferedRange *seekRange;
216 
218 @property(atomic) ShakaBufferedInfo *bufferedInfo;
219 
220 @end
221 
222 
229 @interface ShakaPlayer : NSObject
230 
231 - (instancetype)init NS_UNAVAILABLE; // initWithError: should always be used
232 
237 - (nullable instancetype)initWithError:(NSError * _Nullable __autoreleasing * _Nullable)error NS_SWIFT_NAME(init());
238 
239 
241 @property (atomic, weak, nullable) id<ShakaPlayerClient> client;
242 
244 - (void)play;
245 
247 - (void)pause;
248 
250 @property(atomic, readonly) BOOL paused;
251 
253 @property(atomic, readonly) BOOL ended;
254 
256 @property(atomic, readonly) BOOL seeking;
257 
259 @property(atomic, readonly) double duration;
260 
262 @property(atomic) double playbackRate;
263 
265 @property(atomic) double currentTime;
266 
268 @property(atomic) double volume;
269 
271 @property(atomic) BOOL muted;
272 
273 
278 @property(atomic) ShakaPlayerLogLevel logLevel;
279 
281 @property(atomic, readonly, nullable) NSString *playerVersion;
282 
284 @property(atomic, readonly) BOOL isAudioOnly;
285 
287 @property(atomic, readonly) BOOL isLive;
288 
290 @property(atomic) BOOL closedCaptions;
291 
293 @property(atomic, readonly) NSArray<ShakaLanguageRole *> *audioLanguagesAndRoles;
294 
296 @property(atomic, readonly) NSArray<ShakaLanguageRole *> *textLanguagesAndRoles;
297 
303 @property(atomic, readonly, nullable) AVPlayer *avPlayer;
304 
305 
310 - (void)getUiInfoWithBlock:(void (^)(ShakaPlayerUiInfo *))block;
311 
313 - (ShakaStats *)getStats;
314 
320 - (NSArray<ShakaTrack *> *)getTextTracks;
321 
327 - (NSArray<ShakaTrack *> *)getVariantTracks;
328 
335 - (void)load:(NSString *)uri withBlock:(ShakaPlayerAsyncBlock)block;
336 
344 - (void)load:(NSString *)uri
345 withStartTime:(double)startTime
346  andBlock:(ShakaPlayerAsyncBlock)block;
347 
349 - (void)unloadWithBlock:(ShakaPlayerAsyncBlock)block;
350 
351 
360 - (void)configure:(const NSString *)namePath withBool:(BOOL)value;
361 
370 - (void)configure:(const NSString *)namePath withDouble:(double)value;
371 
380 - (void)configure:(const NSString *)namePath withString:(const NSString *)value;
381 
390 - (void)configure:(const NSString *)namePath withData:(NSData *)value;
391 
399 - (void)configureWithDefault:(const NSString *)namePath;
400 
408 - (BOOL)getConfigurationBool:(const NSString *)namePath;
409 
417 - (double)getConfigurationDouble:(const NSString *)namePath;
418 
426 - (nullable NSString *)getConfigurationString:(const NSString *)namePath;
427 
428 
433 - (void)selectAudioLanguage:(NSString *)language withRole:(nullable NSString *)role;
434 
439 - (void)selectAudioLanguage:(NSString *)language;
440 
445 - (void)selectTextLanguage:(NSString *)language withRole:(nullable NSString *)role;
446 
451 - (void)selectTextLanguage:(NSString *)language;
452 
457 - (void)selectTextTrack:(const ShakaTrack *)track;
458 
463 - (void)selectVariantTrack:(const ShakaTrack *)track;
464 
469 - (void)selectVariantTrack:(const ShakaTrack *)track withClearBuffer:(BOOL)clear;
470 
475 - (void)destroy;
476 
477 
479 
486 - (void)addTextTrack:(NSString *)uri
487  language:(NSString *)lang
488  kind:(NSString *)kind
489  mime:(NSString *)mime;
490 - (void)addTextTrack:(NSString *)uri
491  language:(NSString *)lang
492  kind:(NSString *)kind
493  mime:(NSString *)mime
494  codec:(nullable NSString *)codec;
495 - (void)addTextTrack:(NSString *)uri
496  language:(NSString *)lang
497  kind:(NSString *)kind
498  mime:(NSString *)mime
499  codec:(nullable NSString *)codec
500  label:(nullable NSString *)label;
502 
507 - (void)addNetworkFilter:(id<ShakaPlayerNetworkFilter>)filter;
508 
510 - (void)removeNetworkFilter:(id<ShakaPlayerNetworkFilter>)filter;
511 
512 @end
513 
516 NS_ASSUME_NONNULL_END
517 #endif // SHAKA_EMBEDDED_SHAKA_PLAYER_H_
ShakaBufferedInfo * bufferedInfo
Definition: ShakaPlayer.h:218
#define SHAKA_EXPORT
Definition: macros.h:30
NSArray< ShakaLanguageRole * > * audioLanguagesAndRoles
Definition: ShakaPlayer.h:293
NSArray< ShakaLanguageRole * > * textLanguagesAndRoles
Definition: ShakaPlayer.h:296
void(^ ShakaPlayerAsyncBlock)(ShakaPlayerError *_Nullable)
Definition: ShakaPlayer.h:36
id< ShakaPlayerClient > client
Definition: ShakaPlayer.h:241
ShakaPlayerLogLevel logLevel
Definition: ShakaPlayer.h:278
NSArray< ShakaTrack * > * getTextTracks()
Definition: ShakaPlayer.mm:457
NSString * ShakaPlayerAdvancedDrmConfig(const NSString *key_system, const NSString *config)
Definition: ShakaPlayer.mm:214
NS_ASSUME_NONNULL_BEGIN NSString * ShakaPlayerLicenseServerConfig(const NSString *key_system)
Definition: ShakaPlayer.mm:209
NSArray< ShakaTrack * > * getVariantTracks()
Definition: ShakaPlayer.mm:465
typedef NS_ENUM(NSInteger, ShakaPlayerLogLevel)
Definition: ShakaPlayer.h:38
ShakaBufferedRange * seekRange
Definition: ShakaPlayer.h:215
NSString * playerVersion
Definition: ShakaPlayer.h:281
ShakaStats * getStats()
Definition: ShakaPlayer.mm:447
AVPlayer * avPlayer
Definition: ShakaPlayer.h:303
instancetype NS_UNAVAILABLE()