2013-08-27 36 views
1

我想在我的應用程序中使用avplayer播放設備歌曲。在NSLog的即時得到數組值===> 「18023427656013653237」, 「15946441828903552798」, 「10791915036547881152」, 「17986655796364263078」 //現在我想這些是什麼值.....如何在AVPlayer中將MPMediaItemCollection提取到NSData?

我有試過這.....

-(IBAction)SelectSongs:(id)sender 
{ 

MPMediaPickerController *picker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeAny]; 
picker.delegate = self; 
picker.allowsPickingMultipleItems =YES; 
picker.prompt = @"Select songs from the list"; 

[self presentViewController:picker animated:YES completion:^(void) {}]; 
} 

-(void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection 
{ 


if (mediaItemCollection) 
{ 
    NSMutableArray *medialibraryArray; 
    medialibraryArray=[[NSMutableArray alloc]init]; 
    [medialibraryArray addObject:mediaItemCollection.items];// Modified 
    NSLog(@"%@=========>",medialibraryArray); 


} 
[self dismissViewControllerAnimated:YES completion:^(void) {}];} 

-(void) mediaPickerDidCancel: (MPMediaPickerController *) mediaPicker 
{ 
[self dismissViewControllerAnimated:YES completion:^(void) {}]; 
} 


// Thanks in Advance 

回答

1
-(void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection 
{ 


    if (mediaItemCollection) 
    { 
     NSArray *items = [mediaItemCollection items]; 
     for(int n=0; n < items.count; n++) { 
      MPMediaItem *mediaItem = [items objectAtIndex:n]; 
      NSLog(@"%@=========>",[mediaItem valueForProperty:MPMediaItemPropertyTitle]); 
     } 

     MPMusicPlayerController *musicPlayer = [MPMusicPlayerController iPodMusicPlayer]; 
     [musicPlayer setQueueWithItemCollection: mediaItemCollection]; 
     NSLog(@"==>%@",musicPlayer); 


    } 
    [self dismissViewControllerAnimated:YES completion:^(void) {}]; 
} 

你會得到庫中的所有歌曲與此所以打印輸出可能需要一段時間!閱讀MPMediaItem類參考和媒體查詢,瞭解如何獲取整個音樂庫的子集。

+0

非常感謝您的寶貴意見 – NextStep

相關問題