-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add region tags to the Objective-C example for live snippets in the G…
…etting started guide. These region tags are used in the Getting started guide for DAI Full service at https://developers.google.com/ad-manager/dynamic-ad-insertion/sdk/ios?service=full PiperOrigin-RevId: 694144415
- Loading branch information
Showing
3 changed files
with
86 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 17 additions & 28 deletions
45
Objective-C/SampleVideoPlayer/SampleVideoPlayer/ViewController.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,41 @@ | ||
#import "ViewController.h" | ||
|
||
@import AVFoundation; | ||
#import <AVKit/AVKit.h> | ||
|
||
@interface ViewController () | ||
|
||
/// Content video player. | ||
@property(nonatomic, strong) AVPlayer *contentPlayer; | ||
/// Content URL. | ||
static NSString *const kBackupContentUrl = | ||
@"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"; | ||
|
||
@interface ViewController () | ||
/// Play button. | ||
@property(nonatomic, weak) IBOutlet UIButton *playButton; | ||
|
||
/// UIView in which we will render our AVPlayer for content. | ||
@property(nonatomic, weak) IBOutlet UIView *videoView; | ||
|
||
/// Video player. | ||
@property(nonatomic, strong) AVPlayer *videoPlayer; | ||
@end | ||
|
||
@implementation ViewController | ||
|
||
// The content URL to play. | ||
NSString *const kTestAppContentUrl_MP4 = | ||
@"https://storage.googleapis.com/gvabox/media/samples/android.mp4"; | ||
|
||
- (void)viewDidLoad { | ||
[super viewDidLoad]; | ||
self.view.backgroundColor = [UIColor blackColor]; | ||
|
||
self.playButton.layer.zPosition = MAXFLOAT; | ||
|
||
[self setUpContentPlayer]; | ||
} | ||
|
||
- (IBAction)onPlayButtonTouch:(id)sender { | ||
[self.contentPlayer play]; | ||
self.playButton.hidden = YES; | ||
} | ||
|
||
#pragma mark Content Player Setup | ||
|
||
- (void)setUpContentPlayer { | ||
// Load AVPlayer with path to our content. | ||
NSURL *contentURL = [NSURL URLWithString:kTestAppContentUrl_MP4]; | ||
self.contentPlayer = [AVPlayer playerWithURL:contentURL]; | ||
// Load AVPlayer with the path to your content. | ||
NSURL *contentURL = [NSURL URLWithString:kBackupContentUrl]; | ||
self.videoPlayer = [AVPlayer playerWithURL:contentURL]; | ||
|
||
// Create a player layer for the player. | ||
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.contentPlayer]; | ||
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.videoPlayer]; | ||
|
||
// Size, position, and display the AVPlayer. | ||
playerLayer.frame = self.videoView.layer.bounds; | ||
[self.videoView.layer addSublayer:playerLayer]; | ||
} | ||
|
||
- (IBAction)onPlayButtonTouch:(id)sender { | ||
[self.videoPlayer play]; | ||
self.playButton.hidden = YES; | ||
} | ||
|
||
@end |