這是我的理解,它取決於您使用的iOS版本。我認爲在4.3之前,返回nil
的資產意味着該項目是DRMed,而您無法訪問它。但是,在當前版本(5)中,零表示它只是iCloud。也許你有一些你認爲只是DRMed的音軌,但實際上是iCloud存儲的歌曲。在我正在開發的當前應用程序中,我原本沒有考慮過iCloud曲目(因爲我針對的是iOS以前版本的應用程序),因此我根據使用的設備而發生崩潰。要解決的iCloud/DRM的問題,並測試我使用:
AVURLAsset* asset;
NSURL* realAssetUrl = [item valueForProperty:MPMediaItemPropertyAssetURL];
if(!realAssetUrl){
//track is iCloud
}
asset = [[AVURLAsset alloc]initWithURL:realAssetUrl options:nil];
if(asset == nil || asset.hasProtectedContent){
//asset is DRMed such that it cannot be played back.
//most apps can stop here but I need to be able to export the song
}
if (!asset.exportable || !asset.readable){
//the asset cannot be exported and thus cannot be cached to a file
//the current app directory and cannot be transferred over network
//if asset passed earlier check, can still be used for local playback
}
[asset release];
這似乎爲我工作得很好,但你也意味着你領導下相同的路徑,已經,所以我不知道有多少幫助那會給你。不過,祝你的項目好運,我希望你找到你正在尋找的答案!
我可以肯定地說,在iOS 5上,資產URL在iCloud和DRM兩種情況下都是零。因此你的解決方案(這也是我的嘗試)並不能解決這個問題。 – awolf
我認爲我們使用操作系統的體驗非常不同。讓我知道你找到/找到解決方案,我會很感激聽到它。 – btomw