0

I have an audio app that loops sounds for playback using Cordova 2.2 and its Audio API. At the moment I have setup a number of loops that will stop when finished based on predetermined time (calculated on n seconds per loop / 3 hours) . This method generally works.

           playMainAudio = new Media(url,
                                          // success callback
                                          function() {
                                          console.log("playAudio():Audio Success");
                                          },
                                          // error callback
                                          function(err) {
                                          console.log("playAudio():Audio Error: "+err);
                                          });

                // Play audio
                playMainAudio.play({ numberOfLoops: 123, playAudioWhenScreenIsLocked : true });

But I'd prefer a native code addition where I could just set all audio to stop after 3 hours rather then work it out based on time- but not sure were to look or even place the code. The catch is it has to work when locked or the app is in the background (currently I have the correct background mode set so the audio will play in the BG).

is there a native timer that is background compatible ?

Adam Ware
  • 1,202
  • 11
  • 17

1 Answers1

1

If you are keen on editing app delegate.m in Objective-C (not your language of choice) inside

- (void)applicationDidEnterBackground:(UIApplication *)application stop audio but delay using

– performSelector:withObject:afterDelay:

See the documentation here:

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html

https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/Reference/Reference.html

For examples on how to play audio in Objective-C:

How to play a sound in objective C iphone coding

Play Audio iOS Objective-C

How can I Add Audio Player in iphone App

Pang
  • 9,564
  • 146
  • 81
  • 122
  • Thanks for the information, objective C isnt my code of choice and I guess its hard as I'm starting sounds through phonegap rather then directly. – Adam Ware Apr 09 '13 at 05:32
  • Write down your pseudocode or algorithm. Google the exact commands in objective C and the file you need to insert that code in (appdelegate.m etc etc), I have provided the links. I do not see any other way out for you if you want to become an iphone programmer as some of the coding can be done in jquery but superior control is in xcode, which is objective C. Give it some time and learn. – iOSAndroidWindowsMobileAppsDev Apr 10 '13 at 03:02