Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 08-24-2008, 02:20 PM   #5 (permalink)
refreshe
mr.
 
refreshe's Avatar
 
Join Date: Jul 2008
Location: SF, California | Melbourne, Australia
Posts: 346
refreshe is on a distinguished road
Default

Try using the SoundEffect class files from the metronome example from Apple. It has some console messages that are printed if there's a problem loading sound files etc. It could give you a better idea of what's going wrong.


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

@interface SoundEffect : NSObject {
    SystemSoundID _soundID;
}

+ (id)soundEffectWithContentsOfFile:(NSString *)aPath;
- (id)initWithContentsOfFile:(NSString *)path;
- (void)play;

@end

SoundEffect.m
Code:
#import "SoundEffect.h"

@implementation SoundEffect
+ (id)soundEffectWithContentsOfFile:(NSString *)aPath {
    if (aPath) {
        return [[[SoundEffect alloc] initWithContentsOfFile:aPath] autorelease];
    }
    return nil;
}

- (id)initWithContentsOfFile:(NSString *)path {
    self = [super init];
    
    if (self != nil) {
        NSURL *aFileURL = [NSURL fileURLWithPath:path isDirectory:NO];
        
        if (aFileURL != nil)  {
            SystemSoundID aSoundID;
            OSStatus error = AudioServicesCreateSystemSoundID((CFURLRef)aFileURL, &aSoundID);
            
            if (error == kAudioServicesNoError) { // success
                _soundID = aSoundID;
            } else {
                NSLog(@"Error %d loading sound at path: %@", error, path);
                [self release], self = nil;
            }
        } else {
            NSLog(@"NSURL is nil for path: %@", path);
            [self release], self = nil;
        }
    }
    return self;
}

-(void)dealloc {
    AudioServicesDisposeSystemSoundID(_soundID);
    [super dealloc];
}

-(void)play {
    AudioServicesPlaySystemSound(_soundID);
}

@end

Playing sound
Code:
SoundEffect *soundEffect = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"sound1" ofType:@"caf"]];

[soundEffect play];
__________________
appz
refreshe is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 175,419
Threads: 94,016
Posts: 402,536
Top Poster: BrianSlick (7,978)
Welcome to our newest member, estherkt98
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:22 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.