MPMediaItem and iTunes Match

前端 未结 4 1489
故里飘歌
故里飘歌 2020-12-23 11:47

I have an app that uses the iPod Library API to access the song database in iOS. With the release of iTunes Match, any song which is not on the device will fail to load. I

相关标签:
4条回答
  • 2020-12-23 12:28

    I have found something, but it isn't great. If you select the song to be played through the iPod player then that will trigger a download. You can access the iPod player with an MPMusicPlayerController.

    MPMusicPlayerController *mDRMAudioPlayer;
    mDRMAudioPlayer = [MPMusicPlayerController iPodMusicPlayer];
    
    MPMediaQuery *assetQuery = [[MPMediaQuery alloc] init];
    NSNumber *persistentID = [mediaItem valueForProperty: MPMediaItemPropertyPersistentID];
    MPMediaPropertyPredicate *predicate = [MPMediaPropertyPredicate predicateWithValue: persistentID 
                                                                           forProperty: MPMediaItemPropertyPersistentID];
    [assetQuery addFilterPredicate: predicate];
    
    [mDRMAudioPlayer setQueueWithQuery: assetQuery];
    [mDRMAudioPlayer play];
    

    No feedback on if this really started a download or not, or progress on the download but the item will start downloading and if your connection is good it will play the first time (otherwise you can spam play and it will get around to starting).

    0 讨论(0)
  • 2020-12-23 12:30

    Here's something to watch out for. My app does an ordinary [MPMediaQuery albumsQuery] to gather all albums and their songs. This works fine even if the whole music library consists of iTunes Match stuff most of which is still in the cloud. But there's one problem:

    If a song is being played at that moment, and if that song was in the cloud, so that now it is being downloaded, that song and the next song in the album are missing from the result of [MPMediaQuery albumsQuery]. This is presumably because those songs are "in transit": they are both partially downloaded. (I presume two songs are always downloaded so that when the first finishes it is possible to segue seamlessly into the next.)

    Moreover, playing and therefore downloading a song triggers an MPMediaLibraryDidChangeNotification even though the "table of contents" of the library has not in fact changed.

    I don't see any way around this, since there's no other way to query the library. Apple needs to fix the system and the APIs to take account of iTunes Match's existence. Unfortunately I am not getting a sense that they are working on this for iOS 5.1...

    0 讨论(0)
  • 2020-12-23 12:39

    I just heard back from Apple regarding this issue (I used one of my Technical Support Incidents).

    According to Apple, the iOS SDK does not currently provide any APIs for initiating a download from iCloud. I was instructed to file an enhancement request for this feature via Apple's bug reporter tool. I would encourage others to do the same.

    Apple really should provide programmatic support for downloading audio assets from iCloud considering that iCloud is one of the defining features of iOS 5.

    0 讨论(0)
  • 2020-12-23 12:49

    MPMediaItem | iCloud or DRM Protected

    The link above shows how you can use a property introduced in iOS 6 to see if an MPMediaItem is in the cloud.

    MPMediaItemPropertyIsCloudItem

    BOOL isCloud = FALSE;
    
    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0")) {
        NSNumber *isCloudNumber = [mediaItem valueForProperty:MPMediaItemPropertyIsCloudItem];
        isCloud = [isCloudNumber boolValue];
    }
    if (isCloud) {
        DebugLog(@"Cloud Asset URL: %@", assetURL);
    }
    

    That is using a macro to ensure only iOS 6 uses that code which was added with iOS 6. Below is that macro.

    #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
    

    Still you cannot initiate a download as far as I can tell.

    0 讨论(0)
提交回复
热议问题