Home  >  Blog  >   iPhone  > 

Audio Player in iPhone

Rating: 4

Audio player:-

Audio and video are quite common in the latest devices. An instance of the AVAudioPlayer class, called an audio player, provides playback of audio data from a file or memory. It is supported in iOS with the help of AV FOUNDATION.FRAMEWORK and Media Player. framework respectively. 

Interested in taking up Online IOS Training? You are at the Right Place. Start Learning!                                                                        


Add the AVFoundation Framework.

Framework Capture15 --> Add Capture15  --> Existing FrameWork Capture 15 --> AVFoundation Frame work.

.h file:-

# import   < UIKIT/UIKIT .H>
# import 
@ interface divAudioPlayerviewController : UIView Controller.
{                                                           {


.m file:-

# import  “divAudio player viewController .h”
@ implementation divAudioplayerviewController
-(void) viewDidLoad

Capture 15//

MindMajix Youtube Channel

How to get resources file path:

  • Using an audio player you can:
  • Play sounds of any duration
  • Play sounds from files or memory buffers
  • Loop sounds
  • Play multiple sounds simultaneously, one sound per audio player, with precise synchronization
  • Control relative playback level, stereo positioning, and playback rate for each sound you are playing
  • Seek to a particular point in a sound file, which supports such application features as fast forward and rewind
  • Obtain data you can use for playback-level metering
NSString   * path  =  [[ NSBundle  mainBundle]
PathForResources  : @  “or   Enduko emo” Of Type :@ “MP3”];
NSURL    * URL   =  [ NSURL fileURLwithpath :path];
Av AudioPlayer   *  audioPlayer    =   [[ AVAudio player  alloc]
                  Init WithContentsof   URL:url    error :nil];

Capture 15//

Setting Volume:

[ audioplayer  set volume  :1]  //   0 to 1  (max value is 1)

Capture 15//

Repeat play:

[ audioplayer  setNumberofLoops:2];

Capture 15//

prepare  to play:

[ audioplayer  PrepareToplay];

Capture 15//

Setting  Delegate:

[  audioplayer  setDelegate: self]

Capture 15//


[ audioplayer  play];

Capture 15//


[ audioplayer   pause];

Capture 15//


[  audioplayer stop];
[ super viewDidLoad];

Capture 15

-(void) audioplayerDidFinishplaying: (AVAudio player    *)
             Player  Successfully  : (Bool)flag
If (flag)
NSLog ( @ “ Audioplayer  DidFinishplaying is successfully”)
 NSLog ( @ “AudioplayerDidFinishplaying  is un successfully”)

Capture 15

 -(void) audioplayerDecade  ErrorDidOccur: (AV player    *)
                            Player error : ( ns error       *) error
UIAlertView     * alert  =   [[ UIAlertview   alloc]
InitwithTitle: @  “message” message: [NSString
StringwithFormat: @ “% @”, error .user info] delegate :nil
Cancel  button title: @ “ok” otherButtonTitles :nil];
[ alert show];
[ alert release];


Frequently Asked IPhone Interview Questions & Answers


Join our newsletter

Stay updated with our newsletter, packed with Tutorials, Interview Questions, How-to's, Tips & Tricks, Latest Trends & Updates, and more ➤ Straight to your inbox!

Course Schedule
IOS Development TrainingMar 28 to Apr 12
IOS Development TrainingApr 01 to Apr 16
IOS Development TrainingApr 04 to Apr 19
IOS Development TrainingApr 08 to Apr 23
Last updated: 26 March 2023
About Author
Remy Sharp
Ruchitha Geebu

I am Ruchitha, working as a content writer for MindMajix technologies. My writings focus on the latest technical software, tutorials, and innovations. I am also into research about AI and Neuromarketing. I am a media post-graduate from BCU – Birmingham, UK. Before, my writings focused on business articles on digital marketing and social media. You can connect with me on LinkedIn.

Recommended Courses

1 /15