• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Why the file does not open
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why the file does not open


  • Subject: Re: Why the file does not open
  • From: Jens Alfke <email@hidden>
  • Date: Tue, 10 Feb 2009 08:55:12 -0800


On Feb 10, 2009, at 8:43 AM, Gabriele Palmas wrote:

I have a file in my project called track.aif. When I run my app the file cannot be found because the this set of following instructions don't work as suppose to.

- (BOOL)getFilename:(char*)buffer maxLenth:(int)maxBufferLength
{
  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

You're looking in the wrong directory. Data files in an app live in the Contents/Resources/ subdirectory by default. (See the Apple docs on the structure of a bundle, if you want the gory details.) There are API calls to find resources. You should be locating this file via:

[[NSBundle mainBundle] pathForResource: @"track" ofType: @"aif"]

  return [file getCString:buffer maxLength:maxBufferLength encoding:NSUTF8StringEncoding];

This will basically work, but it's wiser not to rely on the fact that the filesystem uses UTF-8 encoding (since there are a few edge cases involving Unicode minutae that make my head spin.) Instead, use

return [file fileSystemRepresentation];

This returns a const char* suitable for use with file system calls that take C strings. (You don't have to free that pointer; it's autoreleased for you.)

—Jens

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Why the file does not open (From: Gabriele Palmas <email@hidden>)

  • Prev by Date: Why the file does not open
  • Next by Date: Why a simple aif file doesn't play?
  • Previous by thread: Why the file does not open
  • Next by thread: Why a simple aif file doesn't play?
  • Index(es):
    • Date
    • Thread