IOS: avaudioplayer

Source: Internet
Author: User

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}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.