开发者

iphone sdk button sound

开发者 https://www.devze.com 2023-02-09 22:51 出处:网络
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 sta

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

精彩评论

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

关注公众号