Anyone know if it's possible to use custom sounds on the iTouch piezo speaker? - iphone

I'm obviously not trying to play full spectrum audio, but is there some way to customize the iPhone/iTouch system alert sounds to play a little melody on the piezo speaker? The functionality is clearly present, so I guess the question is has Apple made it available for developer use...
Thanks,
-S

There are quite a few predefined sounds you can use in the 0-2000 range. For example, the keyboard click can be called like such:
AudioServicesPlayAlertSound(1104);
There is also a way to play a custom melody on the first-generation iPod touch, but it's not pretty.

It isn't. Sorry.
Only thing you can do from an application is this (you can use any SoundID for this, really):
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
Discussion
Depending on the particular iPhone OS device, this function plays a short sound and may invoke vibration. Calling this function does the following on various iPhone OS devices:
iPhone—plays the specified sound and, if the user has configured the Settings application for vibration on ring, invokes vibration.
iPod touch, original—plays a short alert melody.
iPod touch, 2nd generation—plays the specified sound.

Related

Assign alert tone for UILocalNotification from available sounds in iphone

I am working on an app that used UILocalNotification. I wanted to select sound from default sounds that came with iPhone. How can i list down sounds for assign as the alert tone.
There is one standard sound for notification from system (UILocalNotificationDefaultSoundName). You can play any custom sound shorter than 30 seconds. So, if you can download any native sound from ios from anywhere, you will be able to use it as custom sound. Documentation

iOS determine if VoiceOver is still talking

Is there a way to determine whether VoiceOver is currently announcing and when it stops. I've tried UIAccessibilityVoiceOverStatusChanged but my understanding is that this is only if you switch VoiceOver on or off. Any help would be greatly appreciated. thanks.
We use otherAudioIsPlaying, the problem is some app's running in the background like some pedometer monitors etc. turn on the audio it seems and never release it so even though nothing is actually being spoken or played otherAudioIsPlaying always returns 1 until you remove the other application from the background. So now not only can you not play music but you have no idea that another application in the background will mess up this test. Apple really needs to put in an API to determine if Voice Over is currently speaking or not.
These are all the Accessibility booleans that I found in the documentation:
UIAccessibilityPostNotification
UIAccessibilityIsVoiceOverRunning
UIAccessibilityIsMonoAudioEnabled
UIAccessibilityIsClosedCaptioningEnabled
UIAccessibilityRegisterGestureConflictWithZoom
I don't think that there are any booleans to do what you are talking about.
You could use the audio session's "OtherAudioIsPlaying" property to check if another system process is using the audio hardware at the moment. It should be "true" if VoiceOver is speaking and "false" if not.
Actually this might not work properly if the user is playing music in the background. But most users running VoiceOver will usually not have any other audio enabled permanently, since it makes it harder to understand what VoiceOver is saying.
Here is an example for usage:
UInt32 otherAudioIsPlaying;
UInt32 propertySize = sizeof(otherAudioIsPlaying);
AudioSessionGetProperty(kAudioSessionProperty_OtherAudioIsPlaying,&propertySize, &otherAudioIsPlaying);
if(otherAudioIsPlaying) {
// other application is generating sound output (including VoiceOver)
// but might also be any other app (like iPod App)
}

How to disable iOS System Sounds

