No sound on my final build

Discussion in 'Mac Programming' started by larswik, Jun 30, 2011.

  1. larswik macrumors 68000

    Sep 8, 2006
    I added dice sounds to my app and built a final version again to try on another computer. The program worked but there is no sound? I check the audio settings for the computer and it plays music just fine but when I press the roll button I get no dice sound. I am guessing it is not building the app with the embedded sound.

    I still can't understand why there are sooooooo many build settings, what a nightmare to look at and figure out, even the descriptions are hard to understand. I am guessing some place in the build I have to tell it to build the sound into the app?

  2. mfram macrumors 65816

    Jan 23, 2010
    San Diego, CA USA
    Did you add the sound files to the "resources" directory for the app? How are you specifying the sound files in the source code? You should be doing them through the main bundle for the application.
  3. larswik thread starter macrumors 68000

    Sep 8, 2006
    Here is the source for the audio

        sound = [[NSSound alloc] initWithContentsOfFile: @"/Users/larspro/diceRollSound.aif" byReference:YES];
    	[sound play];
  4. chown33 macrumors 604

    Aug 9, 2009
    That's not the pathname of an embedded sound file.

    It's the pathname of the file diceRollSound.aif residing in your Home folder (assuming the user larspro is you).

    Pathnames of files embedded in an app bundle requires the use of the NSBundle class, such as its -pathForResource methods.

    You should read the two Companion Guides listed on the left, too.

    Also see "NSBundle Additions":
  5. larswik thread starter macrumors 68000

    Sep 8, 2006
    Chown33 - thanks for the docs! I have been looking all over the net for this information. The whole build thing is a nightmare to figure out. All the build setting, build phases and 'build for' running, testing, profiling and archiving??? Then there is the 'Edit Scheme' area??? a Simple Build COMMAND + B.

    I build it and it runs on my machine but send it to a friend and they can't open it.

    Man, what the hell. They should make an app for this :)

  6. chown33 macrumors 604

    Aug 9, 2009
    You can test it on your computer by creating a new user account. Copy the built app to removable media like a USB thumb drive, eject it, then log out of your normal account. Log into your new account, reinsert the thumb drive, and try running the app from there. If it has errors, you'll get the same kind of problems as sending it to someone else.

    Learn to use to look for NSLog messages. Learn to put NSLog messages in your code, so it tells you things like the sound pathname it's trying to load. NSLog messages are Debugging 101.

    Have you followed a complete "Build an App" tutorial, from start to finish?

    Have you tried downloading and building any of the sample projects associated with a class you're trying to use? For example, have you looked at the sample code projects associated with NSSound? How about the ones for NSBundle?

    In general, sample projects are complete buildable apps. Also, they show more than just how to use a particular class (like NSSound). They also show how to structure your project, and all that stuff you seem to have difficulty finding.

    Once you've built a sample project as-is, you can try modifying it, as a way to explore what happens when you change things. It's a lot easier to start with something that works (a sample project), and notice where you break it, than it is to puzzle out why your broken project isn't working.
  7. larswik thread starter macrumors 68000

    Sep 8, 2006
    Thanks Chown33

    - "You can test it on your computer by creating a new user account."
    I never even thought of that. Cool

    - "Learn to use to look for NSLog messages"
    No clue that existed

    - "Have you followed a complete "Build an App" tutorial, from start to finish?"
    I had no idea there was one. I started learning from the books and they say download Xcode and then I read the books. They never mentioned the Tutorial, I will run through it, if I can find it :)

    My dice app was a fun little distraction from the book. I think I learned a lot more by doing and testing then just the book. But once I finish the dice app I will do the tutorial and then start on the book again.

    Thanks Chown33

  8. larswik thread starter macrumors 68000

    Sep 8, 2006
    Quick Question, The purpose of an NSBundle regarding my audio file is that it will take the audio that has a path to a folder on my hard drive, and put it into an object, an NSBundle object?

  9. chown33 macrumors 604

    Aug 9, 2009
    First sentence from the NSBundle class reference:
    An NSBundle object represents a location in the file system that groups code and resources that can be used in a program. ​

    Given that you're using an application NSBundle, then the NSBundle object represents the application's "location in the file system that groups code and resources that can be used in a program".

    Since the "location in the file system" is where your sound files reside, it should be obvious that the NSBundle is how you access the files, but the NSBundle is not the actual files on disk, nor is it a particular sound file.

    To me, the key word in the class reference's sentence is represents. Every object represents something. If it's an NSNumber object, it represents a number. If it's an NSArray object, it represents an array of other objects.

    Each class of object (e.g NSNumber or NSArray) defines, for all objects of that class, what things you can do with the objects. And by omission, the class also defines what you can't do with objects of that class. For NSNumber, you can get other representations (e.g. int, float, double), but you can't set a new value. For NSArray, you can index the arrayed objects by number, but you can't change them. If you need a mutable array representation, you have to use an NSMutableArray representation.

    The concepts of representation (objects represent something), and capabilities determined by class (i.e. the methods and properties of the class) are fundamental to all object-oriented programming.

    All software consists entirely of representations. This bit-pattern represents an integer of 32-bits. That bit-pattern represents the memory address (i.e. pointer) of a bit-pattern representing a floating-point number of 64-bits. The 8-bit field at the high end of a floating-point representation represents the exponent. Except the high bit represents the sign. And so on up and down the scale of representations.

    So you break things down into the most suitable representation. And you build things up from simpler representations. It's all about what represents what.
  10. larswik thread starter macrumors 68000

    Sep 8, 2006
    I did read the part that you mentioned. Some concepts and code stick with me pretty fast and other things leave me baffled still. It took for ever to learn / understand [self = super init], and even after Jim showed me countless examples. Then one day it clicked and seemed so easy. The [self = super init] was the whole reason I stopped learning Objc - C in the first place. That sent me back to C and then to my Pascal class, now I get it.

    Once I finish my Dice program test I will hit the books again. I need a distraction from a year of just command line programming.

    The one thing I am learning is that it's the foundation of how things work that is important. I understand that I send messages to methods. That is true for every object and class (as far as I know). Like you said "Every object represents something", this is part of learning the foundation.

    Thanks for the detailed explanation Chown33

  11. jiminaus macrumors 65816


    Dec 16, 2010
    Wirelessly posted (Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5)

    Lars, write on the board 100 times.

    "I send messages to objects, not methods."

Share This Page