"Plays Sound" Property of UIButton in Interface Builder - iphone

in interface builder there is property of UIButton under Accessibility that says "Plays Sound".
Can any one explain what is this. Actually i am making an application which play sound on every button click and i can disable sounds from setting screen. Will this property of UIButton can help me?
Thanks

You can use [[UIDevice currentDevice] playInputClick]; to play the keyboard input click sound which is available in UIDevice. Check this apple documentation for more details.
You need to do the following for this,
Adopt the UIInputViewAudioFeedback protocol in your input view class.
Implement the enableInputClicksWhenVisible delegate method to return YES.
Do this in UIView class,
#interface MyView : UIView <UIInputViewAudioFeedback>
Then implement enableInputClicksWhenVisible method
- (BOOL)enableInputClicksWhenVisible
{
return YES;
}
If you are facing issues with this, you can check this.

The answer to your original question of whether you can use the Plays Sound 'property' (it's probably not actually a property) to make your buttons play sound is: No. Plays Sound is a 'Trait' that describes the Accessibility of an object (in this case a button) for people who are using VoiceOver (i.e. most likely people who are blind). You can read the documentation here.

hey you want to play sound on button click event then use bellow code also..
-(IBAction)playSound:(id)sender
{
NSString *path = [[NSBundle mainBundle] pathForResource:#"adriantnt_release_click" ofType:#"mp3"]; /// set .mp3 name which you have in project
AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate=self;
[theAudio play];
}
and use like bellow..
-(IBAction)yourButton_Clicked:(id)sender
{
[self performSelector:#selector(playSound:) withObject:sender];
//your code write here
}
Note: Add AudioToolbox.framework Framework And also import
#import<AVFoundation/AVAudioPlayer.h> in .h file and also add Delegate AVAudioPlayerDelegate in .h file
i hope this help you...

Related

Preview of the ringtone

This is my first question, & i am new to iOS Development. I wanted to ask how can i play preview of the ringtone when tapped on a cell in table view on iphone.
Basically i am trying to write an app which allows downloading of ringtone from my server on iphone, in that i want to add a preview feature, through which person will be able to listen the tone if he likes he will download. then he will be able to set it as ringtone.
I have managed to get the links of tones, on my server in a table view. now i want to play preview. how can i do that??
Request: please describe as i am newbie. not an advance programmer.
please ignore my mistakes.
Regards,
Malhaar
edit: i am using this code..
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSURL* musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:[[ringArray objectAtIndex:indexPath.row]getName]
ofType:#"m4r"]];
AVAudioPlayer *click = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile error:nil];
[click play];
[click release];
}
There are not too many details given, but at a high level, you would want to do the following:
1) Implement the "tableView:didSelectRowAtIndexPath:" delegate method of UITableView in order to respond to touches on the table cells.
2) Obtain the data for the ringtone. You could do this using NSURLConnection.
3) Play the ringtone using AVFoundation, specifically AVAudioPlayer.

objective c MPMoviePlayerController wont work on iOS 4.3

