I'm a new developer and I'm getting to grips with audio in iOS.
This will be tricky to explain, but I'll give it a go. I'm using a media picker so that the user can select a song from their library. I don't want there to be a queue or for it to play immediately. Instead, I want it to appear in a tableview and when the user selects that song in the table view, it will play that when, in another view, a button is pressed.
So basically, I want the user to be able to select a song from their library and it is added to list. They can then selected a song from that list and It will play that when a button is pressed.
If it helps, this is the code I'm using for the media picker and to play audio (and they're not actually connected to each other):
Media Picker:
MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeAnyAudio];
[mediaPicker setDelegate:self];
[mediaPicker setAllowsPickingMultipleItems:NO];
mediaPicker.prompt = NSLocalizedString(@"text1", "text2");
[self presentViewController:mediaPicker animated:YES completion:nil];
Playing Audio:
if (self.panicButtonPressed == NO) {
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:@"Alarm 1"
ofType:@"mp3"]];
alarmSound = [[AVAudioPlayer alloc]
initWithContentsOfURL:url
error:nil];
[alarmSound play];
self.panicButtonPressed = YES;
}
Any help would be greatly appreciated.