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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:24:42+00:00 2026-06-05T00:24:42+00:00

I’ve searched multiple forums including this one, and cannot find a solution to my

  • 0

I’ve searched multiple forums including this one, and cannot find a solution to my problem. I have a sound file set to play when my “IQTest” view controller loads. It plays fine, and I can stop the sound in “IQTest” view controller.

IQTest.h

@interface IQTest : UIViewController
{
AVAudioPlayer *theAudio;
}
@property (nonatomic, strong) AVAudioPlayer *theAudio;
@end

IQTest.m

- (void)viewDidLoad
{
[super viewDidLoad];

NSString *path = [[NSBundle mainBundle] pathForResource:@"IQTestBackgroundMusic" ofType:@"mp3"];
AVAudioPlayer* soundTrack=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
soundTrack.numberOfLoops = -1;
self.theAudio = soundTrack;
[theAudio play];
}

I want to stop playing the sound when a user presses the button in “IQTestQuestionThree”‘s view controller, but when I try at stop the sound, it either keeps playing, or my app crashes. I’ve tried multiple ways, and have yet to find one to stop my sound.

IQTestQuestionThree.m

- (IBAction) question3Answer1
{
IQTest *IQTestAudio = [[IQTest alloc] init];
[IQTestAudio.theAudio stop];

iqScaryFace.hidden = NO;
homeButton.hidden = NO;
homeButtonLabel.hidden = NO;
answer1Button.hidden = YES;
answer2Button.hidden = YES;
answer3Button.hidden = YES;
answer4Button.hidden = YES;
}

Thank you for any help I can get.

  • 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-05T00:24:44+00:00Added an answer on June 5, 2026 at 12:24 am
    - (IBAction) question3Answer1
    {
        IQTest *IQTestAudio = [[IQTest alloc] init];
        [IQTestAudio.theAudio stop];
    

    This code creates a brand new IQTest object (which is a UIViewController subclass — and therefore has a confusing name), and then calls its stop method.

    This brand-new IQTest object (maybe rename it IQTestViewController?) was just created — it isn’t the same object that started playing the sound. So you’re expecting it to stop playing something it has no control over. (At least, I don’t expect it to work, without seeing more code.)

    I want to stop playing the sound when a user presses the button in
    “IQTestQuestionThree”‘s view controller

    How is the view hierarchy structured?

    Is IQTestQuestionThree a view controller whose parent is IQTest? (Again, consider renaming IQTestQuestionThree to something like IQTestQuestionThreeViewController.) If so, you could use the delegate pattern to have IQTestQuestionThree alert IQTest to stop playing the sound.

    If your view controller hierarchy is more complex, and/or if there are other view controllers in other places that might want to stop playing the sound, consider creating a model class for sound playing to act as a proxy for playing sounds, instantiate that model class in your app delegate, and pass it along to all the view controllers that need to control audio.

    (UIViewController subclasses, by convention, have “ViewController” as a suffix on their name. You’ll find this is the case in Apple’s source code. If you want to write your code for readability, you should follow conventions for what language in which you’re writing as closely as possible.)

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a reasonable size flat file database of text documents mostly saved in
I have some data like this: 1 2 3 4 5 9 2 6
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.