Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 571743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:32:21+00:00 2026-05-13T13:32:21+00:00

I am writing an iPhone app that when a certain thing occurs, a sound

  • 0

I am writing an iPhone app that when a certain thing occurs, a sound is played. I have trying using different WAV, MP3, M4A files and have intermittent problems. The below code works fine in the simulator but the MP3 does not play on the iPhone. (3GS if it matters). Any ideas? I have changed the mp3 file to a wav and it will work for the one supplied below (knock_knock), but not another. Possibly the way it is encoded?

Any help is appreciated. Thanks

Here is the code:

SystemSoundID soundID;
NSString *soundFile;

if (something == somethingelse) {
    soundFile = [[NSBundle mainBundle] pathForResource:@"knock_knock" ofType:@"wav"];
}
else {
   soundFile = [[NSBundle mainBundle] pathForResource:@"strike" ofType:@"mp3"];
}
   AudioServicesCreateSystemSoundID((CFURLRef)
                                 [NSURL fileURLWithPath:soundFile]
                                 , &soundID);
AudioServicesPlaySystemSound(soundID);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T13:32:22+00:00Added an answer on May 13, 2026 at 1:32 pm

    System sounds have to be uncompressed. I ran into this and changed my code to use AVAudioSession, and AVAudioPlayer. Of the top of my head, something like this (needs better error checking)

        -(void)load {
        NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: [self path]];
        if (fileURL) {
    
            AVAudioPlayer *newPlayer =
            [[AVAudioPlayer alloc] initWithContentsOfURL: fileURL
                                                   error: nil];
            [fileURL release];
            [self stop];
            self.player = newPlayer;
            [newPlayer release];
    
            [self.player prepareToPlay];
        }   
    }
    
        -(void)play {
    
        if (self.player == nil)
            [self load];
    
        AVAudioSession *audioSession = [AVAudioSession sharedInstance];
        NSError *err = nil;
        [audioSession setCategory: AVAudioSessionCategoryAmbient error:&err];
        if(err){
            NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
            return;
        }
        [audioSession setActive:YES error:&err];
    
        self.player.currentTime = 0;
        [self.player play]; 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an iPhone App that relies on getting the device location. Management have
I'm writing server-side programs in PHP for an iPhone app. And I have no
I'm writing an iPhone app for a client, and they have requested a feature
I'm writing an iPhone app that is mainly centered around grid patterns, so I
I'm writing an iPhone app that uses OpenAL. When the application starts, the music
I'm writing an iPhone app that requests data from a web service, and in
I am writing an iPhone app that needs to be able to upload photos
I am writing an iPhone app that needs to calculate the square root of
Right now i'm writing an iPhone app that will interact with a network, and
I'm writing a native iPhone app that contains a UIWebView component. This component accesses

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.