Hi Guys I've got a for loop that lets me display a different image on each page using the uiscrollview and uipagecontroller. I'm trying to add a sound to play on each page change. I have 6 pages and I have 6 images 1.png - 6.png. I also have 6 mp3 files named 1.mp3 - 6.mp3
The page control for the images works fine. I'm wanting to add the sound and I've added a bit of code in to make it work. It does not error, however it does not work. The app just won't load? I'm not sure why?
this is the code for the for loop.
Code:
- (void)viewDidLoad {
[super viewDidLoad];
for (int i = 1; i < 7; i++) {
UIImageView *imagen = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d.png",i]]];
imagen.frame = CGRectMake((i-1)*320, 0, 320, 480);
NSString *pathTosoundclip = [[NSBundle mainBundle] pathForResource:@"%i" ofType:@"mp3"];
soundclip = [[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:pathTosoundclip] error:NULL];
[scroller addSubview:imagen];
[imagen release];
}
scroller.delegate = self;
scroller.contentSize = CGSizeMake(320*6, 480);
scroller.pagingEnabled = YES;
pageControl.numberOfPages=6;
pageControl.currentPage=0;
}
Does anyone have any ideas? Obviously I want the mp3 to load on each load of an image. so 1.png would load with 1.mp3 and it would play the audio file from 0seconds. It would also stop the audio file playing and start the new audio file playing when the following page is loaded.
The main thing at this stage is just getting it to play and load.
Hope someone can help?