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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:19:53+00:00 2026-05-27T20:19:53+00:00

My previous code was – (void) playaudio: (id) sender { NSString *filePath = [[NSBundle

  • 0

My previous code was

- (void) playaudio: (id) sender
{
   NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Theme" 
                                                 ofType:@"mp3"];   
   NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];   

   self.audioPlayer = [[AVAudioPlayer alloc] 
                initWithContentsOfURL:fileURL error:nil];

   self.audioPlayer.currentTime = 0;
   [self.audioPlayer play];
}

- (void)pause: (id)sender

{
   [audioPlayer pause]; 

}

- (void)stop: (id)sender

{

  [audioPlayer stop];

 }

In the above code pause button was acting as stop button rather than pause where it was supposed to resume the audio file.

Now i have added simple statements to my code it is working to some extent but still not upto my expectations.

What happening now is when you play audio file and click on pause button nothing happens but when you click on the stop button it stops playing audio file and then when you press the pause button it resumes the audio file from where it was stopped by pressing stop button. Why is that when you press stop buttons only then pause button functions but not before that. I don’t get this why?

Any ideas why this is happening

- (void)pause: (id)sender

{

  [audioPlayer pause];    
  [audioPlayer prepareToPlay];
  [audioPlayer play];


}


- (void) stop: (id) sender

{
    [audioPlayer stop];

 }

If anyone have any ideas that why this is happening. Will appreciate help.

Thanks in advance.

  • 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-27T20:19:54+00:00Added an answer on May 27, 2026 at 8:19 pm

    You shouldn’t be recreating the audio file every time you play it. Here is how you could do this:

    - (void) playaudio: (id) sender
    {
       if(self.audioPlayer == nil) {
          NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Theme" 
                                                     ofType:@"mp3"];   
          NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];   
    
          self.audioPlayer = [[AVAudioPlayer alloc] 
                    initWithContentsOfURL:fileURL error:nil];
    
          self.audioPlayer.currentTime = 0; //this could be outside the if if you want it to start over when they hit play
       }
       [self.audioPlayer play];
    }
    
    - (void)pause: (id)sender
    
    {
       if([audioPlayer isPlaying]){
           [audioPlayer pause]; 
       } else {
           [audioPlayer play];
       }
    
    }
    
    - (void)stop: (id)sender
    
    {
    
      [audioPlayer stop];
    
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a previous html code. <table width=600px cellspacing=0 border=1 id=mainTable> <tr> <th> Name
Please refer my previous question for code sample Sockets: sometimes (rarely) packets are lost
I have code examples from some of my previous work that help me to
In previous versions of Visual Studio I remember I saw the error code/number in
I have taken over some code from a previous developer and have come across
I'm trying to get some code working that a previous developer has written. Yep,
I have started working on some code left behind by previous developers, and I'm
I sometimes check out some previous version of the code to examine or test.
This question is related to a previous question of mine That's my current code
How to get previous page URL using jQuery? I am using the following code

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.