iDevGames Forums
Sound's working on simulator but not on device - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: Sound's working on simulator but not on device (/thread-2143.html)



Sound's working on simulator but not on device - cceetix - Nov 16, 2008 03:52 PM

Helle everyone !

I have a problem ...
I would like te play a short sound on my iPhone. On the simulator it's working perfectly but when I put my app on my iphone nothing happends ... Why ?
Here's my code :

SoundEffect .h

Code:
#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioServices.h>

@interface SoundEffect : NSObject {
    
    SystemSoundID soundID;
    
}
-(void)play;
- (id)initWithContentsOfFile:(NSString *)path;
@end

SoundEffect.m

Code:
#import "SoundEffect.h"


@implementation SoundEffect

- (id)initWithContentsOfFile:(NSString *)path
{
    self = [super init];
    if (self != nil) {
        NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
        AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);
    }
    return self;
}
-(void)play {
    
    AudioServicesPlaySystemSound(soundID);
}

@end

MyView.h

Code:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>

@class SoundEffect;
@interface ViewOne : UIView {
    
    SoundEffect *soundEffect;
    SoundEffect *soundEffect2;
}

MyView.m

Code:
- (void)awakeFromNib {  

    NSBundle *mainBundle = [NSBundle mainBundle];
    soundEffect = [[SoundEffect alloc]initWithContentsOfFile:[mainBundle pathForResource:@"sound1" ofType:@"mp3"]];
    soundEffect2 = [[SoundEffect alloc]initWithContentsOfFile:[mainBundle pathForResource:@"sound2" ofType:@"mp3"]];
}


// A button action

- (IBAction)MakeSound {

if(//condition)
[soundEffect play];
else
[soundEffect2 play];
}

So it's working 100% on simulator.
I don't understand why it's not working on my device.
I have correctly imported my sound in my project...

Please I need some help Annoyed

Thanks !


Sound's working on simulator but not on device - Zunnun - Dec 4, 2008 06:12 PM

Device supports .caf, aif & wav. but simulator also supports mp3 !