cordova - How I can play music background on IOS app using phonegap -


i'm building first ios app, , want play mp3 file when app start run , when change page still play not reload start play.

thank you!

in ios 4.0 , above can run audio in background. phonegap doesn't support out of box, can add it. so, you'll need 2 things; add item info.plist file , add line of code phonegap.

to info.plist file, add new key of “required background modes”. key have array of options. in “item 0” of array set value “app plays audio”.

next, modify ~/phonegaplib/classes/sound.m file. line contains “if ([resourceurl isfileurl]) {”. it's around line 103. below line, inside if statement, you'll want add following.

[[avaudiosession sharedinstance] setcategory:avaudiosessioncategoryplayback error:nil]; 

so, section of code following.

if ([resourceurl isfileurl]) {     [[avaudiosession sharedinstance] setcategory:avaudiosessioncategoryplayback error:nil];     audiofile.player = [[ avaudioplayer alloc ] initwithcontentsofurl:resourceurl error:&error]; } else {     nsdata* data = [nsdata datawithcontentsofurl:resourceurl];     audiofile.player = [[ avaudioplayer alloc ] initwithdata:data error:&error]; } 

note: users have have had trouble finding sound.m file. it's not in xcode project itself. you'll find beneath home directory (~) under ~/phonegaplib/classes/ or can use finder search sound.m. right-click on , open in xcode.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -