18

音楽トラックを表す MPMediaItem が Fairplay/DRM で保護されたアイテム用であるかどうかを知りたいです。これを行う方法はありますか?

4

7 に答える 7

10

これが私がそれをする方法です:

MPMediaItem* item;

NSURL* assetURL = [item valueForProperty:MPMediaItemPropertyAssetURL];
NSString *title=[item valueForProperty:MPMediaItemPropertyTitle];

if (!assetURL) {
    /*
     * !!!: When MPMediaItemPropertyAssetURL is nil, it typically means the file
     * in question is protected by DRM. (old m4p files)
     */
    NSLog(@"%@ has DRM",title);
}
于 2011-09-13T22:11:58.197 に答える
6

Since iOS 4.2 there is a way. There may be a more effective way then the example here (but for my app I needed to create AVPlayerItems anyway).

MPMediaItem item;
NSURL *assetURL = [item valueForProperty:MPMediaItemPropertyAssetURL];
AVPlayerItem *avItem = [[AVPlayerItem alloc] initWithURL:assetURL];
BOOL fairplayed = avItem.asset.hasProtectedContent;
于 2011-06-19T08:21:22.047 に答える
5

iOS 4.2 以降、AVAssetクラスにはプロパティがあるhasProtectedContentため、以下を確認できます。

NSURL *assetURL = [item valueForProperty:MPMediaItemPropertyAssetURL];
AVAsset *asset = [AVAsset assetWithURL:assetURL];

if ([asset hasProtectedContent] == NO) {..do your stuff..}
于 2012-05-22T13:30:35.140 に答える
0

Justin Kents のソリューションはうまく機能します。ただし、ブロックを使用することをお勧めします。そうしないと、たくさんの曲を扱う場合に UX が損なわれます。

-(void)checkDRMprotectionForItem:(MPMediaItem*)item OnCompletion:(void (^)(BOOL drmProtected))completionBlock
{
    dispatch_async(_drmCheckQueue, ^{
        BOOL drmStatus;
        NSURL* assetURL = [item valueForProperty:MPMediaItemPropertyAssetURL];
        if (!assetURL) {
            drmStatus = YES;
        }

        dispatch_async(dispatch_get_main_queue(), ^{
            if (completionBlock) {
                completionBlock(drmStatus);
            }
    });
    });
}
于 2014-05-19T08:44:10.267 に答える