diff --git a/PlayerSDK/PlayerViewController.m b/PlayerSDK/PlayerViewController.m index 39625b02..1c299c64 100644 --- a/PlayerSDK/PlayerViewController.m +++ b/PlayerSDK/PlayerViewController.m @@ -14,8 +14,8 @@ #import "KPEventListener.h" #if !(TARGET_IPHONE_SIMULATOR) - #import "WVSettings.h" - #import "WViPhoneAPI.h" +#import "WVSettings.h" +#import "WViPhoneAPI.h" #endif @implementation PlayerViewController { @@ -30,6 +30,9 @@ @implementation PlayerViewController { BOOL openFullScreen; UIButton *btn; BOOL isCloseFullScreenByTap; + // AirPlay Params + MPVolumeView *volumeView; + NSArray *prevAirPlayBtnPositionArr; BOOL isJsCallbackReady; NSMutableDictionary *kPlayerEventsDict; @@ -49,9 +52,9 @@ @implementation PlayerViewController { - (void)viewDidLoad { NSLog(@"View Did Load Enter"); - #if !(TARGET_IPHONE_SIMULATOR) - [self initWideVineParams]; - #endif +#if !(TARGET_IPHONE_SIMULATOR) + [self initWideVineParams]; +#endif [self initPlayerParams]; appConfigDict = [NSDictionary dictionaryWithContentsOfFile: [ [NSBundle mainBundle] pathForResource: @"AppConfigurations" ofType: @"plist"]]; @@ -149,11 +152,11 @@ - (void)play { isPlayCalled = YES; - #if !(TARGET_IPHONE_SIMULATOR) - if ( isWideVine && !isWideVineReady ) { - return; - } - #endif +#if !(TARGET_IPHONE_SIMULATOR) + if ( isWideVine && !isWideVineReady ) { + return; + } +#endif if( !( self.player.playbackState == MPMoviePlaybackStatePlaying ) ) { [self.player prepareToPlay]; @@ -182,14 +185,14 @@ - (void)stop { isPlaying = NO; isPlayCalled = NO; - #if !(TARGET_IPHONE_SIMULATOR) - // Stop WideVine - if ( isWideVine ) { - [wvSettings stopWV]; - isWideVine = NO; - isWideVineReady = NO; - } - #endif +#if !(TARGET_IPHONE_SIMULATOR) + // Stop WideVine + if ( isWideVine ) { + [wvSettings stopWV]; + isWideVine = NO; + isWideVineReady = NO; + } +#endif NSLog(@"Stop Player Exit"); } @@ -455,7 +458,7 @@ - (void)openFullScreen: (BOOL)openFullscreen{ NSLog( @"openFullScreen Enter" ); isFullScreen = YES; - + CGRect mainFrame; openFullScreen = openFullscreen; @@ -509,7 +512,7 @@ - (void)closeFullScreen{ self.webView.frame = self.player.view.frame; if ( ![self isIOS7] ) { - [UIApplication sharedApplication].statusBarHidden = NO; + [UIApplication sharedApplication].statusBarHidden = NO; } [self triggerEventsJavaScript:@"exitfullscreen" WithValue:nil]; @@ -713,7 +716,7 @@ - (void)setAttribute: (NSArray*)args{ attributeVal = [args objectAtIndex:1]; [self visible: attributeVal]; break; - #if !(TARGET_IPHONE_SIMULATOR) +#if !(TARGET_IPHONE_SIMULATOR) case wvServerKey: wvSettings = [[WVSettings alloc] init]; isWideVine = YES; @@ -724,8 +727,8 @@ - (void)setAttribute: (NSArray*)args{ attributeVal = [args objectAtIndex:1]; [self initWV: playerSource andKey: attributeVal]; break; - #endif - +#endif + default: break; } @@ -809,9 +812,22 @@ - (void)stopAndRemovePlayer{ player = nil; self.webView = nil; + [self removeAirPlayIcon]; + NSLog(@"stopAndRemovePlayer Exit"); } +- (void)removeAirPlayIcon { + NSLog(@"removeAirPlayIcon Enter"); + + if ( volumeView ) { + [volumeView removeFromSuperview]; + volumeView = nil; + } + + NSLog(@"removeAirPlayIcon Exit"); +} + - (void)doneFSBtnPressed { NSLog(@"doneFSBtnPressed Enter"); @@ -821,6 +837,56 @@ - (void)doneFSBtnPressed { NSLog(@"doneFSBtnPressed Exit"); } +#pragma mark - airplay plugin +- (void)addNativeAirPlayButton { + NSLog(@"addNativeAirPlayButton Enter"); + + // Add airplay + self.view.backgroundColor = [UIColor clearColor]; + if ( !volumeView ) { + volumeView = [ [MPVolumeView alloc] init ]; + [volumeView setShowsVolumeSlider: NO]; + } + + NSLog(@"addNativeAirPlayButton Exit"); +} + +-(void)showNativeAirPlayButton: (NSArray*)airPlayBtnPositionArr { + NSLog(@"showNativeAirPlayButton Enter"); + + if ( volumeView.hidden ) { + volumeView.hidden = NO; + + if ( prevAirPlayBtnPositionArr == nil || ![prevAirPlayBtnPositionArr isEqualToArray: airPlayBtnPositionArr] ) { + prevAirPlayBtnPositionArr = airPlayBtnPositionArr; + }else { + return; + } + } + + CGFloat x = [[airPlayBtnPositionArr objectAtIndex:0] floatValue]; + CGFloat y = [[airPlayBtnPositionArr objectAtIndex:1] floatValue]; + CGFloat w = [[airPlayBtnPositionArr objectAtIndex:2] floatValue]; + CGFloat h = [[airPlayBtnPositionArr objectAtIndex:3] floatValue]; + + volumeView.frame = CGRectMake( x, y, w, h ); + + [self.view addSubview: volumeView]; + [self.view bringSubviewToFront: volumeView]; + + NSLog(@"showNativeAirPlayButton Exit"); +} + +-(void)hideNativeAirPlayButton { + NSLog(@"hideNativeAirPlayButton Enter"); + + if ( !volumeView.hidden ) { + volumeView.hidden = YES; + } + + NSLog(@"hideNativeAirPlayButton Exit"); +} + - (BOOL)isIpad{ return ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad); @@ -900,9 +966,9 @@ - (Attribute)attributeNameEnumFromString{ NSDictionary *Attributes = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInteger:src], @"src", [NSNumber numberWithInteger:currentTime], @"currentTime", - #if !(TARGET_IPHONE_SIMULATOR) - [NSNumber numberWithInteger:wvServerKey], @"wvServerKey", - #endif +#if !(TARGET_IPHONE_SIMULATOR) + [NSNumber numberWithInteger:wvServerKey], @"wvServerKey", +#endif nil ]; NSLog(@"attributeNameEnumFromString Exit");