Skip to content

Commit

Permalink
Merge branch 'ANInstreamVideoAd_API_For_CreativeURL_Duration_VastXML_…
Browse files Browse the repository at this point in the history
…VastURL'
  • Loading branch information
asharmaa committed Dec 18, 2017
2 parents f42b0d0 + a437d36 commit 8cab827
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 99 deletions.
30 changes: 12 additions & 18 deletions examples/SimpleVideo/SimpleVideo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
60846A1B1E43C676005D46BC /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 60846A191E43C676005D46BC /* Main.storyboard */; };
60846A1D1E43C676005D46BC /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 60846A1C1E43C676005D46BC /* Assets.xcassets */; };
60846A201E43C676005D46BC /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 60846A1E1E43C676005D46BC /* LaunchScreen.storyboard */; };
60846A8E1E48E19B005D46BC /* AVPlayerView.m in Sources */ = {isa = PBXBuildFile; fileRef = 60846A8D1E48E19B005D46BC /* AVPlayerView.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -194,8 +193,6 @@
60846A1F1E43C676005D46BC /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
60846A211E43C676005D46BC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
60846A261E43C676005D46BC /* SimpleVideoUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SimpleVideoUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
60846A8C1E48E19B005D46BC /* AVPlayerView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AVPlayerView.h; sourceTree = "<group>"; };
60846A8D1E48E19B005D46BC /* AVPlayerView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AVPlayerView.m; sourceTree = "<group>"; };
60AB324C1E52163C00429ED7 /* ANSDK.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = ANSDK.xcodeproj; path = ../../BinaryProjects/ANSDK.xcodeproj; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -243,8 +240,6 @@
60846A131E43C676005D46BC /* AppDelegate.h */,
60846A141E43C676005D46BC /* AppDelegate.m */,
60846A1C1E43C676005D46BC /* Assets.xcassets */,
60846A8C1E48E19B005D46BC /* AVPlayerView.h */,
60846A8D1E48E19B005D46BC /* AVPlayerView.m */,
60846A211E43C676005D46BC /* Info.plist */,
60846A1E1E43C676005D46BC /* LaunchScreen.storyboard */,
60846A191E43C676005D46BC /* Main.storyboard */,
Expand All @@ -265,25 +260,25 @@
60AB324D1E52163C00429ED7 /* Products */ = {
isa = PBXGroup;
children = (
60AB32651E52163C00429ED7 /* ANSDKResources.bundle */,
60AB32811E52163C00429ED7 /* AppNexusSDK.framework */,
60AB327D1E52163C00429ED7 /* libANAdapterForGoogleAdMobSDK.a */,
60AB327F1E52163C00429ED7 /* libANAdapterForMoPubSDK.a */,
60AB32631E52163C00429ED7 /* libANSDK.a */,
60AB32751E52163C00429ED7 /* libANSDKAdColonyAdapter.a */,
60AB32851E52163C00429ED7 /* libANSDKAdMarvelAdapter.a */,
60AB326F1E52163C00429ED7 /* libANSDKAmazonAdapter.a */,
60AB32791E52163C00429ED7 /* libANSDKChartboostAdapter.a */,
60AB326D1E52163C00429ED7 /* libANSDKFacebookAdapter.a */,
60AB32651E52163C00429ED7 /* ANSDKResources.bundle */,
60AB32671E52163C00429ED7 /* libANSDKGoogleAdMobAdapter.a */,
60AB32711E52163C00429ED7 /* libANSDKInMobiAdapter.a */,
60AB32691E52163C00429ED7 /* libANSDKMillennialMediaAdapter.a */,
60AB326B1E52163C00429ED7 /* libANSDKMoPubAdapter.a */,
60AB32871E52163C00429ED7 /* libANSDKRubiconAdapter.a */,
60AB32831E52163C00429ED7 /* libANSDKSmartAdAdapter.a */,
60AB326D1E52163C00429ED7 /* libANSDKFacebookAdapter.a */,
60AB326F1E52163C00429ED7 /* libANSDKAmazonAdapter.a */,
60AB32711E52163C00429ED7 /* libANSDKInMobiAdapter.a */,
60AB32731E52163C00429ED7 /* libANSDKVdopiaAdapter.a */,
60AB32751E52163C00429ED7 /* libANSDKAdColonyAdapter.a */,
60AB32771E52163C00429ED7 /* libANSDKVungleAdapter.a */,
60AB32791E52163C00429ED7 /* libANSDKChartboostAdapter.a */,
60AB327B1E52163C00429ED7 /* libANSDKYahooAdapter.a */,
60AB327D1E52163C00429ED7 /* libANAdapterForGoogleAdMobSDK.a */,
60AB327F1E52163C00429ED7 /* libANAdapterForMoPubSDK.a */,
60AB32811E52163C00429ED7 /* AppNexusSDK.framework */,
60AB32831E52163C00429ED7 /* libANSDKSmartAdAdapter.a */,
60AB32851E52163C00429ED7 /* libANSDKAdMarvelAdapter.a */,
60AB32871E52163C00429ED7 /* libANSDKRubiconAdapter.a */,
);
name = Products;
sourceTree = "<group>";
Expand Down Expand Up @@ -536,7 +531,6 @@
buildActionMask = 2147483647;
files = (
60846A151E43C676005D46BC /* AppDelegate.m in Sources */,
60846A8E1E48E19B005D46BC /* AVPlayerView.m in Sources */,
60846A121E43C676005D46BC /* main.m in Sources */,
60846A181E43C676005D46BC /* ViewController.m in Sources */,
);
Expand Down
23 changes: 0 additions & 23 deletions examples/SimpleVideo/SimpleVideo/AVPlayerView.h

This file was deleted.

30 changes: 0 additions & 30 deletions examples/SimpleVideo/SimpleVideo/AVPlayerView.m

This file was deleted.

10 changes: 5 additions & 5 deletions examples/SimpleVideo/SimpleVideo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11542" systemVersion="15G1108" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11524"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13527"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand All @@ -28,7 +28,7 @@
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
</textView>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="IRQ-ds-JnX" customClass="AVPlayerView">
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="IRQ-ds-JnX">
<rect key="frame" x="16" y="45" width="343" height="250"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="kgR-WA-MU0">
Expand Down Expand Up @@ -63,7 +63,7 @@
<connections>
<outlet property="logTextView" destination="rJM-PO-wUU" id="gaL-3L-e66"/>
<outlet property="playButton" destination="kgR-WA-MU0" id="f2P-pf-oSm"/>
<outlet property="videoView" destination="IRQ-ds-JnX" id="MMk-hK-meE"/>
<outlet property="videoView" destination="IRQ-ds-JnX" id="cVk-N7-ULm"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
Expand Down
69 changes: 46 additions & 23 deletions examples/SimpleVideo/SimpleVideo/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
*/

#import "ViewController.h"
#import "AVPlayerView.h"

#import <AVFoundation/AVFoundation.h>

@import AVFoundation;

Expand All @@ -27,8 +26,7 @@

@interface ViewController ()<ANInstreamVideoAdLoadDelegate, ANInstreamVideoAdPlayDelegate>

@property(nonatomic, weak) IBOutlet AVPlayerView *videoView;

@property(nonatomic, weak) IBOutlet UIView *videoView;

@property (weak, nonatomic) IBOutlet UITextView *logTextView;

Expand All @@ -55,16 +53,11 @@ - (void)viewDidLoad {
[super viewDidLoad];

self.playButton.layer.zPosition = MAXFLOAT;

self.isvideoAdAvailable = false;

[ANLogManager setANLogLevel:ANLogLevelAll];

[[ANSDKSettings sharedInstance] setHTTPSEnabled:false];

// Fix iPhone issue of log text starting in the middle of the UITextView
self.automaticallyAdjustsScrollViewInsets = NO;

self.portraitVideoViewFrame = self.videoView.frame;


Expand All @@ -73,8 +66,8 @@ - (void)viewDidLoad {
[[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight) {
[self viewDidEnterLandscape];
}
[self setupContentPlayer];

[self setupContentPlayer];
self.videoAd = [[ANInstreamVideoAd alloc] initWithPlacementId:placementId];
[self.videoAd loadAdWithDelegate:self];
self.videoAd.opensInNativeBrowser = false;
Expand Down Expand Up @@ -122,11 +115,12 @@ - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)interfaceOrien
-(void) setupContentPlayer {
NSURL *contentURL = [NSURL URLWithString:videoContent];
self.videoContentPlayer = [AVPlayer playerWithURL:contentURL];
[self.videoContentPlayer seekToTime:kCMTimeZero];
[self.videoView setPlayer:self.videoContentPlayer];

self.videoContentPlayer = [AVPlayer playerWithURL:contentURL];
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.videoContentPlayer];
playerLayer.frame = self.videoView.bounds;
[self.videoView.layer addSublayer:playerLayer];
[self.videoView setNeedsLayout];
self.videoView.translatesAutoresizingMaskIntoConstraints = YES;

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(itemDidFinishPlaying:) name:AVPlayerItemDidPlayToEndTimeNotification object:self.videoContentPlayer.currentItem];

}
Expand All @@ -135,15 +129,12 @@ - (void)viewDidEnterLandscape {

CGRect screenRect = [[UIScreen mainScreen] bounds];
self.fullscreenVideoFrame = CGRectMake(0, 0, screenRect.size.width, screenRect.size.height);

[self.videoView setFrame:self.fullscreenVideoFrame];

}

- (void)viewDidEnterPortrait {

[self.videoView setFrame:self.portraitVideoViewFrame];

}

#pragma mark Utility methods
Expand All @@ -167,13 +158,38 @@ - (void)logMessage:(NSString *)log {
}
}

-(void)getAdPlayElapsedTime{

// To get AdPlayElapsedTime
NSUInteger getAdPlayElapsedTime = [self.videoAd getAdPlayElapsedTime];
[self logMessage:[NSString stringWithFormat:@"AdPlayElapsedTime : %lu",(unsigned long)getAdPlayElapsedTime]];

}
#pragma mark - ANInstreamVideoAdDelegate.

//----------------------------- -o-
- (void) adDidReceiveAd: (id<ANAdProtocol>)ad
{
[self logMessage:@"adDidReceiveAd"];

// To get AdDuration
NSUInteger getAdDuration = [self.videoAd getAdDuration];
[self logMessage:[NSString stringWithFormat:@"AdDuration : %lu",(unsigned long)getAdDuration]];

// To get CreativeURL
NSString* getCreativeURL = [self.videoAd getCreativeURL];
[self logMessage:[NSString stringWithFormat:@"CreativeURL : %@",getCreativeURL]];

// To get VastURL
NSString* getVastURL = [self.videoAd getVastURL];
[self logMessage:[NSString stringWithFormat:@"VastURL : %@",getVastURL]];

// To get VastXML
NSString* getVastXML = [self.videoAd getVastXML];
[self logMessage:[NSString stringWithFormat:@"VastXML : %@",getVastXML]];

// To get AdPlayElapsedTime
[self getAdPlayElapsedTime];
self.isvideoAdAvailable = true;


Expand All @@ -183,27 +199,38 @@ - (void) ad: (id<ANAdProtocol>)ad
requestFailedWithError: (NSError *)error
{
[self logMessage:@"adRequestFailedWithError"];
self.isvideoAdAvailable = false;
self.isvideoAdAvailable = false;
}

//----------------------------- -o-
- (void) adCompletedFirstQuartile:(id<ANAdProtocol>)ad
{
[self logMessage:@"adCompletedFirstQuartile"];
[self getAdPlayElapsedTime];
}


//----------------------------- -o-
- (void) adCompletedMidQuartile:(id<ANAdProtocol>)ad
{
[self logMessage:@"adCompletedMidQuartile"];
[self getAdPlayElapsedTime];
}

-(void) adPlayStarted:(id<ANAdProtocol>)ad{

[self logMessage:@"adPlayStarted"];
[self getAdPlayElapsedTime];

}



//----------------------------- -o-
- (void) adCompletedThirdQuartile:(id<ANAdProtocol>)ad
{
[self logMessage:@"adCompletedThirdQuartile"];
[self getAdPlayElapsedTime];
}


Expand All @@ -219,10 +246,8 @@ -(void) adMute: (id<ANAdProtocol>)ad
{
if(muteStatus == YES){
[self logMessage:@"adMuteOn"];

} else {
[self logMessage:@"adMuteOff"];

}

}
Expand All @@ -235,13 +260,11 @@ -(void) adDidComplete:(id<ANAdProtocol>)ad withState:(ANInstreamVideoPlaybackSta
[self logMessage:@"adplaybackFailedWithError"];
}else if(state == ANInstreamVideoPlaybackStateCompleted){
[self logMessage:@"adPlayCompleted"];
[self getAdPlayElapsedTime];
}

self.isvideoAdAvailable = false;

[self.videoContentPlayer play];


}


Expand Down

0 comments on commit 8cab827

Please sign in to comment.