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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:22:25+00:00 2026-06-15T06:22:25+00:00

I have been trying to create a app that when I press a button

  • 0

I have been trying to create a app that when I press a button it plays a sound but then when I press the same button again it plays a different sound I don’t mind if it plays it totally random all the time or if it plays a different sound a time but the same order every time hope this make sense guys

Here’s all the code I have:

.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController



@class AVAudioPlayer;


@interface ViewController : UIViewController

-(IBAction)PlayRandomSound;
@property (nonatomic, retain) AVAudioPlayer *soundPlayer;




@end

.m

#import "ViewController.h"
#import <AVFoundation/AVAudioPlayer.h>
@interface ViewController ()

@end

@implementation ViewController


@synthesize soundPlayer = _soundPlayer;


-(IBAction)PlayRandomSound{

    int randomNumber = arc4random() % 8 + 1;

    NSURL *soundURL = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:[NSString stringWithFormat:@"Sound%02d", randomNumber] ofType:@"mp3"]];


    _soundPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL error:nil];

    [_soundPlayer prepareToPlay];
    [_soundPlayer play];


    NSLog(@"randomNumber is %d", randomNumber);
    NSLog(@"tmpFilename is %@", soundURL);
}

Here the errors I have in images

enter image description here

enter image description here

I have also inserted the AVFoundation.Framework and AudioToolbox.Frame

  • 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-15T06:22:27+00:00Added an answer on June 15, 2026 at 6:22 am

    You have many problems with this. It’s hard to answer your actual question because you have lots of little problems that are getting in the way.

    To give you some help:

    this is incorrect:

    #import <UIKit/UIKit.h>
    
    @interface ViewController : UIViewController
    
    @class AVAudioPlayer;
    
    @interface ViewController : UIViewController
    

    As the image you have posted, even Xcode is trying to help you. The @class forward declaration is in the wrong place. Try putting it just after the #import statements. Because of this your soundplayer isn’t being created properly and you are getting other warnings.

    You need to fix all the errors and then all the warnings and keep doing this until it builds cleanly.

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

Sidebar

Related Questions

I have been trying to create a simple app that parse an entire channel
I have been trying to create a menu panel with jQuery that can be
I have been trying to create a new google custom search engine, but when
I'm new here. I have been trying to create a video capture app using
I have been trying to create a simple application that will let the user
I have been trying to create an iphone app sending telnet command. However what
recently I been trying to create an android app that uses JSON Objects to
I've been trying to create an ASP.net - MVC app that uses entity framework
I have been trying to generate simple PDFs from my app so that I
I have been trying to create a ListView which I can sort using drag

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.