diff --git a/Classes/YTPlayerView.h b/Classes/YTPlayerView.h index acb55c7..f5e2946 100644 --- a/Classes/YTPlayerView.h +++ b/Classes/YTPlayerView.h @@ -66,7 +66,7 @@ typedef NS_ENUM(NSInteger, YTPlayerError) { * * @param playerView The YTPlayerView instance that has become ready. */ -- (void)playerViewDidBecomeReady:(YTPlayerView *)playerView; +- (void)playerViewDidBecomeReady:(nonnull YTPlayerView *)playerView; /** * Callback invoked when player state has changed, e.g. stopped or started playback. @@ -74,7 +74,7 @@ typedef NS_ENUM(NSInteger, YTPlayerError) { * @param playerView The YTPlayerView instance where playback state has changed. * @param state YTPlayerState designating the new playback state. */ -- (void)playerView:(YTPlayerView *)playerView didChangeToState:(YTPlayerState)state; +- (void)playerView:(nonnull YTPlayerView *)playerView didChangeToState:(YTPlayerState)state; /** * Callback invoked when playback quality has changed. @@ -82,7 +82,7 @@ typedef NS_ENUM(NSInteger, YTPlayerError) { * @param playerView The YTPlayerView instance where playback quality has changed. * @param quality YTPlaybackQuality designating the new playback quality. */ -- (void)playerView:(YTPlayerView *)playerView didChangeToQuality:(YTPlaybackQuality)quality; +- (void)playerView:(nonnull YTPlayerView *)playerView didChangeToQuality:(YTPlaybackQuality)quality; /** * Callback invoked when an error has occured. @@ -90,7 +90,7 @@ typedef NS_ENUM(NSInteger, YTPlayerError) { * @param playerView The YTPlayerView instance where the error has occurred. * @param error YTPlayerError containing the error state. */ -- (void)playerView:(YTPlayerView *)playerView receivedError:(YTPlayerError)error; +- (void)playerView:(nonnull YTPlayerView *)playerView receivedError:(YTPlayerError)error; /** * Callback invoked frequently when playBack is plaing. @@ -98,14 +98,14 @@ typedef NS_ENUM(NSInteger, YTPlayerError) { * @param playerView The YTPlayerView instance where the error has occurred. * @param playTime float containing curretn playback time. */ -- (void)playerView:(YTPlayerView *)playerView didPlayTime:(float)playTime; +- (void)playerView:(nonnull YTPlayerView *)playerView didPlayTime:(float)playTime; /** * Callback invoked when setting up the webview to allow custom colours so it fits in * with app color schemes. If a transparent view is required specify clearColor and * the code will handle the opacity etc. */ -- (UIColor *)playerViewPreferredWebViewBackgroundColor:(YTPlayerView *)playerView; +- (nonnull UIColor *)playerViewPreferredWebViewBackgroundColor:(nonnull YTPlayerView *)playerView; @end @@ -118,10 +118,10 @@ typedef NS_ENUM(NSInteger, YTPlayerError) { */ @interface YTPlayerView : UIView -@property(nonatomic, strong, readonly) UIWebView *webView; +@property(nonatomic, strong, nullable, readonly) UIWebView *webView; /** A delegate to be notified on playback events. */ -@property(nonatomic, weak) id delegate; +@property(nonatomic, weak, nullable) id delegate; /** * This method loads the player with the given video ID. @@ -135,7 +135,7 @@ typedef NS_ENUM(NSInteger, YTPlayerError) { * @param videoId The YouTube video ID of the video to load in the player view. * @return YES if player has been configured correctly, NO otherwise. */ -- (BOOL)loadWithVideoId:(NSString *)videoId; +- (BOOL)loadWithVideoId:(nonnull NSString *)videoId; /** * This method loads the player with the given playlist ID. @@ -150,7 +150,7 @@ typedef NS_ENUM(NSInteger, YTPlayerError) { * @param playlistId The YouTube playlist ID of the playlist to load in the player view. * @return YES if player has been configured correctly, NO otherwise. */ -- (BOOL)loadWithPlaylistId:(NSString *)playlistId; +- (BOOL)loadWithPlaylistId:(nonnull NSString *)playlistId; /** * This method loads the player with the given video ID and player variables. Player variables @@ -173,7 +173,7 @@ typedef NS_ENUM(NSInteger, YTPlayerError) { * @param playerVars An NSDictionary of player parameters. * @return YES if player has been configured correctly, NO otherwise. */ -- (BOOL)loadWithVideoId:(NSString *)videoId playerVars:(NSDictionary *)playerVars; +- (BOOL)loadWithVideoId:(nonnull NSString *)videoId playerVars:(nullable NSDictionary *)playerVars; /** * This method loads the player with the given playlist ID and player variables. Player variables @@ -197,7 +197,7 @@ typedef NS_ENUM(NSInteger, YTPlayerError) { * @param playerVars An NSDictionary of player parameters. * @return YES if player has been configured correctly, NO otherwise. */ -- (BOOL)loadWithPlaylistId:(NSString *)playlistId playerVars:(NSDictionary *)playerVars; +- (BOOL)loadWithPlaylistId:(nonnull NSString *)playlistId playerVars:(nullable NSDictionary *)playerVars; /** * This method loads an iframe player with the given player parameters. Usually you may want to use @@ -210,7 +210,7 @@ typedef NS_ENUM(NSInteger, YTPlayerError) { * whether a single video or playlist is being loaded. * @return YES if successful, NO if not. */ -- (BOOL)loadWithPlayerParams:(NSDictionary *)additionalPlayerParams; +- (BOOL)loadWithPlayerParams:(nullable NSDictionary *)additionalPlayerParams; #pragma mark - Player controls @@ -272,7 +272,7 @@ typedef NS_ENUM(NSInteger, YTPlayerError) { * @param startSeconds Time in seconds to start the video when YTPlayerView::playVideo is called. * @param suggestedQuality YTPlaybackQuality value suggesting a playback quality. */ -- (void)cueVideoById:(NSString *)videoId +- (void)cueVideoById:(nonnull NSString *)videoId startSeconds:(float)startSeconds suggestedQuality:(YTPlaybackQuality)suggestedQuality; @@ -287,7 +287,7 @@ typedef NS_ENUM(NSInteger, YTPlayerError) { * @param endSeconds Time in seconds to end the video after it begins playing. * @param suggestedQuality YTPlaybackQuality value suggesting a playback quality. */ -- (void)cueVideoById:(NSString *)videoId +- (void)cueVideoById:(nonnull NSString *)videoId startSeconds:(float)startSeconds endSeconds:(float)endSeconds suggestedQuality:(YTPlaybackQuality)suggestedQuality; @@ -302,7 +302,7 @@ typedef NS_ENUM(NSInteger, YTPlayerError) { * @param startSeconds Time in seconds to start the video when it has loaded. * @param suggestedQuality YTPlaybackQuality value suggesting a playback quality. */ -- (void)loadVideoById:(NSString *)videoId +- (void)loadVideoById:(nonnull NSString *)videoId startSeconds:(float)startSeconds suggestedQuality:(YTPlaybackQuality)suggestedQuality; @@ -317,7 +317,7 @@ typedef NS_ENUM(NSInteger, YTPlayerError) { * @param endSeconds Time in seconds to end the video after it begins playing. * @param suggestedQuality YTPlaybackQuality value suggesting a playback quality. */ -- (void)loadVideoById:(NSString *)videoId +- (void)loadVideoById:(nonnull NSString *)videoId startSeconds:(float)startSeconds endSeconds:(float)endSeconds suggestedQuality:(YTPlaybackQuality)suggestedQuality; @@ -332,7 +332,7 @@ typedef NS_ENUM(NSInteger, YTPlayerError) { * @param startSeconds Time in seconds to start the video when YTPlayerView::playVideo is called. * @param suggestedQuality YTPlaybackQuality value suggesting a playback quality. */ -- (void)cueVideoByURL:(NSString *)videoURL +- (void)cueVideoByURL:(nonnull NSString *)videoURL startSeconds:(float)startSeconds suggestedQuality:(YTPlaybackQuality)suggestedQuality; @@ -347,7 +347,7 @@ typedef NS_ENUM(NSInteger, YTPlayerError) { * @param endSeconds Time in seconds to end the video after it begins playing. * @param suggestedQuality YTPlaybackQuality value suggesting a playback quality. */ -- (void)cueVideoByURL:(NSString *)videoURL +- (void)cueVideoByURL:(nonnull NSString *)videoURL startSeconds:(float)startSeconds endSeconds:(float)endSeconds suggestedQuality:(YTPlaybackQuality)suggestedQuality; @@ -362,7 +362,7 @@ typedef NS_ENUM(NSInteger, YTPlayerError) { * @param startSeconds Time in seconds to start the video when it has loaded. * @param suggestedQuality YTPlaybackQuality value suggesting a playback quality. */ -- (void)loadVideoByURL:(NSString *)videoURL +- (void)loadVideoByURL:(nonnull NSString *)videoURL startSeconds:(float)startSeconds suggestedQuality:(YTPlaybackQuality)suggestedQuality; @@ -377,7 +377,7 @@ typedef NS_ENUM(NSInteger, YTPlayerError) { * @param endSeconds Time in seconds to end the video after it begins playing. * @param suggestedQuality YTPlaybackQuality value suggesting a playback quality. */ -- (void)loadVideoByURL:(NSString *)videoURL +- (void)loadVideoByURL:(nonnull NSString *)videoURL startSeconds:(float)startSeconds endSeconds:(float)endSeconds suggestedQuality:(YTPlaybackQuality)suggestedQuality; @@ -400,7 +400,7 @@ typedef NS_ENUM(NSInteger, YTPlayerError) { * @param startSeconds Time in seconds to start the video when YTPlayerView::playVideo is called. * @param suggestedQuality YTPlaybackQuality value suggesting a playback quality. */ -- (void)cuePlaylistByPlaylistId:(NSString *)playlistId +- (void)cuePlaylistByPlaylistId:(nonnull NSString *)playlistId index:(int)index startSeconds:(float)startSeconds suggestedQuality:(YTPlaybackQuality)suggestedQuality; @@ -417,7 +417,7 @@ typedef NS_ENUM(NSInteger, YTPlayerError) { * @param startSeconds Time in seconds to start the video when YTPlayerView::playVideo is called. * @param suggestedQuality YTPlaybackQuality value suggesting a playback quality. */ -- (void)cuePlaylistByVideos:(NSArray *)videoIds +- (void)cuePlaylistByVideos:(nonnull NSArray *)videoIds index:(int)index startSeconds:(float)startSeconds suggestedQuality:(YTPlaybackQuality)suggestedQuality; @@ -434,7 +434,7 @@ typedef NS_ENUM(NSInteger, YTPlayerError) { * @param startSeconds Time in seconds to start the video when YTPlayerView::playVideo is called. * @param suggestedQuality YTPlaybackQuality value suggesting a playback quality. */ -- (void)loadPlaylistByPlaylistId:(NSString *)playlistId +- (void)loadPlaylistByPlaylistId:(nonnull NSString *)playlistId index:(int)index startSeconds:(float)startSeconds suggestedQuality:(YTPlaybackQuality)suggestedQuality; @@ -451,7 +451,7 @@ typedef NS_ENUM(NSInteger, YTPlayerError) { * @param startSeconds Time in seconds to start the video when YTPlayerView::playVideo is called. * @param suggestedQuality YTPlaybackQuality value suggesting a playback quality. */ -- (void)loadPlaylistByVideos:(NSArray *)videoIds +- (void)loadPlaylistByVideos:(nonnull NSArray *)videoIds index:(int)index startSeconds:(float)startSeconds suggestedQuality:(YTPlaybackQuality)suggestedQuality; @@ -519,7 +519,7 @@ typedef NS_ENUM(NSInteger, YTPlayerError) { * * @return An NSArray containing available playback rates. nil if there is an error. */ -- (NSArray *)availablePlaybackRates; +- (nullable NSArray *)availablePlaybackRates; #pragma mark - Setting playback behavior for playlists @@ -606,9 +606,9 @@ typedef NS_ENUM(NSInteger, YTPlayerError) { * JavaScript API defined here: * https://developers.google.com/youtube/iframe_api_reference#getAvailableQualityLevels * - * @return An NSArray containing available playback quality levels. + * @return An NSArray containing available playback quality levels. Returns nil if there is an error. */ -- (NSArray *)availableQualityLevels; +- (nullable NSArray *)availableQualityLevels; #pragma mark - Retrieving video information @@ -630,18 +630,18 @@ typedef NS_ENUM(NSInteger, YTPlayerError) { * to the JavaScript API defined here: * https://developers.google.com/youtube/iframe_api_reference#getVideoUrl * - * @return The YouTube.com URL for the video. + * @return The YouTube.com URL for the video. Returns nil if no video is loaded yet. */ -- (NSURL *)videoUrl; +- (nullable NSURL *)videoUrl; /** * Returns the embed code for the current video. This method corresponds * to the JavaScript API defined here: * https://developers.google.com/youtube/iframe_api_reference#getVideoEmbedCode * - * @return The embed code for the current video. + * @return The embed code for the current video. Returns nil if no video is loaded yet. */ -- (NSString *)videoEmbedCode; +- (nullable NSString *)videoEmbedCode; #pragma mark - Retrieving playlist information @@ -656,7 +656,7 @@ typedef NS_ENUM(NSInteger, YTPlayerError) { * * @return An NSArray containing all the video IDs in the current playlist. |nil| on error. */ -- (NSArray *)playlist; +- (nullable NSArray *)playlist; /** * Returns the 0-based index of the currently playing item in the playlist. diff --git a/Classes/YTPlayerView.m b/Classes/YTPlayerView.m index 31a9f08..0e1ba87 100644 --- a/Classes/YTPlayerView.m +++ b/Classes/YTPlayerView.m @@ -90,7 +90,9 @@ - (BOOL)loadWithPlaylistId:(NSString *)playlistId playerVars:(NSDictionary *)pla NSMutableDictionary *tempPlayerVars = [[NSMutableDictionary alloc] init]; [tempPlayerVars setValue:@"playlist" forKey:@"listType"]; [tempPlayerVars setValue:playlistId forKey:@"list"]; - [tempPlayerVars addEntriesFromDictionary:playerVars]; // No-op if playerVars is null + if (playerVars) { + [tempPlayerVars addEntriesFromDictionary:playerVars]; + } NSDictionary *playerParams = @{ @"playerVars" : tempPlayerVars }; return [self loadWithPlayerParams:playerParams]; @@ -653,7 +655,9 @@ - (BOOL)loadWithPlayerParams:(NSDictionary *)additionalPlayerParams { @"onError" : @"onPlayerError" }; NSMutableDictionary *playerParams = [[NSMutableDictionary alloc] init]; - [playerParams addEntriesFromDictionary:additionalPlayerParams]; + if (additionalPlayerParams) { + [playerParams addEntriesFromDictionary:additionalPlayerParams]; + } if (![playerParams objectForKey:@"height"]) { [playerParams setValue:@"100%" forKey:@"height"]; }