你應該試試這個,但我用MPMusicPlayer:
musicPlayer = [MPMusicPlayerController iPodMusicPlayer];
currentItem = [musicPlayer nowPlayingItem];
if (currentItem == nil) {
//Not playing
}
else
{
NSString *name = [currentItem valueForProperty:@"title"];
int length = [name length];
if (length > 30) {
name = [name substringWithRange:NSMakeRange(0, 30)];
name = [name stringByAppendingString:@"..."];
}
NSString *album = [currentItem valueForProperty:@"albumTitle"];
int lengthAl = [album length];
if (lengthAl > 30) {
album = [album substringWithRange:NSMakeRange(0, 30)];
album = [album stringByAppendingString:@"..."];
}
NSString *artist = [currentItem valueForProperty:@"artist"];
int lengthAr = [artist length];
if (lengthAr > 30) {
artist = [artist substringWithRange:NSMakeRange(0, 30)];
artist = [artist stringByAppendingString:@"..."];
}
MPMediaItemArtwork *artworkPrev = [currentItem valueForProperty:@"artwork"];
if (artworkPrev != nil)
{
UIImage *img = [artworkPrev imageWithSize:CGSizeMake(65, 65)];
UIImageView *imgNew = [[UIImageView alloc] initWithImage:img];
imgNew.frame = CGRectMake(-15,-20, 65, 65);
}
}
正如你可以看到我使用NSMakeRange,我用它只是在我的應用程序不會留下空間。我希望能幫到你
你好,你有沒有找到如何獲得專輯封面?我嘗試了用戶最後的FM服務,但是我的收音機中的歌手並不流行,所以我無法獲得專輯封面(( –