2011-02-10 170 views

回答

0
- (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
- (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

您不能複製和粘貼代碼。您必須使用堆棧溢出的格式化選項。請改正。 – 2011-02-10 12:54:37

1

您可以使用類中的方法- (void)playInputClick。您可以使用靜態方法+ (UIDevice *)currentDevice訪問此類的一個實例。使用此方法將默認輸入聲音添加到您自己的自定義用戶界面中。