I've implemented iAd's Preroll Video Ad and I want to guarantee that my user will watch the entire advertisement. How do I hide the AVPlayerViewController's control bar so the user can not tap "Done" and get out of the video before it finishes?
self.canDisplayBannerAds = YES;
[AVPlayerViewController preparePrerollAds];
player = [[AVPlayerViewController alloc] init];
player.showsPlaybackControls = NO;
player.delegate = self;
Simple code
// create an AVPlayer
AVPlayer *player = [AVPlayer playerWithURL:videoURL];
// create a player view controller
AVPlayerViewController *controller = [[AVPlayerViewController alloc]init];
controller.player = player;
controller.showsPlaybackControls = FALSE;
You can use this code to do the same. You need to call play when you present the controller.
playerItem = [[AVPlayerItem alloc] initWithURL:url];
if(playerItem) {
player = [[AVPlayer alloc] initWithPlayerItem:playerItem];
playerViewController = [[AVPlayerViewController alloc] init];
playerViewController.player = _player;
[playerViewController setShowsPlaybackControls:NO];
[parentViewController presentViewController:playerViewController animated:YES completion:^{
[playerViewController.player play];
}];
Related
NSURL *videoURL = [[NSBundle mainBundle] URLForResource:#"thoughtcastAnimate_v02" withExtension:#"mov"];
// create an AVPlayer
AVPlayer *player = [AVPlayer playerWithURL:videoURL];
// create a player view controller
AVPlayerViewController *controller = [[AVPlayerViewController alloc]init];
controller.showsPlaybackControls = false;
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(itemDidFinishPlaying) name:AVPlayerItemDidPlayToEndTimeNotification object: player];//edited
controller.player = player;
// show the view controller
[self addChildViewController:controller];
[self.view addSubview:controller.view];
controller.view.frame = self.view.frame;
[player play];
itemDidFinishPlaying is never called ?!
I don't understand why.
Perhaps I have an invalid NSNotificationCenter issue. Or maybe one of it's parameters. Unsure.
I init a AVQueuePlayer like :
AVPlayerItem *item1 = [AVPlayerItem playerItemWithURL:[NSURL URLWithString:#"http://XXX.mp4"]];
AVPlayerItem *item2 = [AVPlayerItem playerItemWithURL:[NSURL URLWithString:#"http://YYY.mp4"]];
AVQueuePlayer player = [[AVQueuePlayer alloc]initWithItems:#[item1,item2]];
and I want to show it by AVPlayerViewController so I init a AVPlayerViewController like :
AVPlayerViewController *playerController = [[AVPlayerViewController alloc] init];
playerController.player = player;
...
...
[self.view addSubview:_playerController.view];
[self addChildViewController:_playerController];
now I want to play it:
[player play];
Question:
It always crashes at main when the first AVPlayerItem end play.
Did I do something wrong or wrong way to show it?
(AVPlayer is OK by this way)
I am working on playing a recorded video recorded by AVCapture.I am saving the video URL in string named outputFileURL. I tried playing back the video using AVPlayerLayer concept. The code I used is
AVPlayer *avPlayerq = [AVPlayer playerWithURL:outputFileURL];
avPlayerq.actionAtItemEnd = AVPlayerActionAtItemEndNone;
AVPlayerLayer *videoLayer = [AVPlayerLayer playerLayerWithPlayer:avPlayerq];
videoLayer.frame= self.view.bounds;
[self.view.layer addSublayer:videoLayer];
[avPlayerq play];
But the video I am getting is not full screen.
Can anyone can help me to solve?
I added the following code and I am able to get the full screen.
videoLayer.videoGravity=AVLayerVideoGravityResizeAspectFill;
Hope this may help.
AVPlayer *player = [[AVPlayer alloc] initWithURL:url];
AVPlayerViewController *playerViewController = [AVPlayerViewController new]; playerViewController.delegate = self;
playerViewController.player = player;
[playerViewController.player play];
[self presentViewController:playerViewController animated:YES completion:nil];
Try This
Ok than you have to use MPMoviePlayerController
NSString *path = [[NSBundle mainBundle] pathForResource:#"Video_Intro" ofType:#"mov"];
moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:[NSURL fileURLWithPath:path]];
moviePlayer.view.frame = ivVideoThumbnail.frame;
//moviePlayer.view.top += 20; // Add to fix 20 pixel diff of moviePlayer view
// Register this class as an observer instead.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
[svIntro addSubview:moviePlayer.view];
moviePlayer.fullscreen = true;
[moviePlayer play];
Also implement Observer method
-(void)movieFinishedCallback:(id)mPlayer
{
[moviePlayer.view removeFromSuperview];
}
I want to play video on clicking a button. My AVPlayerViewController is open but not playing an video .Please help.
- (IBAction)btnPlay_Click:(id)sender {
NSURL *videoURL = [NSURL URLWithString:#"https://player.vimeo.com/video/143506410"];
AVPlayer *player = [AVPlayer playerWithURL:videoURL];
AVPlayerViewController *playerViewController = [AVPlayerViewController new];
playerViewController.player = player;
[self presentViewController:playerViewController animated:YES completion:nil];
}
If you are using vimeo video you can use third party tools which helps you load the vimeo video.
Solution 1: Please try this, It works for me, just some lines of code.
- (void)viewDidLoad
{
[super viewDidLoad];
vimeoHelper = [[VimeoHelper alloc] init];
[vimeoHelper getVimeoRedirectUrlWithUrl:#"http://vimeo.com/52760742" delegate:(id)self];
}
- (void)finishedGetVimeoURL:(NSString *)url
{
_moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:url]];
[self presentViewController:_moviePlayerController animated:NO completion:nil];
}
Solution 2: YTVimeoExtractor
May be it will help you.
Use MPMoviePlayerController and add this line of code:
NSURL *videoURL = [NSURL URLWithString:#"https://player.vimeo.com/video/143506410"];
MPMoviePlayerViewController *player =[[MPMoviePlayerViewController alloc] initWithContentURL: videoURL];
[self.view addSubview: [player view]];
[self presentMoviePlayerViewControllerAnimated:player];
[player.moviePlayer prepareToPlay];
Add one more line : [self.view addSubview: [player view]];
movieController is an instance of MPMoviePlayerViewController declared in the .h file.
[movieController.moviePlayer play] is not required and the player will start regardless if you didn't set autoplay to NO, but I observed that if you put play in it it starts a bit quicker. This could be just a coincidence.
--------- If this is not working you can just do that following ----------
player = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
[player.view setFrame:CGRectMake(0, 0, 320, 320)];
[player play];
[self.view addSubview:player.view];
I am creating an AVPlayer to display a video. I have some code to create the Player but nothing displays. I'm not sure if the URL is not working or if the player it's self is not working.
Here is the code I am using to create the player:
self.playing = NO;
AVPlayer *player = [[AVPlayer alloc] init];
player = [player initWithURL:self.videoURL];
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
[[[self view] layer] insertSublayer:playerLayer atIndex:3];
[playerLayer setFrame:self.view.bounds];
[player play];
Here is the code to save the video:
self.videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSLog(#"%#", self.videoURL);
DetailViewController *detailViewController = [[DetailViewController alloc] init];
detailViewController.videoURL = self.videoURL;