当我到达ios5中的最后一个声音片段时,应用程序挂起

时间:2013-01-09 18:36:08

标签: iphone ios5 ios4

我有一个带图像的应用程序,一旦用户按下图像,就会播放声音片段。一旦我到达最后一张没有声音剪辑的图像(25),如果我按下该应用程序自动关闭,我该如何防止这种情况。

例如,我需要播放C01.mp3一旦用户点击01.Png(注意我的所有图像也保存在图像阵列中)基本上我有25.png这只是我网站的广告所以它不会有一个声音剪辑,但一旦我点击该图像,应用程序将自动关闭。需要帮助来解决这个问题。

//

#import "SoundsGenerator.h"


@implementation SoundsGenerator

- (id) init
{
    CFBundleRef mainBundle;
    mainBundle = CFBundleGetMainBundle ();

    soundObjects=[[NSMutableArray alloc] init];

    NSMutableArray *soundNames = [[NSMutableArray alloc] initWithObjects:@"c1",
                                @"c2", 
                                @"c3", 
                                @"c4", 
                                @"c5", 
                                @"c6", 
                                @"c7", 
                                @"c8", 
                                @"c9", 
                                @"c10", 
                                @"c11", 
                                @"c12", 
                                @"c13", 
                                @"c14", 
                                @"c15", 
                                @"c16", 
                                @"c17", 
                                @"c18", 
                                @"c19", 
                                @"c20", 
                                @"c21", 
                                @"c22", 
                                @"c23", 
                                @"c24",nil];    

    for(NSString *soundName in soundNames)
    {
        CFBundleRef mainBundle = CFBundleGetMainBundle();
        CFURLRef soundFileURLRef;
        soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (__bridge CFStringRef)soundName, CFSTR ("mp3"), NULL);

        SystemSoundID soundFileObject;
        // Create a system sound object representing the sound file
        AudioServicesCreateSystemSoundID (soundFileURLRef, &soundFileObject);

        SoundObject *objSound=[[SoundObject alloc] init];
        objSound.soundFileObject=soundFileObject;
        objSound.soundFileURLRef=soundFileURLRef;
        [soundObjects addObject:objSound];
    }

    return self;
}

// Respond to a tap on the System Sound button
- (void) playSound:(int)index 
{
    SoundObject *soundObject=[soundObjects objectAtIndex:index];
    AudioServicesPlaySystemSound ((SystemSoundID)soundObject.soundFileObject);
}


@end

1 个答案:

答案 0 :(得分:0)

替换

for(NSString *soundName in soundNames)
{

for(int i = 0 ; i < soundNames.count-1 ; i++)
{
   NSString *soundName = [soundNames objectAtIndex:i];
   //rest of the code same

这将运行循环,直到24个索引数组的23个索引...