ios - how to play Wav file -
below code unable play snarehitsample.wav file. don't know getting wrong.
-(void)playaudiofiles { nsstring * path; avaudioplayer * snd; nserror * err; nsstring *name; name = @"snarehitsample.wav"; path = [[[nsbundle mainbundle] resourcepath] stringbyappendingpathcomponent:name]; if ([[nsfilemanager defaultmanager] fileexistsatpath:path]) { nsurl * url = [nsurl fileurlwithpath:path]; snd = [[avaudioplayer alloc] initwithcontentsofurl:url error:&err] ; if (! snd) { nslog(@"sound named '%@' had error %@", name, [err localizeddescription]); } else { [snd preparetoplay]; } } else { nslog(@"sound file '%@' doesn't exist @ '%@'", name, path); } }
thank declared avaudioplayer object in .h files issue solved.
{ avaudioplayer *player1; }
ios avaudioplayer wav
No comments:
Post a Comment