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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:04:28+00:00 2026-06-07T06:04:28+00:00

Im playing a sound in my app that I would like to loop. My

  • 0

Im playing a sound in my app that I would like to loop. My research into this hasnt quite sorted my issue.

my code .m

CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"ar4", CFSTR 
                                          ("wav"), NULL);


UInt32 soundID;
AudioServicesCreateSystemSoundID (soundFileURLRef, &soundID);
AudioServicesPlaySystemSound (soundID);

I think I need to put something like this in

numberOfLoops = -1;

But unsure how to implement in my code as I get undeclared error for numberOfLoops. Some advice would be very much appreciated

  • 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-07T06:04:28+00:00Added an answer on June 7, 2026 at 6:04 am

    Something like this should do your problem:

        NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
        resourcePath = [resourcePath stringByAppendingString:@"/YOURMUSICNAME.mp3"];
        NSLog(@"Path to play: %@", resourcePath);
        NSError* err;
    
        //Initialize our player pointing to the path to our resource
        player = [[AVAudioPlayer alloc] initWithContentsOfURL:
                     [NSURL fileURLWithPath:resourcePath] error:&err];
    
        if( err ){
            //bail!
            NSLog(@"Failed with reason: %@", [err localizedDescription]);
        }
        else{
            //set our delegate and begin playback
            player.delegate = self;
            [player play];
            player.numberOfLoops = -1;
            player.currentTime = 0;
            player.volume = 1.0;
        }
    

    Then if you want to stop it:

    [player stop];
    

    or pause it :

    [player pause];
    

    and also import it in your header file:

    #import <AVFoundation/AVFoundation.h>.   
    

    You should to ofcourse declare it in your header, then synthesize it.

    //.h and add the bold part:

    @interface ViewController : UIViewController <AVAudioPlayerDelegate> {

    AVAudioPlayer *player;
    }
    @property (nonatomic, retain) AVAudioPlayer *player;
    

    //.m

    @synthesize player;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So i have the following code. When no sound is playing in my app
I am making an app that plays audio... with each sound piece playing I
I want to record the sound of my iPhone-App. So like someone is playing
What I want is that my app should stop playing sound when it enters
How can I disable my iPhone app sound if the user is playing iPod
I have an application that starts playing a sound when user touches the uiview
Using jQuery, can you show me the syntax for playing a sound? I would
I have a plugin system in my app and I would like to prevent
Basically I'm writing a metronome app, but I'm using a sound file that, depending
I Have created an app that records and plays sound and I am looking

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.