Audio Player in iPhone
Audio and video is 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.
Add the AVFoundation frame work.
Framework Capture15 --> Add Capture15 --> Existing FrameWork Capture 15 --> AVFoundation Frame work.
# import < UIKIT/UIKIT .H>
@ interface divAudioPlayerviewController : UIView Controller.
# import “divAudio player viewController .h”
@ implementation divAudioplayerviewController
// 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];
// Setting Volume:
[ audioplayer set volume :1] // 0 to 1 (max value is 1)
// Repeat play:
Subscribe to our youtube channel to get new updates..!
[ audioplayer setNumberofLoops:2];
// prepare to play:
[ audioplayer PrepareToplay];
IOS Certification Training
: Learn how to use iOS, from beginner basics to advanced techniques, with hundreds of online video tutorials taught by industry experts.
// setting delegate:
[ audioplayer setDelegate: self]
[ audioplayer play];
[ audioplayer pause];
[ audioplayer stop];
[ super viewDidLoad];
-(void) audioplayerDidFinishplaying: (AVAudio player *)
Player Successfully : (Bool)flag
NSLog ( @ “ Audioplayer DidFinishplaying is successfully”)
NSLog ( @ “AudioplayerDidFinishplaying is un successfully”)
-(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
Subscribe For Free Demo
Free Demo for Corporate & Online Trainings.