Skip to content

Commit

Permalink
Added nullability specifiers to public interface
Browse files Browse the repository at this point in the history
For better usability in Swift.

And also added nil check before -addEntriesFromDictionary: because it takes nonnull NSDictionary * as a parameter (though looks like it works if you pass nil to it...)
  • Loading branch information
Ono Masashi committed Dec 14, 2015
1 parent f1b6d00 commit 9525d2f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 35 deletions.
66 changes: 33 additions & 33 deletions Classes/YTPlayerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,46 +66,46 @@ 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.
*
* @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.
*
* @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.
*
* @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.
*
* @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

Expand All @@ -118,10 +118,10 @@ typedef NS_ENUM(NSInteger, YTPlayerError) {
*/
@interface YTPlayerView : UIView<UIWebViewDelegate>

@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<YTPlayerViewDelegate> delegate;
@property(nonatomic, weak, nullable) id<YTPlayerViewDelegate> delegate;

/**
* This method loads the player with the given video ID.
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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;

Expand All @@ -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;
Expand All @@ -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;

Expand All @@ -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;
Expand All @@ -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;

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions Classes/YTPlayerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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"];
}
Expand Down

0 comments on commit 9525d2f

Please sign in to comment.