2013-07-22 2 views
0

Help guy : 저는 AVAudioPlayer로 오디오를 얻으려고 모든 노력을했습니다. 어떤 이유로 iPhone 시뮬레이터에서 재생되지 않습니다. 코드는 다음과 같습니다.내 앱에서 오디오가 작동하지 않는 것 같습니까? AVAudio 프레임 워크를 사용하고 있습니다.

#import "ViewController.h" 
#import "AVFoundation/AVFoundation.h" 

@interface ViewController() 
{ 
    AVAudioPlayer *avPlayer; 
} 

@end 

@implementation ViewController 
@synthesize myProgressView; 
@synthesize sliderVolumeOutlet; 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    NSString *stringPath = [[NSBundle mainBundle]pathForResource:@"audioapp" ofType:@"mp3"]; 
    NSURL *url = [NSURL fileURLWithPath:stringPath]; 

    NSError *error; 

    avPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:&error]; 
    [avPlayer setNumberOfLoops:1]; 

    [avPlayer setVolume:self.sliderVolumeOutlet.value]; 
    [NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(updateProgress) userInfo:nil repeats:YES];  
} 

노래 자체가 프로젝트 파일에 있습니다. 실제로 내가 잘못하고있는 것을 실제로 알지 못합니다.

+0

하지 엑스 코드 질문 해보십시오. –

답변

0

오류에 대한 확인하고

-(IBAction) playAudio{ 
     NSError *error; 
     NSURL *url = [NSURL fileURLWithPath:self.audioName]; 

     audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error]; 
     audioPlayer.delegate = self; 
     if (error) 
      NSLog(@"Error: %@", [error localizedDescription]); 
     else 
      [audioPlayer play]; 
} 
+0

Xcode 관련 질문이 아니라면 죄송합니다. 나는 이것에 아주 새롭다 다만 실험하는 것을 시도하고있다 :) 대답을위한 감사합니다 –

+0

유감스러운 녀석은 다만 약간 설명을 여기에서 필요로한다. 오류는 발생하지 않지만 사운드는 시뮬레이터에서 재생되지 않습니다. .h 파일에서 버튼을 설정 한 부분 일 수 있습니까? UIViewController에 @property (약한 비 원자) 함께 IBOutlet UIProgressView * myProgressView; 그 코드는 '@ 인터페이스의 ViewController를 인걸요 @property (weak, nonatomic) IBOutlet UISlider * sliderVolumeOutlet; - (IBAction) sliderVolumeAction : (id) 보낸 사람. - (IBAction) stopButton : (id) 보낸 사람. - (IBAction) pauseButton : (id) 보낸 사람; - (IBAction) playButton : (id) 보낸 사람; @ end' 도움 주셔서 감사합니다. :) –