How to play a song from the itunes library in iphone

后端 未结 3 1589
野趣味
野趣味 2020-12-01 02:36

Hi i need to play a song from the itunes library. I had gone through the Apples ipod Library Access Guide and got the code.

MPMediaQuery *everything = [[MPMe         


        
3条回答
  •  一整个雨季
    2020-12-01 02:54

    I couldn't use theMPMediaPickerController in my scenario.

    My short answer to question is to have a look at [musicplayer setNowPlayingItem:item]

    here's some code below from my implementation.

    // Create a new query
    MPMediaQuery *query = [MPMediaQuery songsQuery];
    MPMediaPropertyPredicate *mpp = [MPMediaPropertyPredicate predicateWithValue:@"a" forProperty:MPMediaItemPropertyTitle comparisonType:MPMediaPredicateComparisonContains];
    [query addFilterPredicate:mpp]; 
    
    // Retrieve the results and reload the table data
    DATAENV.songCollections = [NSMutableArray arrayWithArray:query.collections];
    
    //populate cell rows with 
    
    - (UITableViewCell *)tableView:(UITableView *)tView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        MPMediaItem *item = [[[DATAENV.songCollections objectAtIndex:indexPath.row] items] lastObject];
        titleLbl = [item valueForProperty:MPMediaItemPropertyTitle];
    }
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        MPMediaItem *item = [[[self.songCollections objectAtIndex:indexPath.row] items] lastObject];
        [PLAYER setNowPlayingItem:item];
        [PLAYER play];
    }
    

    Where PLAYER/ DATAENV are my singletons

    #define PLAYER  [[AudioController sharedAudioController_instance] musicPlayer]
    #define DATAENV [DataEnvironment sharedDataEnvironment_instance]
    

提交回复
热议问题