IOS - Click in Settings.bundle - ios

I need to do a simple action when user click in multi value list in my preference app (in Settings system)
I show a simple list of my custom sound (like whatsapp or others app did) but instead of putting its on the app tab o same I'd like to put in my preferences.
When user selects a sound (ringtone) I'd like to play the selected sound (like a preview).
Is it possible ? No problem with the list, but I have no idea to handle the click.

If you are talking about the iOS preferences application, then no, it is not possible. You cannot modify the operation of this application to run your own code.
If you want to play a sample of the selected sound then you will need to implement this in a preferences section of your own app.

Here is how to play a short sound.
NSString *soundPath = [[NSBundle mainBundle] pathForResource:#"yourSound" ofType:#"aif"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath: soundPath], &soundID);
AudioServicesPlaySystemSound (soundID);

Related

AVAudioPlayer Control through WatchKit

I have a playercontroller view..in this view I am playing selected poem from an array which have collection of my poems.
Now when playing any poem I want to take control to push, play, next, previous and volume control from Apple Watch.
Here is my code for the iPhone which plays a poem:
if(btnClick == 1) {
self.lblTitle.text=[titles objectAtIndex:0];
[self.imgpoem setImage:[poemImages objectAtIndex:0]];
NSString *songurl=[poemcollection objectAtIndex:0];
[self playselectdpoem:songurl];
}
How can I add this functionality to the WatchKit Extension to control all the things?
To control the iPhone app from the watch, you have to use the openParentApplication method. You can take a look HERE, how to implement this method.
The same thing as sending data is to send a signal to the iPhone to do something - in your case, to Pause, Play, Stop ect.

iOS 8 Custom Keyboard that play sounds

I'm trying to build a custom keyboard for iOS 8 that a custom play sound when a key is pressed. I'm using a AVAudioPlayer and small mp3-files.
This works fine in the simulator, but on a real device I don't get any sounds.
RequestOpenAccess is enabled.
Please not that I'm not trying to play the default keyboard click sound, but a custom sound. Most existing questions seems to be about the default system sound.
edit: I've also tried using .caf and .aiff files and loading and playing them with SystemSoundID.
This snippet plays custom sound in my keyboard project.
NSString *soundPath = [[NSBundle mainBundle] pathForResource:#"your_custom_sound"
ofType:#"mp3"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath: soundPath], &soundID);
AudioServicesPlaySystemSound (soundID);
Cited from:
How to play tock sound when tapping custom keyboard buttons
I'm positive this is not your case but it often happens that the sound on the device is turned off. I made the mistake searching for an hour why sound didn't work. If it could only be that, it would be a quick fix ;)

iOS: how to conveniently store and play many mp3 files

I have a program with about 2000 short mp3 files. I am now storing all those file into folder Supporting Files and when I want to play I call this function:
-(void)playSound:(NSString *)mySoundFileName{
NSString *filePath = [[NSBundle mainBundle] pathForResource:mySoundFileName ofType:#"mp3"];
if ([NSData dataWithContentsOfFile:filePath]) {
url = [NSURL fileURLWithPath:filePath];
audioPlayer = [[AVAudioPlayer alloc]
initWithContentsOfURL:url
error:nil];
[audioPlayer play];
}
}
However, the first time I play the sound, it always takes long time to search/load the file. More specifically, after pressing "play sound" button to play sound, I have to wait for at least 5 seconds until it plays. It is OK to play other sound after that, i.e, it play almost immediately when I press "play sound" button. Do you have any suggestion to store and play those many files more efficiently? Thank you very much
It can sometimes take an undesirable amount of time for AVAudioPlayer to start playing initially. A good way to solve this is to make the initial alloc/init before you call play. This way the player is ready to play before the user presses the play button. Additionally, calling [player prepareToPlay]; before play will help improve performance slightly.

AudioServicesPlaySystemSound Volume on iPad

in my application I use AudioServicesPlaySystemSound to play little caf files.
When run my app on the iPhone and I change volume by lateral buttons, the app's sound changes
too, but on iPad the sound's volume in my app is always the same.
Maybe because on the iPhone is the ring volume, instead on the iPad is device volume.
How can I obtain same iPhone behavior on iPad?
Excuse me for my bad English....
I had the same problem but if you change the system sounds volume with buttons all the system sounds will be modified along with your app's. I found this really annoying.
The solution is to use AVAudioPlayer in place of AudioServices: as easy, but way more versatile. And there you can finely tune the volume for each sound, programmatically.
NSURL *soundurl = [[NSBundle mainBundle] URLForResource: #"mysound" withExtension: #"caf"];
AVAudioPlayer *mySoundPlayer =[[AVAudioPlayer alloc] initWithContentsOfURL:soundurl error:&error];
mySoundPlayer .volume=0.4f; //between 0 and 1
[mySoundPlayer prepareToPlay];
mySoundPlayer.numberOfLoops=0; //or more if needed
[mySoundPlayer play];

iOS audio samples play only on earphone output

I'm developing a program that plays a short sample when a button is pressed. The problem is that it only plays through earphone output and not through the device's speaker. I've tried .wav and .aiff and AVAudioPlayer and SystemSoundID. On the simulator I can hear the sound. I'm using iPod Touch 4th gen. running iOS 4.1. Example code:
NSString *soundFile = [[NSBundle mainBundle] pathForResource:#"button" ofType:#"wav"];
NSURL *url = [NSURL fileURLWithPath:soundFile];
AudioServicesCreateSystemSoundID( (CFURLRef)url, &buttonID);
AudioServicesPlaySystemSound( buttonID );
Edit (solution found): I tried with another .wav file and it worked. Odd, because the original .wav's format is supported by iOS.
Sounds like you've solved the issue, but as a heads-up, you should only be using SystemSoundID style playback for user interface related sounds.
If the audio is a key part of your app, you need to set the appropriate AVAudioSession category and use (for example) the AVAudioPlayer playback methods.
Then again, this might not be relevant. :-)

Resources