PDA

View Full Version : No sound on my final build




larswik
Jun 30, 2011, 01:30 PM
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?

-Lars



mfram
Jun 30, 2011, 02:16 PM
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.

larswik
Jun 30, 2011, 02:34 PM
Here is the source for the audio

-(void)playAudio{
sound = [[NSSound alloc] initWithContentsOfFile: @"/Users/larspro/diceRollSound.aif" byReference:YES];
[sound play];
}

chown33
Jun 30, 2011, 03:34 PM
-(void)playAudio{
sound = [[NSSound alloc] initWithContentsOfFile: @"/Users/larspro/diceRollSound.aif" byReference:YES];
[sound play];
}

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.
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSBundle_Class/Reference/Reference.html

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

Also see "NSBundle Additions":
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSBundle_AppKitAdditions/Reference/Reference.html

larswik
Jun 30, 2011, 03:48 PM
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 :)

-Lars

chown33
Jun 30, 2011, 04:25 PM
I build it and it runs on my machine but send it to a friend and they can't open it.

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 Console.app 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.


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

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.

larswik
Jul 1, 2011, 12:40 AM
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 Console.app 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

-Lars

larswik
Jul 1, 2011, 02:06 PM
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?

-Lars

chown33
Jul 1, 2011, 02:22 PM
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?

First sentence from the NSBundle class reference:
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSBundle_Class/Reference/Reference.html
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.

larswik
Jul 1, 2011, 04:20 PM
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

-Lars

jiminaus
Jul 1, 2011, 09:50 PM
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."