audio - Playing a simple wav file in iphone ios -
i trying play wav file on click of button using audiotoolbox framework.there no error thrown,but sound not getting played.
-(ibaction)buttonpressed { nsstring *path; nsurl *url; avaudioplayer *player; nslog(@"hai"); path = [[nsbundle mainbundle] pathforresource:@"sound" oftype:@"wav"]; url=[nsurl fileurlwithpath:path]; player=[[avaudioplayer alloc]initwithcontentsofurl:url error:null]; [player setvolume:5.0]; [player play]; } also tried code
nsstring *path = [nsstring stringwithformat:@"%@%@", [[nsbundle mainbundle] resourcepath], @"censor-beep-01.wav"]; systemsoundid soundid; nsurl *filepath = [nsurl fileurlwithpath:path isdirectory:no]; //use sound sevices create sound audioservicescreatesystemsoundid((__bridge cfurlref)filepath, &soundid); //use sound services play sound audioservicesplaysystemsound(soundid);
set avaudioplayer framework in header file.. , declare avaudioplayer *player; in .h file as
@property (nonatomic, retain) avaudioplayer *player; synthesize , remove line in button action avaudioplayer *player; should declare in .h file.
ios audio
No comments:
Post a Comment