Skip to content

Commit

Permalink
Add Console warning for unrecommended early method calls
Browse files Browse the repository at this point in the history
 - Also update deprecated player event names
  • Loading branch information
dharFr committed Mar 30, 2016
1 parent abae628 commit 5e1e96d
Showing 1 changed file with 42 additions and 8 deletions.
50 changes: 42 additions & 8 deletions dailymotion-player-objc/DMPlayerViewController.m
Expand Up @@ -15,6 +15,7 @@ @interface DMPlayerViewController () <UIAlertViewDelegate>
@property (nonatomic, readwrite) BOOL seeking;
@property (nonatomic, readwrite) BOOL paused;
@property (nonatomic, readwrite) BOOL ended;
@property (nonatomic, readwrite) BOOL started;
@property (nonatomic, readwrite) NSError *error;
@property (nonatomic, assign) BOOL inited;
@property (nonatomic, strong) NSDictionary *params;
Expand All @@ -35,21 +36,23 @@ - (void)dealloc {
}

- (void)setup {
// See https://developer.dailymotion.com/player#player-parameters for available parameters
_params = @{};

_autoplay = [self.params[@"autoplay"] boolValue];
_currentTime = 0;
_bufferedTime = 0;
_duration = NAN;
_seeking = false;
_seeking = NO;
_error = nil;
_ended = false;
_muted = false;
_started = NO;
_ended = NO;
_muted = NO;
_volume = 1;
_paused = true;
_fullscreen = false;
_fullscreen = NO;
_webBaseURLString = @"http://www.dailymotion.com";
_autoOpenExternalURLs = false;
_autoOpenExternalURLs = NO;
}

- (void)awakeFromNib {
Expand Down Expand Up @@ -185,10 +188,13 @@ - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)
else if ([eventName isEqualToString:@"play"] || [eventName isEqualToString:@"playing"]) {
self.paused = NO;
}
else if ([eventName isEqualToString:@"ended"]) {
else if ([eventName isEqualToString:@"start"]) {
self.started = YES;
}
else if ([eventName isEqualToString:@"end"]) {
self.ended = YES;
}
else if ([eventName isEqualToString:@"ended"] || [eventName isEqualToString:@"pause"]) {
else if ([eventName isEqualToString:@"end"] || [eventName isEqualToString:@"pause"]) {
self.paused = YES;
}
else if ([eventName isEqualToString:@"seeking"]) {
Expand Down Expand Up @@ -276,6 +282,12 @@ - (void)loadVideo:(NSString *)videoId withParams:(NSDictionary *)params {
- (void)api:(NSString *)method arg:(NSString *)arg {
if (!self.inited) return;
if (!method) return;

NSString *warnMessage = [self APIReadyWarnMessageForMethod:method];
if (!self.started && warnMessage) {
NSLog(@"%@", warnMessage);
}

UIWebView *webview = (UIWebView *)self.view;
NSString *jsMethod = [NSString stringWithFormat:@"\"%@\"", method];
NSString *jsArg = arg ? [NSString stringWithFormat:@"\"%@\"", [arg stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""]] : @"null";
Expand All @@ -286,6 +298,28 @@ - (void)api:(NSString *)method {
[self api:method arg:nil];
}

- (NSString *) APIReadyWarnMessageForMethod:(NSString *)method {

NSString * param = @{
@"play" : @"autoplay",
@"toggle-play" : @"autoplay",
@"seek" : @"start",
@"quality" : @"quality",
@"muted" : @"muted",
@"toggle-muted" : @"muted"
}[method];

if (param) {
return [NSString stringWithFormat:@"Warning [DMPlayerViewController]: \n"
"\tCalling `%@` method right after `apiready` event is not recommended.\n"
"\tAre you sure you don\'t want to use the `%@` parameter instead?\n"
"\tFor more information, see: https://developer.dailymotion.com/player#player-parameters", method, param];
}
else {
return nil;
}
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
Expand Down

0 comments on commit 5e1e96d

Please sign in to comment.