2014-06-23 2 views
0

을 만들어 검색 I이 파일을 만들기위한 다음 코드를는 파일의 경로가 IOS

내가 생성 된 파일의 경로를 얻을 필요가
NSString *name = @"dtmf-received.aif"; 

//create file 
NSString *cachesFolder = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject]; 
fileName= [cachesFolder stringByAppendingPathComponent:name]; 

. 다음 코드는 작동하지 않습니다. 내가 뭘 놓치고 있니?

NSString* filePath = [[NSBundle mainBundle] pathForResource:@"dtmf-received.aif" 
                 ofType:@""]; 

답변

0

캐시 디렉토리와 앱 번들 디렉토리가 다릅니다. 두 곳에서 같은 코드를 사용하면 올바르게 작동합니다.

+0

동일한 코드를 사용한다는 것은 무엇을 의미합니까? 예제를 추가해 주시겠습니까? –

+0

첫 번째 코드는 정확하므로 어디서나 사용하십시오. – trojanfoe

+0

이 NSString *으로 변경했습니다. filePath = [[NSSearchPathForDirectoriesInDomains (NSCachesDirectory, NSUserDomainMask, YES) lastObject] pathForResource : @ "dtmf-received.aif"ofType : @ "aif"]; 그리고 지금 나는 충돌이있다. –

0
Here it is an example how you can play your aif file: 


-(void) playSound { 
    NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"dtmf-received" ofType:@"aif"]; 
    SystemSoundID soundID; 
    AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath: soundPath], &soundID); 
    AudioServicesPlaySystemSound (soundID); 
    //[soundPath release]; 
    NSLog(@"soundpath retain count: %d", [soundPath retainCount]); 
} 
+0

감사합니다! 또한 ios에서 10 562 바이트의 빈 파일을 어떻게 만들 수 있는지 알려주실 수 있습니까? 이 파일은 스트림이 열리면서 열리고 스트림 쓰기로 일부 데이터가 추가됩니다. –

+0

이것은 필요한 정확한 크기입니까? – doruvil

0

이 시도 :

 NSString *fileLocation = [[NSBundle mainBundle] pathForResource:@"dtmf-received" ofType:@"aif"]; 
     NSURL *vedioURL =[NSURL fileURLWithPath:fileLocation]; 
     MPMoviePlayerViewController *videoPlayerView = [[MPMoviePlayerViewController alloc] initWithContentURL:vedioURL]; 
     [self presentMoviePlayerViewControllerAnimated:videoPlayerView]; 
     [videoPlayerView.moviePlayer play]; 
+0

무엇이이 번들입니까? –

+0

시도해보세요. – svmrajesh

+0

고마워요! 또한 ios에서 10 562 바이트의 빈 파일을 어떻게 만들 수 있는지 알려주실 수 있습니까? 이 파일은 열어서 열리고 스트림 쓰기로 일부 데이터가 추가됩니다. –

0

을 당신은 .AIF에게로 '유형'으로 설정해야 this->

NSString* filePath = [[NSBundle mainBundle] pathForResource:@"dtmf-received" 
                ofType:@"aif"]; 

을 시도하고 프로젝트를 확인 문자열

NSString* filePath = [[NSBundle mainBundle] pathForResource:@"dtmf-received.aif" 
                ofType:@""]; 

을 '번들 리소스 복사'섹션에 파일이 필요합니다.

Copy Bundle Resouces

+0

재생 해 주셔서 감사합니다. 또한 dtmf-received.aif를 작성해야합니다. 메인 번들에 파일을 생성하도록 도와 주시겠습니까? –

+0

파일을 '번들 리소스 복사'로 드래그 – LLIAJLbHOu

+0

ios에서 특정 크기의 파일을 만들 수 있습니까? –

관련 문제