Help creating custom iPhone Classes

Posted by seanny94 on Stack Overflow See other posts from Stack Overflow or by seanny94
Published on 2010-04-04T20:14:03Z Indexed on 2010/04/04 20:23 UTC
Read the original article Hit count: 309

This should be a simple question, but I just can't seem to figure it out.

I'm trying to create my own class which will provide a simpler way of playing short sounds using the AudioToolbox framework as provided by Apple. When I import these files into my project and attempt to utilize them, they just don't seem to work. I was hoping someone would shed some light on what I may be doing wrong here.

simplesound.h

#import <Foundation/Foundation.h>


@interface simplesound : NSObject {

    IBOutlet UILabel *statusLabel;

}

@property(nonatomic, retain) UILabel *statusLabel;

- (void)playSimple:(NSString *)url;

@end

simplesound.m

#import "simplesound.h"


@implementation simplesound

@synthesize statusLabel;

- (void)playSimple:(NSString *)url {

    if (url = @"vibrate") {
        AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
        statusLabel.text = @"VIBRATED!";
    } else {
        NSString *paths = [[NSBundle mainBundle] resourcePath];
        NSString *audioF1ile = [paths stringByAppendingPathComponent:url];
        NSURL *audioURL = [NSURL fileURLWithPath:audioFile isDirectory:NO];
        SystemSoundID mySSID;
        OSStatus error = AudioServicesCreateSystemSoundID ((CFURLRef)audioURL,&mySSID);
        AudioServicesAddSystemSoundCompletion(mySSID,NULL,NULL,simpleSoundDone,NULL);

        if (error) {
            statusLabel.text = [NSString stringWithFormat:@"Error: %d",error];
        } else {
            AudioServicesPlaySystemSound(mySSID);
        }
    }


    static void simpleSoundDone (SystemSoundID mySSID, void *args) {

        AudioServicesDisposeSystemSoundID (mySSID);

    }
}

- (void)dealloc {
    [url release];
}

@end

Does anyone see what I'm trying to accomplish here? Does anyone know how to remedy this code that is supposedly wrong?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about iphone-sdk-3.0