3

I cannot work this out - it should be simple.

I have:

ShowAVPlayer method

AVPlayerItem *video = [[AVPlayerItem alloc] initWithURL:url];
AVQueuePlayer *queue = [[AVQueuePlayer alloc] initWithItems:@[video]];
video = [[AVPlayerItem alloc] initWithURL:url];   
[queue insertItem:video afterItem:nil];    
AVPlayer *player = [AVPlayer playerWithURL:url];
self.avmovieplayer = [AVPlayerViewController new];

I want to add a button to my overlay - but the button is not responding :

UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setTitle:@"Do stuff" forState:UIControlStateNormal];
btn.frame = CGRectMake(0, 330, 320, 40);
[btn addTarget:self action:@selector(DoSpeech:) forControlEvents:UIControlEventTouchUpInside];
[btn setUserInteractionEnabled:true];
[self.avmovieplayer.contentOverlayView addSubview:btn];

Here is my DoSpeech which is never being called:

- (void) DoSpeech:(UIButton *)button {

   //DoSpeech

}
  • Why are you adding button to contentOverlayView? just add it to view. i.e, [self.avmovieplayer.view addSubview : btn]; – Ketan Parmar Apr 12 '16 at 10:38

1 Answers1

0

Try this,

[btn setUserInteractionEnabled:YES];
[self.avmovieplayer.contentOverlayView bringSubviewToFront:btn];

Hope it will help.

Muhammad Burhan
  • 145
  • 1
  • 2
  • 11
  • Unfortunately not - but thanks any how ! When I tab the doStuff button avplayerviewcontroller is responding to the tab - is it something first responder maybe – TheSnakeWizard Apr 12 '16 at 11:11
  • 2
    Ok I found the answer From the apple docs: Use the content overlay view to add additional custom views between the video content and the controls. So it looks like this: (with a bunch of other layers over your UISlider) To make it work just change this line: [avPlayerViewController.contentOverlayView addSubview:sliderForVolumeControl]; to this: [avPlayerViewController.view addSubview:sliderForVolumeControl]; - See more at: http://www.mzan.com/article/34529065-uislider-added-on-avplayerviewcontroller-contentoverlayview-is-not-responding.shtml#sthash.rRHDzDiT.dpuf – TheSnakeWizard Apr 12 '16 at 14:29
  • its the same with a button – TheSnakeWizard Apr 12 '16 at 14:30
  • Good to hear @TheSnakeWizard that you have solved your problem. Cheers. – Muhammad Burhan Apr 13 '16 at 06:35