To use avaudioplayer, you must first import: avfoundation. Framework
Initialization:
_Player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:backgroundMusicPath] error:&error];
Attribute:
1. Volume
Player. volume = 0.8; // 0.0 ~ Between 1.0
2. Number of cycles
Player. numberofloops = 3; // by default, only playback is performed once.
3. Playback position
Player. currenttime = 15.0; // you can specify any position to start playing.
4. Number of Audio Channels
Nsuinteger channels = player. numberofchannels; // read-only attribute
5. Duration
Nstimeinterval duration = player. dueration; // gets the sampling duration.
6. Meter count
Player. meteringenabled = yes; // enable the meter count function [Player meters]; // update the meter readings // read the average power level and peak level of each sound channel, representing the number of decibels per sound channel, the range is-100 ~ Between 0. For (INT I = 0; I <player. numberofchannels; I ++) {float power = [Player averagepowerforchannel: I]; float peak = [Player peakpowerforchannel: I];}
7. Speed Rate
player.rate = 1.0f;
Callback:
-(Void) audioplayerdidfinishplaying :( avaudioplayer *) player successfully :( bool) Flag {// action executed at the end of playback}-(void) warn :( avaudioplayer *) player error :( nserror *) error {// The Action for decoding the error execution}-(void) audioplayerbegininteruption :( avaudioplayer *) player {// code for handling the interrupt}-(void) audioplayerendinteruption :( avaudioplayer *) player {// code for handling the end of the interrupt}