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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:09:47+00:00 2026-05-27T12:09:47+00:00

I have an AVAudioPlayer instance attached with a view controller. @property (nonatomic, retain) AVAudioPlayer

  • 0

I have an AVAudioPlayer instance attached with a view controller.

@property (nonatomic, retain) AVAudioPlayer *previewAudioPlayer;

I initialized it in -viewDidLoad.

NSError *error = nil;
AVAudioPlayer *aNewPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:&error];
self.previewAudioPlayer = aNewPlayer;
[aNewPlayer release];

[self.previewAudioPlayer prepareToPlay];

And, i release it in the view controllers -dealloc method.

- (void)dealloc {
    [_previewAudioPlayer pause];
    [_previewAudioPlayer release];

    [super dealloc];
}

Audio is played on a button click.

[self.previewAudioPlayer play];

Now, if the view controller is dismissed or pop’ed, dealloc should be called and audio player should stop and view controller should be destroyed. However, this doesn’t happen. The audio doesn’t stop, because the dealloc is not called until the audio stops playing. What’s going on here? And, how can i make sure that if user is dismissing the controller than the audio stops.

  • 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-27T12:09:47+00:00Added an answer on May 27, 2026 at 12:09 pm

    You can pause or stop the audio when the view gets dismissed, that is when the viewWillDisappear: or viewDidDisappear: methods get called.

    - (void)viewWillDisappear:(BOOL)animated 
    {
       [_previewAudioPlayer stop];
       [super viewWillDisappear:animated];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view where a video record, then I have a section AVAudioPlayer,
I have an instance of AVAudioPlayer running inside one of my tabs. It is
I have a UIViewController residing in a UINavController. The view controller which is playing
I am using the AVAudioPlayer framework, and I have several sounds that play one
Have you ever seen any of there error messages? -- SQL Server 2000 Could
I have problem with AVAudioPlayer in iphone when ever the my ipod is lock(sleep)
Alright I have two problems. I'm using AVAudioPlayer to play a simple audio file
i am building an music application in iphone which i have made using AVAudioPlayer,and
I have an issue with my AVAudioPlayer in which if it is paused, I
I have to start more than one processes simultaneously - an AVAudioPlayer's play, a

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.