Faraz Haider
Faraz Haider

Reputation: 128

iphone sdk button sound

i want to add a sound to button please help me with this.

Upvotes: 0

Views: 380

Answers (3)

The deals dealer
The deals dealer

Reputation: 1016

- (IBAction)startPlayback:(UIButton *)sender {
   
       NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
       resourcePath = [resourcePath stringByAppendingString:@"/grabbag.m4a"];
       NSLog(@"Path to play: %@", resourcePath);
       NSError* err;

     
       player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:resourcePath] error:&err];

       if( err ){
           //bail!
           NSLog(@"Failed with reason: %@", [err localizedDescription]);
       }
       else{
           player.delegate = self;
           [player play];
       }
   
}

Upvotes: 0

Chandaboy
Chandaboy

Reputation: 313

 - (IBAction)startPlayback:(UIButton *)sender {
       
           NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
           resourcePath = [resourcePath stringByAppendingString:@"/grabbag.m4a"];
           NSLog(@"Path to play: %@", resourcePath);
           NSError* err;

         
           player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:resourcePath] error:&err];

           if( err ){
               //bail!
               NSLog(@"Failed with reason: %@", [err localizedDescription]);
           }
           else{
               player.delegate = self;
               [player play];
           }
       
     }

Upvotes: 0

James Bedford
James Bedford

Reputation: 28962

You can use the method - (void)playInputClick, found in the UIDevice class. You can access an instance of this class using the static method + (UIDevice *)currentDevice. Use this method to attatch the default input sound to your own custom UI.

Upvotes: 1

Related Questions