Error getting artwork for current song

点点圈 提交于 2019-12-01 07:03:53

问题


Grabbing album art for current song and using it to change a certain imageView.image generates an error, but no longer crashes. (It did before because I left out the if (!artwork) error handling. Eheh.)

This method:

- (void)handleNowPlayingItemChanged:(id)notification {
    MPMediaItem *item = self.musicPlayer.nowPlayingItem;
    CGSize albumCoverSize = self.albumCover.bounds.size;
    MPMediaItemArtwork *artwork =
                            [item valueForProperty:MPMediaItemPropertyArtwork];
    if (artwork) {
        self.albumCover.image = [artwork imageWithSize:albumCoverSize];
    } else {
        self.albumCover.image = nil;
    }
}

Explodes like this:

CPSqliteStatementPerform: attempt to write a readonly database for
    UPDATE ddd.ext_container SET orig_date_modified = (SELECT date_modified
    FROM container WHERE pid=container_pid) WHERE orig_date_modified=0
CPSqliteStatementReset: attempt to write a readonly database for
    UPDATE ddd.ext_container SET orig_date_modified = (SELECT date_modified
    FROM container WHERE pid=container_pid) WHERE orig_date_modified=0

But only on launch. And it still shows the image (or lack thereof). Weird.

Edit: The iPod Library is readonly (apps can't change anything, only iTunes), so maybe it's yelling at
me for writing a readonly something, but still allowing it because nothing readonly is being modified?

And after that's fixed, I need to get resizing working (for Landscape support) instead of IB's stretching.
Not vital, but still a nice thing to have.


回答1:


Here's what I do. It creates no errors, and produces an image every time. If the song doesn't have an image, it defaults to the one I provide. I think because you're not checking for an image with a specific size (320 by 320, matching the screen width for me), it fails to figure it out correctly. I don't know why you're getting the SQLite error, but hopefully this fixes it!

MPMediaItemArtwork *artworkItem = [self.musicPlayer.nowPlayingItem valueForProperty: MPMediaItemPropertyArtwork];
if ([artworkItem imageWithSize:CGSizeMake(320, 320)]) {
    [self.currentlyPlayingArtworkView setImage:[artworkItem imageWithSize:CGSizeMake (320, 320)]];
}
else {
    [self.currentlyPlayingArtworkView setImage:[UIImage imageNamed:@"NoArtworkImage"]];
}



回答2:


Link here - Why am I getting this CPSqliteStatementPerform error in xcode console

Putting this here so the question can be marked as Answered.



来源:https://stackoverflow.com/questions/6346079/error-getting-artwork-for-current-song

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!