Ive got this code from an ebook tutorial on embedding MPMoviePlayerController from a VIEW object but it just dont work at all on iOS 4.3, it just gives me a black screen. I've tried looking at other sources and they have the same source code. Can anyone help me on finding what is the problem in this code.
Thanks
- (IBAction)playMovie:(id)sender {
NSString *filepath = [[NSBundle mainBundle] pathForResource:#"shawarma" ofType:#"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[player.view setFrame: movieHolder.bounds];
[movieHolder addSubview: player.view];
[player play];
}
My VIEW object has a dimension of 400 x 300.
From the MPMoviePlayerController class reference guidelines Consider
a movie player view to be an opaque structure.
You can add your own custom subviews to layer content on top of the
movie but you must never modify any of its existing subviews.
In addition to layering content on top of a movie, you can provide
custom background content by adding
subviews to the view in the backgroundView
MPMoviePlayerController it self has a property view to present the video
Hope this LINK might help you
There is no issue with MPMoviePlayer and ios 4.3 i am working on an application that plays movie from a server and this is working fine for me. I request you to check
Path of you resource try some hardcode path.
Frame of the MoviePlayer.
Thanks

Iphone SDK: sound problems

i've created a drum app. As of now, the app's kinda satisfying but not great.
The problem is a strange delay or "lag" that sometimes happens when i press my sound buttons. When i spam a button it begins to freeze, when unfreezed again, it plays the same sound stacked on itself about 4 times :(
What am i doing wrong?
Are my samples bad?
Should i use an imageView and touchesBegan to simulate the buttons?
This is the code that i use to play a sound when a button is pushed:
- (IBAction) HHC {
NSString *path = [[NSBundle mainBundle] pathForResource:#"HHClosed"ofType:#"wav"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef) [NSURL fileURLWithPath:path], &soundID);
AudioServicesPlaySystemSound (soundID);
}
Please give me some good advice :)
Thanks in advance
-DD
Try doing this and see if it makes your performance better.
In your .h file declare this:
SystemSoundID soundID;
In your .m file in the -viewDidLoad method add this code:
-(void) viewDidLoad {
NSString *path = [[NSBundle mainBundle] pathForResource:#"HHClosed"ofType:#"wav"];
AudioServicesCreateSystemSoundID((CFURLRef) [NSURL fileURLWithPath:path], &soundID);
}
And in the method you showed just keep this one line of code:
- (IBAction) HHC {
AudioServicesPlaySystemSound (soundID);
}
Let me know if that makes the freezing going away. If it doesn't try Core Audio
Every time you hit the button you are loading the sound file from the filesystem, bringing it into memory, and then playing it.
This is very inefficient. Your audio samples should already be loaded in memory at launch, so they don't need to be read in from the filesystem. Also, AudioServicesPlaySystemSound isn't really designed for this kind of usage - its main purpose is playing back short alert sounds (ie, a system alert). If you need low-latency audio playback you should be looking at the Core Audio framework instead.
For low latency sound appropriate for a drum app, you will want to use the RemoteIO Audio Unit API, which is not simple. You will need to know how to handle, buffer and mix PCM sound samples. Start by reading a book on digital audio technology.

MPMoviePlayerController problem when play a movie

i put a movie when my application will lunch . just like gameloft games .
so when application has lunched , movie plays fine but before the move plays .. my FirstViewController xib file show first then moview start to play ! why ?
here is my code :
- (void)applicationDidFinishLaunching:(UIApplication *)application {
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:#"movie" ofType:#"m4v"];
NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *IntroMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
IntroMovie.movieControlMode = MPMovieControlModeHidden;
[IntroMovie play];
}
Your question is a little unclear, but what I think you are asking is why your movie is not playing when the application launches before the user sees the controls and items in your XIB file. If this is correct, then this is the normal behavior as typically the application will launch and only then call the function you have (applicationDidFinishLaunching). There is no guarantee that you will get that function called before the controls have loaded and are viewable on the screen all the time.
It is bad form to start you application with a movie, but if you want to then you have to deal with the fact that there will potentially be a default image or even your controls that you put in your XIB file.
One way to start with a movie, is that you must hide or delete everything in the XIB file so the screen will appear blank when the application loads. Then, when you application calls the applicationDidFinishLaunching function the user will not have seen your application and the first thing they will see is the movie. When the movie is finished playing, you will need to have a notification listener instruct your application to show the controls for your application or switch to another XIB file that has the app controls within it.
I hope this helps.

Audio volume stuck at low level and adjusting volume has no effect?

When I use my app (on the device), the actual volume works OK for a while, but after a few days it seems to get 'stuck' at a low level.
Adjusting the volume rocker has no effect - and it shows 'Ringer' text. I've noticed that other people's apps are similarly affected if they show the 'Ringer' text when adjusting the volume. But apps which don't show 'Ringer' text are not affected by this.
How would I remove the 'Ringer' text and get my app to respond properly to different volumes?
I found some code on Apple's forums which fixes it. You have to use the AVFoundation.framework and put a bit of code into your app delegate. And put an audio file called 'blank.aif' into your project. Basically, it's a hack which prepares a file to play, but then never plays it. This fools the system into thinking that sound is being played all the time, which allows the user to use the main volume control.
#import <AVFoundation/AVFoundation.h>
//...
-(void)applicationDidFinishLaunching:(UIApplication *)application {
//volume control hack
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:#"blanksound" ofType:#"aif"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:soundFilePath];
AVAudioPlayer *volumeHack = [[[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil]retain];
[fileURL release];
[volumeHack prepareToPlay];
// other applicationDidFinishLaunching stuff
}