I am working on an iPad app that connects with an accessory that plays sound. When the iPad is connected to the accessory, I would like to mute all system sounds but allow other sounds (iPod).
Part of the reason for this is that the accessory is such that it is intended to be used during a live performance. Clearly it would be annoying to have e-mail, alert, or any other system sound running through and amplified (crazy loud).
I have looked at using AVAudioSession (read Audio Sessions to learn more) and tried all of the AudioSessionCategories. None of these categories will mute the system sound, instead it will only allow you to mute application sounds (iPod) - not useful for my purposes.
I also found docs on "System Sound Services", but this only allows you to play system sounds. There is no api here to disable system sounds while your app is running.
A final note, we have made it easy to adjust the iPad level (volume) by including the MPVolumeView, but we expect the user to want to play iPod music. If while playing iPod music (or music from another app) and an e-mail comes through, you'd be amazed how LOUD / ANNOYING that e-mail suddenly becomes when going through our accessory. It's even possible it could damage equipment. :D
It is possible to change the system sounds, which turns out to be the ringer btw, using the AVSystemController. However, AVSystemController exists in the private Celestial framework. Since this framework is referenced by UIKit, it is still possible to use this class without directly referencing it.
Apple prohibits using private API's, so that alone makes this a bad idea. Given my circumstance, I think they may make an exception, BUT I will likely abandon this course since after taking it I realized that it didn't fix my problem. It does indeed mute the sounds, but as soon as I plug in to my accessory, the system sounds come out at max volume even though the ringer volume is set to 0. This leads me to believe the answer to solving my problem is in the MFI documentation.
Anyhow, here is how to change the ringer using private framework / api (which will get your app rejected without some kind of special permission).
short answer:
[[AVSystemController sharedAVSystemController] setVolumeTo:0 forCategory:#"Ringtone"];
answer without having to directly reference Celestial frameork / AVSystemController.h:
- (void) setSystemVolumeLevelTo:(float)newVolumeLevel
{
Class avSystemControllerClass = NSClassFromString(#"AVSystemController");
id avSystemControllerInstance = [avSystemControllerClass performSelector:#selector(sharedAVSystemController)];
NSString *soundCategory = #"Ringtone";
NSInvocation *volumeInvocation = [NSInvocation invocationWithMethodSignature:
[avSystemControllerClass instanceMethodSignatureForSelector:
#selector(setVolumeTo:forCategory:)]];
[volumeInvocation setTarget:avSystemControllerInstance];
[volumeInvocation setSelector:#selector(setVolumeTo:forCategory:)];
[volumeInvocation setArgument:&newVolumeLevel atIndex:2];
[volumeInvocation setArgument:&soundCategory atIndex:3];
[volumeInvocation invoke];
}
Using MediaPlayer framework, we can set the level of SYSTEM sound
[[MPMusicPlayerController applicationMusicPlayer] setVolume:0];
Best you can do is encourage your users to go into airplane mode.

iPhone playing sounds while in the background

I have a small application which is much like a clock. It has been working great on IOS3, but now I am updating it to iOS4.
What I want to do in iOS4 is to let it play a sound any giving time. For instance, if I set it to play at 4.00 PM I want it to play a sound, a sound from the application not from the OS. This works if the app is launced, but if the user went back to the home screen I want the same to happen.
It is OK if a UIAlertView pops up istead of the application.
How can I do this?
Best regards,
Paul Peelen
Sounds like you'll need to use a local notification:
http://developer.apple.com/iphone/library/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction/Introduction.html
and
http://developer.apple.com/iphone/library/documentation/iPhone/Reference/UILocalNotification_Class/Reference/Reference.html#//apple_ref/occ/cl/UILocalNotification
Read http://developer.apple.com/iphone/library/documentation/iphone/conceptual/iphoneosprogrammingguide/BackgroundExecution/BackgroundExecution.html.
What you want is UIApplication setKeepAliveTimeout:handler: which let you register a handler that will be called. You can use that to start playing audio. (Of course, compute the timeout when your app goes to background)
EDIT: Use UILocalNotification as andy said.
Two things you could possibly try under iOS 4.
Local Notifications can pop up an alert and play a short sound.
Another power hungry option is to register as a background music player, and play silence until time for the alarm to go off, then add your chosen sound to the "music" output. This will fail if the user switches to another media player app.

Programmatically powering off an iPhone?

Is it possible to programmatically power off an iPhone or does Apple disallow this?
If Apple disallows this, is it possible to programmatically mute the sound on an iPhone?
The iPhone applications you create with the official SDK are sandboxes in and of themselves. Walled off sandboxes with barbed wire.
You won't be able to turn off the power. And muting sounds other than your own applications' sounds amounts to being able to turn off the iPod playback.
I don't have any evidence for that, but this would involve modifying the "UserExperience" - which is something that Apple never would allow (and why still many people jailbreak their phones).
And this involves "power off" as well as "mute sound" - because both could destroy the UX (you wait for an important call, but application X broke the sound).
Is it possible to programmatically power off apple iPhone or does apple dissalow this. If apple disallow this is it possible to programmatically mute the sound on iPhone?
Apple prevents you from affecting the functionality of other apps and the core phone functions. When in doubt, if you want to do something phone-wide, you can't.
Plus, to mute the phone, you'd also have to figure out some way of making the physical mute switch on the side of the phone match the phone's mute setting. That's not going to happen with software!
I'm not sure how powering down the device and muting the device are reasonable alternatives in your app, but the bottom line is that you can't power down the device. However, you can mute the sound of your own app or the iPod app using the MPMusicPlayerController class.
The code looks like this for your app:
MPMusicPlayerController *player = [MPMusicPlayerController applicationMusicPlayer];
player.volume = 0.0f;
And, this for the iPod:
MPMusicPlayerController *player = [MPMusicPlayerController iPodMusicPlayer];
player.volume = 0.0f;
Anything you do that affects anything external to your application wont make it through the approval process (besides push notifications). You can certainly mute the sound in your app by simply pausing, stopping, or setting the volume to zero for all sounds you are playing. If you mean make the phone be mute globally, no.
You can't turn the device off through software. You can set the music playback volume with the MPMusicPlayerController class, the docs suggest you can't change the volume of the
iPod player though.