【发布时间】:2013-02-09 13:24:20
【问题描述】:
我正在尝试使用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 方法还显示文档目录中歌曲的正确计数。
但我不能玩。
我该怎么办?
【问题讨论】:
标签: ios cocoa-touch mpmusicplayercontroller mpmediaitemcollection