@interface YourViewController : UIViewController
@end
@implementation YourViewController
{
MTRGInstreamAudioAd *_ad;
}
- (void)initAd
{
// Enable debug mode
// [MTRGInstreamAudioAd setDebugMode:YES];
// Create an instance of MTRGInstreamAudioAd
_ad = [MTRGInstreamAudioAd instreamAudioAdWithSlotId:YOUR_SLOT_ID];
}
@interface YourViewController : UIViewController
@end
@implementation YourViewController
{
MTRGInstreamAudioAd *_ad;
}
- (void)initAd
{
// Create an instance of MTRGInstreamAudioAd
_ad = [MTRGInstreamAudioAd instreamAudioAdWithSlotId:YOUR_SLOT_ID];
// Install the player
_ad.player = YOUR_PLAYER;
}
@property(nonatomic, readonly) NSTimeInterval adAudioDuration;
@property(nonatomic, readonly) NSTimeInterval adAudioTimeElapsed;
@property(nonatomic, weak) id <MTRGInstreamAudioAdPlayerDelegate> adPlayerDelegate;
@property(nonatomic) float volume;
void setVolume(float volume);
- (void)playAdAudioWithUrl:(NSURL *)url;
- (void)pauseAdAudio;
- (void)resumeAdAudio;
- (void)stopAdAudio;
- (void)onAdAudioStart;
- (void)onAdAudioPause;
- (void)onAdAudioResume;
- (void)onAdAudioStop;
- (void)onAdAudioErrorWithReason:(NSString *)reason;
- (void)onAdAudioComplete;
interface YourViewController : UIViewController <MTRGInstreamAudioAdDelegate>
@end
@implementation YourViewController
{
MTRGInstreamAudioAd *_ad;
}
- (void)initAd
{
// Create an instance of MTRGInstreamAudioAd
_ad = [MTRGInstreamAudioAd instreamAudioAdWithSlotId:YOUR_SLOT_ID];
// Set the delegate
_ad.delegate = self;
// Start loading data
[_ad load];
}
- (void)onLoadWithInstreamAudioAd:(MTRGInstreamAudioAd *)instreamAudioAd
{
// The data was successfully loaded
}
- (void)onNoAdWithReason:(NSString *)reason instreamAudioAd:(MTRGInstreamAudioAd *)instreamAudioAd
{
// No data received
}
- (void)onErrorWithReason:(NSString *)reason instreamAudioAd:(MTRGInstreamAudioAd *)instreamAudioAd
{
// An error occurred while playing the promotional video
}
- (void)onBannerStart:(MTRGInstreamAudioAdBanner *)banner instreamAudioAd:(MTRGInstreamAudioAd *)instreamAudioAd
{
// Began playing the promotional video
}
- (void)onBannerComplete:(MTRGInstreamAudioAdBanner *)banner instreamAudioAd:(MTRGInstreamAudioAd *)instreamAudioAd
{
// Ad video playback completed
}
- (void)onBannerTimeLeftChange:(NSTimeInterval)timeLeft duration:(NSTimeInterval)duration instreamAudioAd:(MTRGInstreamAudioAd *)instreamAudioAd
{
// 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 instreamAudioAd:(MTRGInstreamAudioAd *)instreamAudioAd
{
// Playback of all promotional videos in the advertising section is completed
}
- (void)onShowModalWithInstreamAudioAd:(MTRGInstreamAudioAd *)instreamAudioAd
{
}
- (void)onDismissModalWithInstreamAudioAd:(MTRGInstreamAudioAd *)instreamAudioAd
{
}
- (void)onLeaveApplicationWithInstreamAudioAd:(MTRGInstreamAudioAd *)instreamAudioAd
{
}
// Before starting the main video
[_ad startPreroll];
// After showing the main video
[_ad startPostroll];
@interface YourViewController : UIViewController <MTRGInstreamAudioAdDelegate>
@end
@implementation YourViewController
{
MTRGInstreamAudioAd *_ad;
NSArray <NSNumber *> *_adPositions;
}
- (void)initAd
{
// Создаем экземпляр MTRGInstreamAudioAd
_ad = [MTRGInstreamAudioAd instreamAudioAdWithSlotId:YOUR_SLOT_ID];
// Set positions on the first and fifth second of audio
[_ad configureMidpoints:@[@1, @5] forVideoDuration:_videoDuration];
// or percentage, 10% and 50% audio
// [_ad configureMidpointsP:@[@10, @50] forVideoDuration:_videoDuration];
// Set the delegate
_ad.delegate = self;
// Start loading data
[_ad load];
}
- (void)onLoadWithInstreamAudioAd:(MTRGInstreamAudioAd *)instreamAudioAd
{
// The data was successfully loaded
// Array of positions (in seconds) available to display the midroll section
_adPositions = _ad.midpoints;
}
// Audio play to 5 seconds and there position in the array adPositions
[_ad startMidrollWithPoint:_adPositions[1]];
@property(nonatomic) NSTimeInterval duration;
@property(nonatomic) BOOL allowSeek;
@property(nonatomic) BOOL allowSkip;
@property(nonatomic) BOOL allowTrackChange;
@property(nonatomic) NSArray<MTRGInstreamAdCompanionBanner *> *companionBanners;
@property(nonatomic, copy) NSString *adText;
- (void)onCompanionAdShow:(MTRGInstreamAdCompanionBanner *)companionBanner
{
[_ad handleCompanionShow:companionBanner];
}
- (void)onCompanionAdClick:(MTRGInstreamAdCompanionBanner *)companionBanner
{
[_ad handleCompanionClick:companionBanner withController: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
{
MTRGInstreamAudioAd *_ad;
}
-(void) initAd
{
// Create an instance of MTRGInstreamAudioAd
_ad = [MTRGInstreamAudioAd instreamAudioAdWithSlotId:YOUR_SLOT_ID];
// Set age
_ad.customParams.age = [NSNumber numberWithInt:25];
// Set gender
_ad.customParams.gender = MTRGGenderMale;
}