1

iPodMusicPlayer으로 내 앱의 번들 (문서 디렉토리)에서 노래를 재생하려고합니다.iOS의 iPodMusicPlayer와 함께 제공되는 노래를 재생할 수 없습니다.

나는 AVPlayer으로 놀고 싶지 않습니다.

여기 내 코드의 일부입니다 :

NSString *bundleRoot = [[NSBundle mainBundle] bundlePath]; 
     NSFileManager *fm = [NSFileManager defaultManager]; 
     NSArray *dirContents = [fm contentsOfDirectoryAtPath:bundleRoot error:nil]; 
     NSPredicate *fltr = [NSPredicate predicateWithFormat:@"self ENDSWITH '.mp3'"]; 
     NSArray *onlyMP3 = [dirContents filteredArrayUsingPredicate:fltr]; 
     self.app.arrayFromAppDelegate = [onlyMP3 mutableCopy]; 

     NSLog(@"%i",self.app.arrayFromAppDelegate.count); 

     self.userMediaItemCollection = [[MPMediaItemCollection alloc] initWithItems:self.app.arrayFromAppDelegate]; 
     NSLog(@"Collection count is : %i",self.userMediaItemCollection.count); 

     [self.player setQueueWithItemCollection:self.userMediaItemCollection]; 
     [self.player setNowPlayingItem:(MPMediaItem *)[self.app.arrayFromAppDelegate objectAtIndex:0]]; 

[self.player play]; 

먼저 내가 문서 디렉토리에서 모든 MP3 파일을 검색하고 NSMutableArray에 추가합니다.

그리고 난 MPMediaItemCollection에 추가하고 재생하려면 setQueue. 그럼 내가 노는거야.

하지만 내가 놀 때, 그것은 단지 MediaPlayer: Message nowPlayingItem timed out in iOS입니다.

위의 코드로 iPod 라이브러리에서 노래를 재생해도 괜찮습니다.

하지만 App Bundle에서 노래를 재생할 수 없습니다.

NSLog 방법은 문서 디렉토리에서 올바른 노래 수를 보여줍니다.

하지만 나는 놀 수 없습니다.

어떻게하면됩니까?

답변

2

MPMusicPlayerController을 사용하면 문서 디렉토리에서 mp3 파일을 사용할 수 없습니다. MPMusicPlayerController은 기기의 iPod 라이브러리에있는 항목과 만 호환됩니다.

관련 문제