How to detect if an MPMediaItem represents a DRM-protected audio track on iOS

前端 未结 7 2082
粉色の甜心
粉色の甜心 2020-12-01 12:31

I would like to know if an MPMediaItem that represents a music track is for a Fairplay/DRM-protected item. Any way to do this?

相关标签:
7条回答
  • 2020-12-01 13:20

    Justin Kents' solution works great. I recommend using blocks though or else the UX will suffer if you deal with a bunch of songs:

    -(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);
                }
        });
        });
    }
    
    0 讨论(0)
提交回复
热议问题