2013-02-27 9 views
0

mp3 파일을 재생해야하는 앱을 제작하고 있습니다. 그 문제에 관해서, 나는 다른 사람들이 읽고있는 표시를 따라 AVAudioPlayer를 사용하고있다. 하지만 내 문제는 코드 (iOS 벨소리 첨부)가 iOS 시뮬레이터에서 작동하지만 내 iPhone에서 사용하려고하면 작동하지 않는다는 것입니다. 여러분 중 누구도이 문제를 해결할 수 있기를 바랍니다. 발행물.AVAudioPlayer는 iOS 시뮬레이터에서 재생되지만 iPhone에서는 재생되지 않습니다.

파일 .H :

#import "UIKit/UIKit.h" 
#import "AVFoundation/AVFoundation.h" 

@interface ViewController : UIViewController <AVAudioPlayerDelegate> 

@property (strong, nonatomic) AVAudioPlayer *player; 

@end 

파일하는 .m은 : 오디오 (또는 이미지) 시뮬레이터 (도시) 일 때

#import "ViewController.h" 

@implementation ViewController 
@synthesize player; 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"beep_7" ofType:@"mp3"]; 
    NSLog(@"Audio path: %@", soundFilePath); 

    NSError *error; 
    self.player =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:soundFilePath] error:&error]; 

    if (error) { 
     NSLog(@"Error in audioPlayer: %@",[error localizedDescription]); 
    } 
    else { 
     [self.player setDelegate:self]; 
     [self.player setNumberOfLoops:3]; //just to make sure it is playing my file several times 
     self.player.volume = 1.0f; 

     if([self.player prepareToPlay]) //It is always ready to play 
      NSLog(@"It is ready to play"); 
     else 
      NSLog(@"It is NOT ready to play "); 

     if([self.player play]) //It is always playing 
      NSLog(@"It should be playing"); 
     else 
      NSLog(@"An error happened"); 
    } 
} 

-(void)audioPlayerDecodeErrorDidOccur: (AVAudioPlayer *)player error:(NSError *)error { 
    NSLog(@"audioPlayerDecodeErrorDidOccur -> Error in audioPlayer: %@",[error localizedDescription]); 
} 
-(void)audioPlayerDidFinishPlaying: (AVAudioPlayer *)player successfully:(BOOL)flag{ 
    NSLog(@"audioPlayerDidFinishPlaying"); 
} 
-(void)audioPlayerBeginInterruption:(AVAudioPlayer *)player{ 
    NSLog(@"audioPlayerBeginInterruption"); 
} 
-(void)audioPlayerEndInterruption:(AVAudioPlayer *)player{ 
    NSLog(@"audioPlayerEndInterruption"); 
} 

@end 

답변

2

우선 확인 장치에없는 것은 액세스하려는 오디오 파일의 철자입니다.

Mac OSX는 대소 문자를 구분하지 않으므로 iOS는 코드에서 iMage.png 철자로 표시된 이미지와 image.png이 시뮬레이터에는 표시되지만 iPhone에는 표시되지 않음을 의미합니다.

확인해야 할 다른 사항은 실수로 iPhone의 물리적 음소거 버튼을 눌렀을 수 있다는 것입니다. (지난 주에 일어난 일)

희망이 있습니다.

+3

고마워, 나는 물리적 인 음소거 botton을 쳤다. 그리고 나는 그것에 관해 실현을 didnt한다! 감사 – rubrin

관련 문제