@interface YourViewController : UIViewController
@end
@implementation YourViewController
{
MTRGInstreamAd *_ad;
}
- (void)initAd
{
// Enable debug mode
// [MTRGInstreamAd setDebugMode:YES];
// Create an instance of MTRGInstreamAd
_ad = [MTRGInstreamAd instreamAdWithSlotId:YOUR_SLOT_ID];
}
@interface YourViewController : UIViewController
@end
@implementation YourViewController
{
MTRGInstreamAd *_ad;
}
- (void)initAd
{
// Create an instance of MTRGInstreamAd
_ad = [MTRGInstreamAd instreamAdWithSlotId:YOUR_SLOT_ID];
// Install the player
_ad.player = YOUR_PLAYER;
}
@property(nonatomic, readonly) NSTimeInterval adVideoDuration;
@property(nonatomic, readonly) NSTimeInterval adVideoTimeElapsed;
@property(nonatomic, weak) id <MTRGInstreamAdPlayerDelegate> adPlayerDelegate;
@property(nonatomic, readonly) UIView *adPlayerView;
@property(nonatomic) float volume;
- (void)playAdVideoWithUrl:(NSURL *)url;
- (void)pauseAdVideo;
- (void)resumeAdVideo;
- (void)stopAdVideo;
- (void)onAdVideoStart;
- (void)onAdVideoPause;
- (void)onAdVideoResume;
- (void)onAdVideoStop;
- (void)onAdVideoErrorWithReason:(NSString *)reason;
- (void)onAdVideoComplete;
@interface YourViewController : UIViewController
@end
@implementation YourViewController
{
MTRGInstreamAd *_ad;
}
- (void)initAd
{
// Create an instance of MTRGInstreamAd
_ad = [MTRGInstreamAd instreamAdWithSlotId:YOUR_SLOT_ID];
// Install the player SDK
[_ad useDefaultPlayer];
// Add player to the screen
[self.view addSubview:_ad.player.adPlayerView];
}
@interface YourViewController : UIViewController <MTRGInstreamAdDelegate>
@end
@implementation YourViewController
{
MTRGInstreamAd *_ad;
}
- (void)initAd
{
// Create an instance of MTRGInstreamAd
_ad = [MTRGInstreamAd instreamAdWithSlotId:YOUR_SLOT_ID];
// Set the delegate
_ad.delegate = self;
// Start loading data
[_ad load];
}
- (void)onLoadWithInstreamAd:(MTRGInstreamAd *)instreamAd
{
// The data was successfully loaded
}
- (void)onNoAdWithReason:(NSString *)reason instreamAd:(MTRGInstreamAd *)instreamAd
{
// No data received
}
- (void)onErrorWithReason:(NSString *)reason instreamAd:(MTRGInstreamAd *)instreamAd
{
// An error occurred while playing the promotional video
}
- (void)onBannerStart:(MTRGInstreamAdBanner *)banner instreamAd:(MTRGInstreamAd *)instreamAd
{
// Began playing the promotional video
}
- (void)onBannerComplete:(MTRGInstreamAdBanner *)banner instreamAd:(MTRGInstreamAd *)instreamAd
{
// Ad video playback completed
}
- (void)onBannerTimeLeftChange:(NSTimeInterval)timeLeft duration:(NSTimeInterval)duration instreamAd:(MTRGInstreamAd *)instreamAd
{
// Is called multiple times during playback of the promotional video is used to update the timer before the end of the show promotional video
}
- (void)onCompleteWithSection:(NSString *)section instreamAd:(MTRGInstreamAd *)instreamAd
{
// Playback of all promotional videos in the advertising section is completed
}
- (void)onShowModalWithInstreamAd:(MTRGInstreamAd *)instreamAd
{
}
- (void)onDismissModalWithInstreamAd:(MTRGInstreamAd *)instreamAd
{
}
- (void)onLeaveApplicationWithInstreamAd:(MTRGInstreamAd *)instreamAd
{
}
// Before starting the main video
[_ad startPreroll];
// After showing the main video
[_ad startPostroll];
@interface YourViewController : UIViewController <MTRGInstreamAdDelegate>
@end
@implementation YourViewController
{
MTRGInstreamAd *_ad;
NSArray <NSNumber *> *_adPositions;
}
- (void)initAd
{
// Create an instance of MTRGInstreamAd
_ad = [MTRGInstreamAd instreamAdWithSlotId:YOUR_SLOT_ID];
// Set positions on the first and fifth seconds of the video
[_ad configureMidpoints:@[@1, @5] forVideoDuration:_videoDuration];
// or percentage, 10% and 50% video
// [_ad configureMidpointsP:@[@10, @50] forVideoDuration:_videoDuration];
// Set the delegate
_ad.delegate = self;
// Start loading data
[_ad load];
}
- (void)onLoadWithInstreamAd:(MTRGInstreamAd *)instreamAd
{
// The data was successfully loaded
// Array of positions (in seconds) available to display the midroll section
_adPositions = _ad.midpoints;
}
// The video was played to the 5th second and it has a position in the array adPositions
[_ad startMidrollWithPoint:_adPositions[1]];
@property(nonatomic) NSTimeInterval duration;
@property(nonatomic) BOOL allowClose;
@property(nonatomic) NSTimeInterval allowCloseDelay;
@property(nonatomic) CGSize size;
@property(nonatomic, copy) NSString *ctaText;
- (void)onAdClick
{
[_ad handleClickWithController:self];
}
- (void)pause;
- (void)resume;
- (void)stop;
- (void)skip;
- (void)skipBanner;
@property(nonatomic) float volume;
@property(nonatomic) NSUInteger loadingTimeout;
@interface YourViewController : UIViewController
@end
@implementation YourViewController
{
MTRGInstreamAd *_ad;
}
- (void)initAd
{
// Create an instance of MTRGInstreamAd
_ad = [MTRGInstreamAd instreamAdWithSlotId:YOUR_SLOT_ID];
// Set the age
_ad.customParams.age = [NSNumber numberWithInt:25];
// Set gender
_ad.customParams.gender = MTRGGenderMale;
}