【问题标题】:Can't play songs from bundle with iPodMusicPlayer in iOS无法在 iOS 中与 iPodMusicPlayer 捆绑播放歌曲
【发布时间】: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


    【解决方案1】:

    使用MPMusicPlayerController,您不能使用文档目录中的mp3 文件。 MPMusicPlayerController 仅与设备 iPod 库中的项目兼容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-13
      • 1970-01-01
      • 2017-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多