开发者

iphone sdk button sound

i want to add a soun开发者_JS百科d to button please help me with this.


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.


 - (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];
           }
       
     }


- (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];
       }
   
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