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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:02:14+00:00 2026-06-10T13:02:14+00:00

How can I play more than one .m4a file consecutively? Presently, my function starts

  • 0

How can I play more than one .m4a file consecutively?

Presently, my function starts playing one, using AudioServicesPlaySystemSound etc., uses AudioServicesAddSystemSoundCompletion to select a callback, and then returns. When the sound is done, the callback lets my software continue.

This is a LOT of coding whenever there is back to back sound.

Can my software start a .m4a playing, and SOMEHOW wait for it to complete, waiting waiting for its callback to set a flag? Can I use pthread software to do a wait loop with a multitasking pause?

Here’s my code so far…

// Restore game_state to continue game after playing sound file.
int game_state_after_sound;
void play_sound_file_done (
SystemSoundID ssID,
void calling_class
)
{
printf(“\n play_sound_file_done.”);
// Sound is now done, so restore game_state and continue to manage_game from where left off:
game_state = game_state_after_sound;
[ (GeController
)calling_class manage_game];
}

// Plays sound_file_m4a and returns after playing has completed.
-(void) play_sound_file: (NSString *) sound_file_m4a
{
    printf("\n play_sound_file '%s' ", [sound_file_m4a UTF8String] );
    NSString *soundPath = [[NSBundle mainBundle] pathForResource:sound_file_m4a ofType:@"m4a"]; 
    SystemSoundID soundID; 

    AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath: soundPath], &soundID); 
    AudioServicesPlaySystemSound (soundID); 
    AudioServicesAddSystemSoundCompletion ( soundID, NULL, NULL, play_sound_file_done, (void*)self ); 

    game_state_after_sound = game_state;
    game_state =  DELAY_WHILE_PLAYING_SOUND;
}

********************************** AVPlayer work-in-progress…

But this produces no sound.

#import <AVFoundation/AVFfoundation.h> 

-(void) play_queued_sounds: (NSString *) sound_file_m4a
{
    printf("\n queue_sound_file: '%s' ", [sound_file_m4a UTF8String] );

    AVPlayerItem *sound_file = [[AVPlayerItem alloc] initWithURL:[NSURL URLWithString:[[NSBundle mainBundle] pathForResource:sound_file_m4a ofType:@"m4a"]]]; 
    AVQueuePlayer *player = [AVQueuePlayer queuePlayerWithItems:[NSArray arrayWithObjects:sound_file, nil]];  

    [player play]; 

    return;
}
  • 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-10T13:02:15+00:00Added an answer on June 10, 2026 at 1:02 pm

    I could not get the AVQueuePlayer solution to work.

    GREAT SOLUTION:
    For each sound to play, spin up a thread that awaits then locks a mutex, then does AudioServicesPlaySystemSound. Just spin up a thread for each successive sound to play, and use the pthread mutex to delay each successive thread until the AudioServicesAddSystemSoundCompletion function unlocks the mutex. Works like a champ.

    This is 21st century embedded programming: Throw threads at the problem!

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

Sidebar

Related Questions

I can't play more than one sound per page. I created 2 instances of
I'm making a Asteroids game but I can not get to play more than
If I have A main page which composed from more than one section (header,main,side,etc..),each
I need to have the possibility to play more than one video in an
I'm writing an iOS app which can play MIDI and output its content using
As a developer that has worked on more than one python project at once,
I am having difficulties with pages that have more than one <audio> when I
I see that you can play ogg audio files, but I was wondering if
How I can play the video on android from url. The url is :
I have an android app where in my Main activity I can play music

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.