ios - [AVPlayerViewController setPlayer:]: unrecognized selector sent to instance -
[avplayerviewcontroller setplayer:]: unrecognized selector sent instance 0x101b91980 error.
i trying play video using avplayerviewcontroller.
@property (nonatomic) avplayer *avplayer; @property (nonatomic) avplayerviewcontroller* avplayerview; nsstring *path = [[nsbundle mainbundle] pathforresource:@"samplevideo_1280x720_1mb" oftype:@"mp4"]; nsurl *url = [[nsurl alloc] initfileurlwithpath: path]; avasset *asset = [avurlasset urlassetwithurl:url options:nil]; avplayeritem *anitem = [avplayeritem playeritemwithasset:asset]; _avplayer = [avplayer playerwithplayeritem:anitem]; [avplayer addobserver:self forkeypath:@"status" options:0 context:nil]; self.avplayerview = [[avplayerviewcontroller alloc] init]; self.avplayerview.view.frame = self.view.bounds; [self.avplayerview setplayer:_avplayer]; [self.view addsubview:_avplayerview.view];
but crashing. if use same code in new project, video play nicely.what problem?please help.
make sure import avfoundation/avfoundation.h , avkit/avkit.h in controller , try assign player playercontroller this.
self.avplayerview.player = self.avplayer;
instead of adding observer avplayer class add observer avplayer instance.
[avplayer addobserver:self forkeypath:@"status" options:0 context:nil];
Comments
Post a Comment