audiotoolbox - Simply Playing A Sound in iOS -



audiotoolbox - Simply Playing A Sound in iOS -

i'm trying play sound when button clicked. first, imported audiotoolbox in header file, added code ibaction fires when button pressed, so:

- (void)viewdidload { [super viewdidload]; } - (ibaction)button1:(id)sender { nsstring *soundpath = [[nsbundle mainbundle] pathforresource:@"mysong" oftype:@"wav"]; systemsoundid soundid; audioservicescreatesystemsoundid((__bridge cfurlref)[nsurl fileurlwithpath:soundpath], &soundid); audioservicesplaysystemsound (soundid); }

i threw nslog in method create sure it's firing. is. in foo path in string see if crash, did. made sure dragged , dropped short sound file app well. tested speakers, tested sound on device simulator going youtube on simulator, everything. can't figure out i'm doing wrong.

when changed code this:

- (ibaction)button1:(id)sender { avaudioplayer *testaudioplayer; // *** implementation... *** // load sound info nsstring *soundfilepath = [[nsbundle mainbundle] pathforresource:@"3" oftype:@"wav"]; nsdata *sampledata = [[nsdata alloc] initwithcontentsoffile:soundfilepath]; nserror *audioerror = nil; // set sound player testaudioplayer = [[avaudioplayer alloc] initwithdata:sampledata error:&audioerror]; if(audioerror != nil) { nslog(@"an sound error occurred: \"%@\"", audioerror); } else { [testaudioplayer setnumberofloops: -1]; [testaudioplayer play]; }}

i error: warning: 137: error '!dat' trying set (null) sound devices' sample rate

hi per question can please check whether sound file nowadays in project folder.it might happen u have forgotten checkmark "copy item if needed" might not there in project file.

you can play sounds provided in device. visit below link helpful.

https://github.com/tuner88/iossystemsoundslibrary

i've tested code , working fine , not getting crashed. here's did.

ios audiotoolbox

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -