ios - Xcode wont play sound in this folder? -
ios - Xcode wont play sound in this folder? -
hi simple app play sound when button pressed. imported frameworks , folder whole host of sounds, when set path wont play sound , nse exception error when click on button play sound. took sound file out of folder though folder in project , magically plays? ideas? or code must add together in order play folder?
#import <avfoundation/avaudioplayer.h> #import "viewcontroller.h" @interface viewcontroller () @end @implementation viewcontroller avaudioplayer *theaudio; - (ibaction)yes:(id)sender { nsurl *url = [nsurl fileurlwithpath:[[nsbundle mainbundle] pathforresource:@"yes" oftype:@"mp3"]]; theaudio = [[avaudioplayer alloc] initwithcontentsofurl:url error:null]; [theaudio play]; } @end
this chance larn both exceptions , bundles/files:
first, exceptions: nsexception root class of exceptions, , not useful way describe happening. take @ linked reference, can see properties available describe went wrong. these properties available inspection within xcode. best way (imo) automatic breakpoint on exceptions. take "add exception breakpoint" + button @ bottom-left of breakpoint navigator (the vertical bar on left side of xcode).
second, bundles: bundles (for our purposes) special kind of directory. when utilize [nsbundle mainbundle]
, referring application's "top level" directory. there several useful methods on nsbundle help locate resources. 1 of them includes taking subdirectory parameter (hint!)
as bonus, sense mention stack overflow , encourage habits improve question quality, in turns promotes reply frequency , quality. if experiencing exception , it's fundamental question, please include total exception details. if working files , not loading properly, please include explanation (perhaps screenshot finder) of how files organized on resultant device (tip: can find application files simulator. set breakpoint , inspect value of path returned 1 of nsbundle's methods).
ios objective-c xcode
Comments
Post a Comment