objective c - Unrecognized Selector in AVplayer setNumberOfLoops Method -


when calling numberofloops method so: [_player setnumberofloops:-1];

i following error: -[avplayer setnumberofloops:]: unrecognized selector sent instance 0x7d52d30

how can fixed?

code:

header:

#import <uikit/uikit.h> #import <avfoundation/avfoundation.h> @interface viewcontroller : uiviewcontroller {  }   @property (strong, nonatomic) avaudioplayer *player;  - (ibaction)playmusic:(id)sender;   @end 

implementation:

#import "viewcontroller.h"  #import <avfoundation/avfoundation.h>  @interface viewcontroller ()  @end  @implementation viewcontroller  - (void)viewdidload {     [super viewdidload];     // additional setup after loading view, typically nib.  }  - (void)didreceivememorywarning {     [super didreceivememorywarning];     // dispose of resources can recreated. }  - (ibaction)playmusic:(id)sender {     _player = [avplayer playerwithurl:[nsurl urlwithstring:@"http://urlpath.wav"]];     [_player setnumberofloops:-1];     [_player preparetoplay];     [_player play]; }  @end 

thank time,

yoni201.

avplayer doesn't have numberofloops property. property of `avaudioplayer. don't ignore compiler warnings when build app.

also, defined _player avaudioplayer alloc/init avplayer.

change code to:

nserror *error = nil; avaudioplayer *player = [[avaudioplayer alloc] initwithcontentsofurl:[nsurl urlwithstring:@"http://urlpath.wav"] error:&error]; if (player) {     [player setnumberofloops:-1];     [player preparetoplay];     [player play];     self.player = player; } else {     nslog(@"error create audio player: %@", error); } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -