簡體   English   中英

獲取當前歌曲的藝術作品時出錯

[英]Error getting artwork for current song

抓取當前歌曲的專輯封面並使用它來更改某個imageView.image產生錯誤,但不再崩潰。 (以前是這樣,因為我忽略了if (!artwork)錯誤處理。嗯。)

這種方法:

- (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;
    }
}

爆發是這樣的:

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

但僅在發射時。 它仍然顯示圖像(或缺少圖像)。 詭異的。

編輯: iPod 庫是只讀的(應用程序不能改變任何東西,只有 iTunes),所以也許它在大喊大叫
我寫了一個只讀的東西,但仍然允許它,因為沒有任何只讀的被修改?

在修復之后,我需要調整大小(用於景觀支持)而不是 IB 的拉伸。
不是很重要,但仍然是一件好事。

這就是我所做的。 它不會產生錯誤,並且每次都會生成圖像。 如果歌曲沒有圖像,則默認為我提供的圖像。 我認為因為您沒有檢查具有特定尺寸(320 x 320,與我的屏幕寬度匹配)的圖像,所以它無法正確計算出來。 我不知道你為什么會收到 SQLite 錯誤,但希望這能解決它!

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"]];
}

鏈接在這里 - 為什么我在 xcode 控制台中收到此 CPSqliteStatementPerform 錯誤

將其放在這里,以便可以將問題標記為已回答。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM