2012-03-12 2 views
0

MP3 오디오 파일을 재생하려고하는데 파일이 웹 서버의 사용자에 의해 업로드되고 해당 파일의 URL을 얻은 다음 해당 파일을 재생해야합니다. 그러나 나는 그것에 성공하지 못하고있다. 여기 내 코드는iphone dev mp3 파일이 av 오디오 플레이어를 사용하여 재생되지 않음

NSURL * url = [NSURL URLWithString : url1]; NSData * theData = [NSData dataWithContentsOfURL : url]; newPlayer = [[AVAudioPlayer alloc] initWithData : theData 오류 : 없음]; [newPlayer play];

URL은

http://mqm.designers99.com/Notification/mp3_files/1331551313_1919.mp3

Plz은 같다.

NSURL *url = [NSURL URLWithString:url1]; 
NSData *theData = [NSData dataWithContentsOfURL:url]; 
NSError *error = nil; 
newPlayer = [[AVAudioPlayer alloc] initWithData:theData error:&error]; 
if (error == nil) { 
    NSLog(@"AVAudioPlayer start playing"); 
    [newPlayer play]; 
} else { 
    NSLog(@"%@", error); 
} 

모든 "행운"내가 여기 고맙습니다 붙어 및

+0

P. 이 경우'-initWithData : error :'인스턴스 메소드가 필요하지 않습니다. 단지 -initWithContentsOfURL : error :' – basvk

+0

을 배포하고 있습니까? – basvk

+0

운이 없다 오히려 그것은이 오류를 표시하고 있습니다. 작업을 완료 할 수 없습니다 (OSStatus -43) –

답변

1

시도 '읽기'오류 간주하고 사촌 나를 인도?

+0

괜찮을 겁니다. –

+0

아무것도 표시하지 않습니다. [error localizedDescription ] 경고가 표시 되더라도 해당 경고가 표시되지 않음 –

+0

오히려 해당 오류가 작업을 완료 할 수 없음 (OSStatus -43) –

0

는 AVFoundation을 포함하고 AudioToolBox은 .H 파일에서 해당 프레임 워크에 대한

가져 오기 헤더를 프레임 워크

#import<AVFoundation/AVFoundation.h> 
    #import<AudioToolbox/AudioToolbox.h> 

인스턴스화 AVAudioPlayer,

AVAudioPlayer *player 

사용 플레이 audio.It의가 제대로 작동이 코드 나

NSString *[email protected]"http://mqm.designers99.com/Notification/mp3_files/1331551313_1919.mp3"; 

url1=[url1 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];//Encode your url 

NSLog(@"after encoding========:%@",url1); 
NSURL *url = [NSURL URLWithString:url1]; 
NSData *theData = [NSData dataWithContentsOfURL:url]; 
player = [[AVAudioPlayer alloc] initWithData:theData error:nil]; 
[player play]; 

편집 : 인코딩하지 않으면 주어진 URL도 잘 재생됩니다.

+0

URL을 인코딩하거나 AudioToolbox 프레임 워크를 가져올 필요가 없습니다. – basvk

+0

@basvk : 안녕하세요. 이제 편집되었습니다. – iphonecool

+0

아직 성공하지 못했습니다. ( –

관련 문제