How to import music file from iphone music library to iPhone App

In my iPhone application I can browse the iphone electronic library even I import the media file name into the list of music files of the application but when I start the application next time I don’t get the name of the media file that I previously imported

In my application, I import songs from one folder "MusicSampler", which is located in my APP folder. Now, on the buttonclick button, I open the iPod’s music library and select a song (using MediaPicker) that is added to my list of songs in buttom, now the next time I open my application it downloads all the songs from the “musicSampler” folder, but on this time new songs added earlier from iPod-Library are not shown

what should I do to save the imported song from the iPod music library to my iphone application (either by adding a music file to my “MusicSampler”, or something else)

Please help and suggest

thank

0
source share
2 answers

 MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeMusic];
    mediaPicker.delegate = self;
    mediaPicker.allowsPickingMultipleItems = YES;
   [self presentViewController:mediaPicker animated:YES completion:nil];

- (void)mediaPicker: (MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection
 {
   [self dismissViewControllerAnimated:YES completion:nil];
    MPMediaItem *item = [mediaItemCollection representativeItem];
    player=[[AVAudioPlayer alloc]initWithContentsOfURL:[item     valueForProperty:MPMediaItemPropertyAssetURL] error:nil];
   [player play];
 }

- (void)mediaPickerDidCancel:(MPMediaPickerController *)mediaPicker {

    [self dismissViewControllerAnimated:YES completion:nil];
}
+1

Source: https://habr.com/ru/post/1786639/


All Articles