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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:05:20+00:00 2026-05-20T02:05:20+00:00

I added a sound file in my Xcode resources folder. I want to play

  • 0

I added a sound file in my Xcode resources folder.

I want to play the sound file by AVAudioPlayer

I can use the image by [UIImage imageNamed:@”xxxx.png”];

But I don’t know how to attach the file to the AVAudioPlayer.

Thank you for helping me.

  • 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-20T02:05:20+00:00Added an answer on May 20, 2026 at 2:05 am

    In the .h file

     #import <AudioToolbox/AudioToolbox.h>
     #import <AVFoundation/AVFoundation.h>
    
    @interface RootViewController : UIViewController {  
    
    AVAudioPlayer *audioPlayer;
    
    }
    
    @property(nonatomic, retain) AVAudioPlayer *audioPlayer;
    

    & also synthesize this in your .m file

    Now in your .m file

    NSString *mp3Path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"test.mp3"];
    NSURL *mp3Url = [NSURL fileURLWithPath:mp3Path];
    
    NSError *err;
    AVAudioPlayer *audPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:mp3Url error:&err];
    [self setAudioPlayer:audPlayer];
    if(audioPlayer)
            [audioPlayer play];
    
    [audPlayer release];
    

    Also add the follwing frameworks

    AudioToolbox.framework & AVFoundation.framework

    Hope it helps

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

Sidebar

Related Questions

I'm using PHP, i want to play sound file when new record added to
I added a mask to UIView's layer: CGImageRef maskImageRef = [UIImage imageNamed:Icon.png].CGImage; CALayer maskLayer
I want to play a sound in my application. Nothing special, just a little
I have huge number of sound bytes which I want to use in my
I added a wav file to my Windows Mobile app and I want to
So I added a sound (.wav) in my UIButton when pressed, but It outputs
I would like to play a sound when someone click home button of iphone/ipad,
I've managed to make it play sound but it never gets EOS message. And
So in my main activity I added an image button and it works fine.
I have a movie file that does work. I added a tableview controller inside

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.