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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:04:09+00:00 2026-06-03T12:04:09+00:00

In my app I have 52 mp3 and when I load my view controller

  • 0

In my app I have 52 mp3 and when I load my view controller I alloc all 52 mp3 in this way:

NSString *pathFrase1 = [NSString stringWithFormat:@"%@/%@",[[NSBundle mainBundle] resourcePath],[NSString stringWithFormat:@"a%d_1a.mp3",set]];
NSURL *filePath1 = [NSURL fileURLWithPath:pathFrase1 isDirectory:NO];
f1 = [[AVAudioPlayer alloc] initWithContentsOfURL:filePath1 error:nil];
[f1 prepareToPlay];

but it’s very slow when I open viewcontroller, then is there a way to alloc mp3 when I use it? and release its AVAudioPlayer??

  • 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-03T12:04:11+00:00Added an answer on June 3, 2026 at 12:04 pm

    Sure, but there will be a delay as the AVAudioPlayer is allocated and prepared for playing. Can you predict what will play and when? If so, maybe you can load a couple of seconds before you need a particular mp3 to play.

    An alternative, which may not work depending on your timing requirements, is the following:

    - (void)prepareAudioPlayer {
        static int index = -1;
        index = index + 1;
        if (index < [[self FileNames] count]) {
            NSError *err = nil;
            NSString *audioFilePath = @""; // Figure out how to get each file name here
            NSURL *audioFileURL = [NSURL fileURLWithPath:audioFilePath];
            AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:audioFileURL error:&err];
            if (err) {
                NSLog(@"Audio Player Error: %@", [err description]);
            }
            [player prepareToPlay];
            // Add this player to the "AudioPlayers" array
            [[self AudioPlayers] addObject:player];
            // Recurse until all players are loaded
            [self prepareAudioPlayer];
        }
    }
    

    This solution requires properties of FileNames and AudioPlayers.

    Once this is set up, you could do something like the following (probably in viewDidLoad):

    // Make the file name array 
    [self setFileNames:[NSMutableArray array]];
    // Initiate the audio player loading
    [self performSelectorInBackground:@selector(prepareAudioPlayer) withObject:nil];
    

    Later, when you need to play a particular file, you can find the index of the file name in the FileNames array and the call play on the AVAudioPlayer for that index in the AudioPlayers array.

    This seems like maybe not the best way to do things, but it might work if you require it this way.

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

Sidebar

Related Questions

I have an app with in-app downloading. I successfully download mp3 files in this
This is a continuation of the question here: JBoss - does app have to
I have an app that have several views. In one view I would like
I have abillity to listen to mp3 song in my app. I am using
I have my app successfully streaming an MP3 via AVPlayer. I implemented a MPVolumeView
I'm dowloading a mp3 file when the app is in background. Does iOS have
i have created an app with 16 btns,every btn plays a sound mp3.my app
I have a small (200kb) mp3 in the res/raw folder of my android app.
hi i have created a new mp3 player app for my owm. In that
I have 20mb of mp3 files I want to add into my app for

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.