IOS-----Play Music with Avaudioplayer

Source: Internet
Author: User

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.

  1. Aac
  2. AMR (Adaptive multi-rate, a voice format)
  3. ALAC (Apple Lossless Audio Code)
  4. ILBC (Internet low bitrate Code, another language format)
  5. IMA4 (IMA/ADPCM)
  6. LINEARPCM (Uncompressed)
  7. Μ-law and A-law
  8. 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

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.