以下代码块会导致错误消息:
2013-09-13 15:27:08.449 Mobile [746:5603] {MediaLibrary}回滚交易.
MPMediaQuery *mediaQuery = [MPMediaQuery songsQuery];
NSArray *collections = [mediaQuery collections];
Run Code Online (Sandbox Code Playgroud)
这是在iOS 7 GM的控制台中.
这在iOS 6中没有问题.
有谁知道这与iOS 7有什么关系?我已经搜遍了所有,并且找不到任何关于它的信息.
此外,在for循环的每次迭代中都会记录该消息:
for (MPMediaItemCollection *collection in collections) {
for (MPMediaItem *item in collection.items) {
//message is written to log here as well
}
}
Run Code Online (Sandbox Code Playgroud) 我正在开发一个使用iPod库播放一些歌曲的iPhone应用程序.我用以下代码加载歌曲.问题是,在设备与iTunes同步后立即运行此代码时出现问题.显然iPod库需要更新,需要一些时间.如果我在同步后立即转到iPod应用程序,我看到一条消息"正在更新库..".如果我在我的应用程序中调用"[查询项目]",那么我会得到一个空数组,表明库中没有歌曲.更新结束后,一切都很完美.有什么方法可以解决这个问题吗?也许是一种检测更新何时结束的方法.我试图听听NSNotifications,但是在更新完成时没有调用.
MPMediaQuery *query = [MPMediaQuery songsQuery];
// convert all items to abstracted media item
NSArray *items = [query items];
NSMutableArray *convertedItems = [[NSMutableArray alloc] initWithCapacity:[items count]];
for (MPMediaItem *item in items) {
REMediaItem *mediaItem = [[REMediaItem alloc] initWithMediaItem:item];
[convertedItems addObject:mediaItem];
[mediaItem release];
}
Run Code Online (Sandbox Code Playgroud)
我希望有人能帮帮忙.
彼得
我想以编程方式排队当前在本地音乐应用程序中播放.我可以使用MPMusicPlayerController来获取当前正在播放的项目,但我想要的不仅仅是项目而是整个播放队列.是否可以使用AVFoundation或任何其他库来完成?
谢谢
如何以与iOS音乐应用程序相同的方式搜索iPod库?我想做一般查询,返回每个艺术家,专辑和歌曲的结果.例如,如果我搜索Kenny Chesney,我希望歌曲查询返回所有Kenny Chesney歌曲(以及包含Kenny Chesney的任何歌曲标题或专辑.)当我为每个属性(歌曲标题,专辑)创建此查询和谓词时标题,艺术家姓名),一个空数组返回.
这里有一些代码可以让您更好地了解我想要实现的目标:
MPMediaPropertyPredicate *songPredicate =
[MPMediaPropertyPredicate predicateWithValue:searchText
forProperty:MPMediaItemPropertyTitle
comparisonType:MPMediaPredicateComparisonContains];
MPMediaPropertyPredicate *albumPredicate =
[MPMediaPropertyPredicate predicateWithValue:searchText
forProperty:MPMediaItemPropertyAlbumTitle
comparisonType:MPMediaPredicateComparisonContains];
MPMediaPropertyPredicate *artistPredicate =
[MPMediaPropertyPredicate predicateWithValue:searchText
forProperty:MPMediaItemPropertyArtist
comparisonType:MPMediaPredicateComparisonContains];
MPMediaQuery *songsQuery = [MPMediaQuery songsQuery];
[songsQuery addFilterPredicate:songNamePredicate];
[songsQuery addFilterPredicate:artistNamePredicate];
[songsQuery addFilterPredicate:albumNamePredicate];
NSLog(@"%@", [songsQuery items]);
Run Code Online (Sandbox Code Playgroud)
我有这个工作通过分别运行每个谓词的查询,但这似乎非常低效!
我在我的应用程序中使用Apple Media Player框架.要获取我正在使用MPMediaQuery文档中所述的项目.哪个效果很好,但是当使用预定义查询来检索所有艺术家时,我会为少数艺术家获得重复的条目.
有人可以解释为什么有重复吗?我该如何抑制它们?
NSArray *collections = [[MPMediaQuery artistsQuery] collections];
Run Code Online (Sandbox Code Playgroud)
(并且艺术家的名字中没有任何拼写错误或外壳的差异!)
我想显示一个UITableView,只显示设备上当前的歌曲.
如果我查询所有项目我(显然)获得所有项目,包括我购买但未下载的项目.这是代码的(部分)
@property (strong, nonatomic) NSMutableArray *songsList;
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView.delegate = self;
self.tableView.dataSource = self;
MPMediaQuery *everything = [[MPMediaQuery alloc] init];
NSArray *itemsFromGenericQuery = [everything items];
self.songsList = [NSMutableArray arrayWithArray:itemsFromGenericQuery];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.songsList.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"TableCellID";
TableCellTitle *tablecell = (TableCellTitle *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
MPMediaItem *song = [self.songsList objectAtIndex:indexPath.row];
NSString *songTitle = [song valueForProperty: MPMediaItemPropertyTitle];
tablecell.cellSongname.text = songTitle;
return tablecell;
}
Run Code Online (Sandbox Code Playgroud)
我读过几件涉及的事情
[song valueForProperty:MPMediaItemPropertyIsCloudItem] …Run Code Online (Sandbox Code Playgroud) 我想在我的iOS应用程序上运行一些测试,我想找到一种在模拟器中测试MPMediaQuery的方法,这样我就可以获得带有模拟数据的MPMediaItemCollection.我可以使用任何库或模拟数据来测试它而不依赖于设备?
谢谢,Alberto
当我在iTunes中查看我购买的音乐时,歌曲列表旁边的红色显式框会显示明确的歌曲.即,您在购买歌曲时看到的显式标签会传递到iTunes资料库.歌曲itunes标记为干净的歌曲也是如此.我真的希望能够识别我的ios应用程序中明确显示的任何歌曲,但是我找不到任何关于标签是否通过其他歌曲信息(MPMediaItemProperty)传递到ios设备的资源,如果是这样的话得到它(我无休止地搜索!)有些歌曲在其标题的末尾包含"[Explicit]",但这只是一些歌曲的情况,而不是所有.有人知道标签是否存在且可从Objective读取-C代码?
我需要按顺序从iOS设备获取N个最近播放的歌曲列表.
目前,我能想象的唯一方法是将所有歌曲通过MPMediaQuery并手动排序lastPlayedDate.
这是一个可能很昂贵的操作,我想知道是否有更好的方法.
编辑:经过一些测试,这是一个非常昂贵的操作.在2500首歌曲的测试库中,花了大约20秒时间:
任何改进的建议将不胜感激.
编辑2:现在解决了,但只是为了记录这里我正在做的事情.
我正在使用如下所述的块进行排序:https://stackoverflow.com/a/805589/112702.简单地将排序方法改为布莱恩的答案,在iPod Touch 3上将我的速度提高了近20倍.
我正在尝试使用以下代码播放专辑…
let predicate = MPMediaPropertyPredicate(value: "1459938538", forProperty: MPMediaItemPropertyAlbumPersistentID)
let iCloudPredicate = MPMediaPropertyPredicate(value: true, forProperty: MPMediaItemPropertyIsCloudItem)
let query = MPMediaQuery.albums()
query.filterPredicates = [predicate, iCloudPredicate]
let mp = MPMusicPlayerController.applicationMusicPlayer
mp.setQueue(with: query)
mp.play()
Run Code Online (Sandbox Code Playgroud)
但是它失败了
[SDKPlayback] -[MPMusicPlayerController prepareToPlay] timeout
[MediaRemote] MRC <MPCPlayerPath: route=<MPAVEndpointRoute: 0x280f1a280 name=iPhone uid=LOCAL> origin=iPhoneID bundleID=com.apple.MediaPlayer.RemotePlayerService playerID=MPMusicPlayerApplicationController>: Undo optimistic state [failed] command=Play error=Error Domain=MPCPlayerRequestErrorDomain Code=1000 "Failed to send command 0 (MRMediaRemoteCommandHandlerStatus = 1)" UserInfo={NSDebugDescription=Failed to send command 0 (MRMediaRemoteCommandHandlerStatus = 1), MPCPlayerErrorKeyMediaRemoteCommandHandlerStatus=1}
[SDKPlayback] -[MPMusicPlayerController play] completed error: Error Domain=MPCPlayerRequestErrorDomain Code=1000 "Failed to …
mpmusicplayercontroller mpmediaquery ios swift apple-musickit
mpmediaquery ×10
ios ×9
objective-c ×6
mpmediaitem ×3
avfoundation ×2
iphone ×2
ipod ×2
explicit ×1
ios7 ×1
ipad ×1
swift ×1
uitableview ×1