How to play a video in background using YTPlayer in iOS app?

365 Views Asked by At

I am getting the following error message...

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[YTPlayerView playerView]: unrecognized selector sent to instance 0x7fd77bd41f80'

and here is my code..

- (void)applicationDidEnterBackground:(NSNotification *)notification
{   
    [_playerView performSelector:@selector(playerView) withObject:nil afterDelay:0.1];

}

- (IBAction)didTapPlayPause:(id)sender {
    self.btnPlayPause.selected = !self.btnPlayPause.selected;
    if (self.btnPlayPause.selected)
    {
        self.title=self.strngvideotitle;
        self.playerView=[[YTPlayerView alloc]initWithFrame:CGRectMake(0,0,375,290)];
        [self.playerView loadWithVideoId:self.strngvideoId];
        [self.view addSubview:_playerView];

      [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];

   }
1

There are 1 best solutions below

2
On

Your code fails at this statement

[_playerView performSelector:@selector(playerView) withObject:nil afterDelay:0.1];

The statement expects that your _playerView object will call the method playerView after a delay of 0.1 seconds. But the class YTPlayerView does not have a method called playerView. You might want to check the actual method name and replace it in the selector name.