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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:54:30+00:00 2026-05-31T15:54:30+00:00

I hope the title is not too misleading… :) I play a system sound

  • 0

I hope the title is not too misleading… 🙂

I play a system sound and add the SoundCompletion-Callback to it like so:

AudioServicesAddSystemSoundCompletion(soundID, NULL, NULL, completionCallback, (__bridge_retained void *)self);

Whereas «self» is a simple NSObject

In the completion callback I try to call the playing routine again:

I had to add the __bridge_transfer and the __bridge_retained to the casts, otherwise I get errors, crashes, or other unexpected behaviour.

But the whole thing doesn’t work despite all that.

I store the sounds to play in an NSMutableArray, grab the first entry of the array and play it, add the sound completion and hope stuff happens.
But – with all that retained-transfer stuff, the NSMutableArray is empty on the second call…

Here’s the code:

static void completionCallback (SystemSoundID  mySSID, void *myself) {

    NSLog(@"Audio callback");

    AudioServicesRemoveSystemSoundCompletion (mySSID);
    AudioServicesDisposeSystemSoundID(mySSID);

    [(__bridge_transfer Speaker *)myself speakCharacter];

    CFRelease(myself); // I heard I need this?

}

-(void)speakCharacter{

    if([sounds count] > 0){

        NSString *soundToPlay = [sounds objectAtIndex:0];
        [sounds removeObjectAtIndex:0];
        NSLog(@"TxtToSpeak %@", soundToPlay);
        CFURLRef        soundFileURLRef;
        NSURL *path = [[NSBundle mainBundle] URLForResource:[soundToPlay uppercaseString] withExtension:@"aif"];
        soundFileURLRef = (__bridge CFURLRef)path;
        SystemSoundID soundID;
        AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
        AudioServicesAddSystemSoundCompletion(soundID, NULL, NULL, completionCallback, (__bridge_retained void *)self);
        AudioServicesPlaySystemSound (soundID);
    }
}

[EDIT] – ANSWERING MY OWN QUESTION:

Always nice to find it out myself 🙂

Turns out, I was almost there.

The call to set up the callback is as follows:

AudioServicesAddSystemSoundCompletion(soundID, NULL, NULL, completionCallback, (__bridge_retained void *)self);

Then, in the callback-function, I do this:

myClass *theClass = (__bridge myClass *)myself;
    CFRelease(myself);
    [theClass playNextSound]; // The routine that plays the sounds

And it works…

  • 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-31T15:54:31+00:00Added an answer on May 31, 2026 at 3:54 pm

    I couldn’t answer my own question since I was too fast for StackOverflow – so just to make this complete, I add the answer again 🙂

    Turns out, I was almost there.

    The call to set up the callback is as follows:

    AudioServicesAddSystemSoundCompletion(soundID, NULL, NULL, completionCallback, (__bridge_retained void *)self);
    

    Then, in the callback-function, I do this:

    myClass *theClass = (__bridge myClass *)myself;
    CFRelease(myself);
    [theClass playNextSound]; // The routine that plays the sounds
    

    And it works…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hope the title doesn't sound too subjective; I absolutely do not mean to
I hope the title explains what I'd like to achieve. If not, please read
I hope the title is not too confusing. I am trying to make folders
I hope my title is not misleading, but what I'm looking for is a
Hope my title is not too confusing. Please let me know if there is
I hope the title and following text are clear, I'm not very familiar with
I hope the title isn't too unclear.. Lets say we are writing the back-end
Hope the title is not that confusing - honestly said I had no idea
Ok hope that title wasn't misleading I have (among other columns) the following info
I hope the title isn't too confusing, I'll try to explain better below. Suppose

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.