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 9101429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:07:46+00:00 2026-06-17T01:07:46+00:00

I am trying to play a .wav file using Audio Toolbox. I have this

  • 0

I am trying to play a .wav file using Audio Toolbox. I have this so far:
However my file will not play. The If condition is triggered right, however it doesn’t play.
It will print the error message if the file isn’t there however. Any clue what is wrong?

-(void) playSound : (NSString *) fName : (NSString *) ext
{

    SystemSoundID audioEffect;
    NSString *path  = [[NSBundle mainBundle] pathForResource : fName ofType :ext];
    if ([[NSFileManager defaultManager] fileExistsAtPath : path])
    {
        NSURL *pathURL = [NSURL fileURLWithPath : path];
        AudioServicesCreateSystemSoundID((__bridge CFURLRef) pathURL, &audioEffect);
        AudioServicesPlaySystemSound(audioEffect);
    }
    else
    {
        NSLog(@"error, file not found: %@", path);
    }
    AudioServicesDisposeSystemSoundID(audioEffect);;
}
  • 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-06-17T01:07:48+00:00Added an answer on June 17, 2026 at 1:07 am

    You can’t dispose of the sound ID immediately after telling it to play, since this causes the playback to stop. That’s why you didn’t hear it in the first place.

    What you should do instead is hold a reference to the ID in a property on whatever object is responsible for creating it (e.g., a view controller). You’d declare it like this in your interface declaration:

    @property(nonatomic, assign) SystemSoundID audioEffect;
    

    …and subsequently assign to it like this:

    AudioServicesCreateSystemSoundID((__bridge CFURLRef) pathURL, &_audioEffect);
    

    This will not only allow you to properly dispose of it at a later time when you know you’re done with it (e.g. in viewDidUnload), but will also prevent you from having to read the file in from disk each time you want to play it back, since each ID can be played an unlimited number of times.

    One final hint: you can ask for the URL to a bundle resource directly instead of requesting a string and then transforming it to a URL.

    NSURL *audioURL = [[NSBundle mainBundle] URLForResource:fName withExtension:ext];
    if([[NSFileManager defaultManager] fileExistsAtPath:[audioURL path]])
        // ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to play audio buffered sound (.wav) using AudioTrack. Please see the
I'm trying to save some audio data to a WAV file -- I have
I am trying to play a sound file in Java. I have written this
I am trying to play a simple wav file using PyGame Subset for Android.
I am trying to play a *.wav file with Java. I want it to
I am trying to play a video file using JMF but it gives me
I'm trying to play a 24bit audio file with my AutoHotkey app. It just
I'm trying to embed and then play back a .wav file in a C++/CLI
I am trying to load a *.wav file to a byte array using C#
I'm trying to write some very simple code to play an audio file. The

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.