-
Notifications
You must be signed in to change notification settings - Fork 377
/
Copy pathVKVideoPlayer.h
164 lines (127 loc) · 6.25 KB
/
VKVideoPlayer.h
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
//
// Created by Viki.
// Copyright (c) 2014 Viki Inc. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "VKVideoPlayerView.h"
#import "VKVideoPlayerCaption.h"
#import "VKVideoPlayerTrack.h"
typedef enum {
// The video was flagged as blocked due to licensing restrictions (geo or device).
kVideoPlayerErrorVideoBlocked = 900,
// There was an error fetching the stream.
kVideoPlayerErrorFetchStreamError,
// Could not find the stream type for video.
kVideoPlayerErrorStreamNotFound,
// There was an error loading the video as an asset.
kVideoPlayerErrorAssetLoadError,
// There was an error loading the video's duration.
kVideoPlayerErrorDurationLoadError,
// AVPlayer failed to load the asset.
kVideoPlayerErrorAVPlayerFail,
// AVPlayerItem failed to load the asset.
kVideoPlayerErrorAVPlayerItemFail,
// Chromecast failed to load the stream.
kVideoPlayerErrorChromecastLoadFail,
// There was an unknown error.
kVideoPlayerErrorUnknown,
} VKVideoPlayerErrorCode;
typedef enum {
VKVideoPlayerStateUnknown,
VKVideoPlayerStateContentLoading,
VKVideoPlayerStateContentPlaying,
VKVideoPlayerStateContentPaused,
VKVideoPlayerStateSuspend,
VKVideoPlayerStateDismissed,
VKVideoPlayerStateError
} VKVideoPlayerState;
typedef enum {
VKVideoPlayerControlEventTapPlayerView,
VKVideoPlayerControlEventTapNext,
VKVideoPlayerControlEventTapPrevious,
VKVideoPlayerControlEventTapDone,
VKVideoPlayerControlEventTapFullScreen,
VKVideoPlayerControlEventTapCaption,
VKVideoPlayerControlEventTapVideoQuality,
VKVideoPlayerControlEventSwipeNext,
VKVideoPlayerControlEventSwipePrevious,
} VKVideoPlayerControlEvent;
@class VKVideoPlayer;
@protocol VKVideoPlayerDelegate <NSObject>
@optional
- (BOOL)shouldVideoPlayer:(VKVideoPlayer*)videoPlayer changeStateTo:(VKVideoPlayerState)toState;
- (void)videoPlayer:(VKVideoPlayer*)videoPlayer willChangeStateTo:(VKVideoPlayerState)toState;
- (void)videoPlayer:(VKVideoPlayer*)videoPlayer didChangeStateFrom:(VKVideoPlayerState)fromState;
- (BOOL)shouldVideoPlayer:(VKVideoPlayer*)videoPlayer startVideo:(id<VKVideoPlayerTrackProtocol>)track;
- (void)videoPlayer:(VKVideoPlayer*)videoPlayer willStartVideo:(id<VKVideoPlayerTrackProtocol>)track;
- (void)videoPlayer:(VKVideoPlayer*)videoPlayer didStartVideo:(id<VKVideoPlayerTrackProtocol>)track;
- (void)videoPlayer:(VKVideoPlayer*)videoPlayer didPlayFrame:(id<VKVideoPlayerTrackProtocol>)track time:(NSTimeInterval)time lastTime:(NSTimeInterval)lastTime;
- (void)videoPlayer:(VKVideoPlayer*)videoPlayer didPlayToEnd:(id<VKVideoPlayerTrackProtocol>)track;
- (void)videoPlayer:(VKVideoPlayer*)videoPlayer didControlByEvent:(VKVideoPlayerControlEvent)event;
- (void)videoPlayer:(VKVideoPlayer*)videoPlayer didChangeSubtitleFrom:(NSString*)fronLang to:(NSString*)toLang;
- (void)videoPlayer:(VKVideoPlayer*)videoPlayer willChangeOrientationTo:(UIInterfaceOrientation)orientation;
- (void)videoPlayer:(VKVideoPlayer*)videoPlayer didChangeOrientationFrom:(UIInterfaceOrientation)orientation;
- (void)handleErrorCode:(VKVideoPlayerErrorCode)errorCode track:(id<VKVideoPlayerTrackProtocol>)track customMessage:(NSString*)customMessage;
@end
@protocol VKVideoPlayerExternalMonitorProtocol;
@protocol VKPlayer <NSObject>
- (void)play;
- (void)pause;
- (CMTime)currentCMTime;
- (NSTimeInterval)currentItemDuration;
- (void)seekToTimeInSeconds:(float)time completionHandler:(void (^)(BOOL finished))completionHandler;
@end
@interface AVPlayer (VKPlayer)
- (void)seekToTimeInSeconds:(float)time completionHandler:(void (^)(BOOL finished))completionHandler;
- (NSTimeInterval)currentItemDuration;
- (CMTime)currentCMTime;
@end
@interface VKVideoPlayer : NSObject<
VKVideoPlayerViewDelegate
>
@property (nonatomic, strong) VKVideoPlayerView *view;
@property (nonatomic, strong) id<VKVideoPlayerTrackProtocol> track;
@property (nonatomic, weak) id<VKVideoPlayerDelegate> delegate;
@property (nonatomic, assign) VKVideoPlayerState state;
@property (nonatomic, strong) AVPlayer *avPlayer;
@property (nonatomic, strong) AVPlayerItem* playerItem;
@property (nonatomic, assign) BOOL playerControlsEnabled;
@property (nonatomic, strong) id<VKPlayer> player;
@property (nonatomic, assign) UIInterfaceOrientation visibleInterfaceOrientation;
@property (nonatomic, assign) UIInterfaceOrientationMask supportedOrientations;
@property (nonatomic, assign) BOOL isFullScreen;
@property (nonatomic, strong) id<VKVideoPlayerExternalMonitorProtocol> externalMonitor;
@property (nonatomic, strong, readonly) NSURL* streamURL;
@property (nonatomic, strong) NSString* defaultStreamKey;
@property (nonatomic, assign) CGRect portraitFrame;
@property (nonatomic, assign) CGRect landscapeFrame;
@property (nonatomic, assign) BOOL forceRotate;
- (id)initWithVideoPlayerView:(VKVideoPlayerView*)videoPlayerView;
- (void)seekToLastWatchedDuration;
- (void)seekToTimeInSecond:(float)sec userAction:(BOOL)isUserAction completionHandler:(void (^)(BOOL finished))completionHandler;
- (BOOL)isPlayingVideo;
- (BOOL)isPlayingOnExternalDevice;
- (NSTimeInterval)currentTime;
- (void)performOrientationChange:(UIInterfaceOrientation)deviceOrientation;
#pragma mark - Error Handling
- (NSString*)videoPlayerErrorCodeToString:(VKVideoPlayerErrorCode)code;
#pragma mark - Resource
- (void)loadVideoWithTrack:(id<VKVideoPlayerTrackProtocol>)track;
- (void)loadVideoWithStreamURL:(NSURL*)streamURL;
- (void)reloadCurrentVideoTrack;
- (VKVideoPlayerView*)activePlayerView;
#pragma mark - Controls
- (void)playContent;
- (void)pauseContent;
- (void)pauseContentWithCompletionHandler:(void (^)())completionHandler;
- (void)pauseContent:(BOOL)isUserAction completionHandler:(void (^)())completionHandler;
- (void)updateTrackControls;
#pragma mark - Captions
- (void)clearCaptions;
- (void)setCaptionToBottom:(id<VKVideoPlayerCaptionProtocol>)caption;
- (void)setCaptionToBottom:(id<VKVideoPlayerCaptionProtocol>)caption playerView:(VKVideoPlayerView*)playerView;
- (void)setCaptionToTop:(id<VKVideoPlayerCaptionProtocol>)caption;
- (void)setCaptionToTop:(id<VKVideoPlayerCaptionProtocol>)caption playerView:(VKVideoPlayerView*)playerView;
- (void)updateCaptionView:(DTAttributedLabel*)captionView caption:(id<VKVideoPlayerCaptionProtocol>)caption playerView:(VKVideoPlayerView*)playerView;
- (void)clearCaptionView:(DTAttributedLabel*)captionView;
@end