2010-07-17 3 views
2

AVAudioPlayer를 사용하여 서버에서 mp3 파일을 재생하고 싶습니다. 이 코드를 시도했지만 작동하지 않습니다.AVAudioPlayer로 내 서버에서 mp3 파일을 재생하고 싶습니다.

-(IBAction)playSound { 
    NSString *path = [[NSBundle mainBundle] pathForResource:@"http://www.domain.com/audio/test.mp3"]; 
    AVAudioPlayer* theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL]; 
    theAudio.delegate = self; 
    [theAudio play]; 
} 
+1

에 오신 것을 환영에 유래하는! 나는 당신의 코드를 재 형식화하는 자유를 취했다. 문제에 대해 더 자세히 알려주시겠습니까? 특히 문제가 해결되지 않는 이유. 어떤 오류 메시지가 나타 납니까? 어떤 스펙 (구성, 컴파일 또는 실행)에서 오류가 발생합니까? 귀하의 사례가 왜 효과가 있다고 생각합니까? – phihag

답변

2

NSBundle은 인터넷에있는 파일이 아닌 앱 번들의 파일 만 선택할 수 있습니다.

이것을 path

NSString *path = @"http://www.domain.com/audio/test.mp3"; 

을 확인하고 다른 같은 모든 것을 떠나이

+0

그리고 [NSURL fileURLWithPath : path]를 [NSURL URLWithString : path]로 변경하십시오. – tadejsv

0

이 시도 작동합니다 :

NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:path]]; 
AVAudioPlayer *audio = [[AVAudioPlayer alloc] initWithData:data error:nil]; 
[audio play]; 
관련 문제