2016-06-19 2 views
0

내 번들에 오디오 파일이 거의없고 그 이름을 UITableView에 표시하고 싶습니다. 사용자가 cell을 탭하면 해당 이름의 오디오 파일이 재생됩니다.번들에서 UITableView로 파일 표시 - iOS

enter image description here

내가 봤지만 내가 얻은 것은 Documents Directory에서 파일을 읽는 것이었다.

내 번들 파일을 어떻게 표시합니까?

도와주세요, 고마워요!

답변

1

먼저 앱의 리소스가 저장된 메인 번들 포인터가 있어야합니다. 이 포인터를 사용하여 mp3 확장자를 가진 모든 자원을 검색 할 수 있습니다. 당신은 다음과 같은 코드를 사용할 수 있습니다

NSBundle *mainBundle = [NSBundle mainBundle]; 
NSArray *paths = [mainBundle pathsForResourcesOfType:@"mp3" inDirectory:nil]; 

모든 경로의 마지막 요소는 각각의 MP3 파일의 파일 이름입니다.

자세한 내용은 Apple Bundle Programming Guide을 참조하십시오. 의 tableview의 didselectrowatindexpath 방법에

1

코드

NSString * soundSelected = cell.textlabel.text; 
    NSString *path = [NSString stringWithFormat:@"%@/%@.mp3", [[NSBundle mainBundle] resourcePath],soundSelected]; 
     NSURL *soundUrl = [NSURL fileURLWithPath:path]; 

     AVAudioPlayer* cellTapSound = [[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:nil]; 
     [cellTapSound play]; 
쓰기