abdus.me
abdus.me

Reputation: 1819

"Plays Sound" Property of UIButton in Interface Builder

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

Upvotes: 3

Views: 2374

Answers (3)

RonH
RonH

Reputation: 514

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.

Upvotes: 2

iDev
iDev

Reputation: 23278

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,

  1. Adopt the UIInputViewAudioFeedback protocol in your input view class.
  2. 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.

Upvotes: 8

Paras Joshi
Paras Joshi

Reputation: 20551

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...

Upvotes: 1

Related Questions