簡體   English   中英

擁有MPMediaItemPropertyPersistentID后,如何播放歌曲?

[英]How do i play song back once i have MPMediaItemPropertyPersistentID?

NSArray * songs = [[NSArray alloc] initWithArray:[[MPMediaQuery songsQuery] collections]];

for (MPMediaItemCollection * item in songs){

    NSString * persistentID = [[[item representativeItem]             valueForProperty:MPMediaItemPropertyPersistentID] stringValue];
    // Do something with it.
    ??? 

}

擁有MPMediaItemPropertyPersistentID后,如何播放歌曲?

//Your song id NSString *songID;

MPMediaPropertyPredicate *predicate = [MPMediaPropertyPredicate predicateWithValue:songID forProperty:MPMediaItemPropertyPersistentID];

MPMediaQuery *mySongQuery = [[MPMediaQuery alloc] init]; 
//finding songs for predicate 
[mySongQuery addFilterPredicate: predicate];

//add songs to queue
[musicPlayer setQueueWithQuery:mySongQuery];

[musicPlayer play];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM