play music with Avaudioplayer
Avaudioplayer is a class that belongs to Avfoundation.framework. It functions like a powerful player. Avaudioplayer supports a wide range of audio formats ,
These are mainly the following formats.
- Aac
- AMR (Adaptive multi-rate, a voice format)
- ALAC (Apple Lossless Audio Code)
- ILBC (Internet low bitrate Code, another language format)
- IMA4 (IMA/ADPCM)
- LINEARPCM (Uncompressed)
- Μ-law and A-law
- MP3 (Mpeg-laudio Layer 3)
Using Avaudioplayer to play the audio is very simple, when the program control Avaudioplayer object loading audio is completed, you can call Avaudioplayer the following methods for playback controls
-play |
Start or resume playback. When the method is called, the program implicitly executes the Preparetoplay method if the audio is not already ready |
-Playattime |
(Nstimeinterval) Time: Starts at or resumes playback at a specified point |
-Ause |
Time out |
-Stop |
Stop it |
-Preparetoplay |
Ready to start playback. When the play method is called, the program implicitly executes the method if it is not already ready. |
Avaudioplayer loading the specified audio file, Avaudioplayer provides the following simple initialization method
-Initwithcontentsofurl:error:: |
Loads the audio file from the specified URL and returns the newly created Avaudioplayer object. |
-Initwithdata:error:: |
Loads the audio data represented by the specified NSData object and returns the newly created Avaudioplayer object |
Avaudioplayer provides the following properties to access information about an audio file |
Playing |
This read-only property returns whether the player is playing audio |
Volume |
This property is used to set and return the volume gain of the player. The gain value can be 0.0~1.0. |
Pan |
This property is used to set or return the stereo balance. If the property is set to-1.0, it is played completely on the left and if set to 0.0, the volume is the same, or if it is set to 1.0, it is played completely on the right. |
Rate |
This property sets or returns the playback rate. This property value supports 0.5 (half-speed playback) floating-point value between ~2.0 |
Enablerate: |
This property sets or returns whether the player is allowed to change the playback rate. |
Numberofloops: |
This property sets or returns the number of cycles of the player. If the property is set to a negative value, the player will play until the program calls the Stop method to stop playback. |
Delegate |
This property is used to set the proxy object for Avaudioplayer. |
Numberofchannels: |
The read-only property returns the number of audio channels |
Duration |
The read-only property returns the duration of the audio. |
CurrentTime: |
This property gets the playback point of the audio. |
Devicecurrenttime: |
The read-only property returns audio. |
Url: |
The read-only property returns the audio URL associated with the player. |
Data |
The read-only property returns the audio data associated with the player. |
IOS-----Play Music with Avaudioplayer