selected music not playing from iPhone music library
-
29-09-2019 - |
Question
I have created an iPhone application. Using this application, I can able to record my voice and able to play that recorded file. But if I select a music file from library, it is not playing.
// sample code that I have used in my application
self.player = [MPMusicPlayerController applicationMusicPlayer];
MPMediaPropertyPredicate *songNamePredicate = [MPMediaPropertyPredicate predicateWithValue: self.songName forProperty: MPMediaItemPropertyTitle];
MPMediaQuery *mySongQuery = [[MPMediaQuery alloc] init];
[mySongQuery addFilterPredicate: songNamePredicate];
[player setQueueWithQuery:mySongQuery];
[player play];
Please help me to resolve it.
Solution
Change
MPMediaPropertyPredicate *songNamePredicate = [MPMediaPropertyPredicate predicateWithValue: self.songName forProperty: MPMediaItemPropertyTitle];
to
MPMediaPropertyPredicate *songNamePredicate = [MPMediaPropertyPredicate predicateWithValue:self.songName forProperty:MPMediaItemPropertyTitle comparisonType:MPMediaPredicateComparisonContains];
also what is the value of the query result
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow