iOS Learning 45 Multimedia operations

Source: Internet
Author: User

1. Audio1> Audio Implementation Brief

There are four ways to play audio specifically in IOS:

    •  System sound Services (systems voice service)

    • OpenAL (cross-platform open source audio processing interface)

    • Audio Queue Services (playback and recording of a voice service)

    • Avaudioplayer (Advanced Audio player)

2> System sound Services (systems voice service)

① System Sound Services is the lowest and simplest voice playback service, by calling Audioservicesplaysystemsound This function can play some simple audio files.

② Limitations:

1. Sound length less than 30 seconds

2. Format:IMA4

3. unable to control playback progress

4. play the sound immediately after calling the method

5. no loop playback and stereo sound playback

③ Instance Code

    cfbundleref mainbundle;    Systemsoundid soundfileobject;     = Cfbundlegetmainbundle ();    Cfurlref soundfileurlref  = Cfbundlecopyresourceurl (Mainbundle, Cfstr (" Tsai Chin-love break " ), Cfstr ("wav"), NULL);     &soundfileobject);    Audioservicesplaysystemsound (soundfileobject);
3> OpenAL

① Introduction

OpenAL is a cross-platform , Open source Audio Processing interface

The best audio for developing your game

OpenAL consists of three entities:Listener (listener), source(source), buffer (cache)

   Audio Queue Services is primarily used to achieve recording , and in order to simplify the processing of audio files, it is often necessary to use the audiofileservices

② Development Steps

1. Get device

2. Associating a context to a device

3. Put the data in buffer

4. Link the buffer to a source

5. Play the source

OpenAL Information Website: http://www.devdiv.com/thread-19636-1-1.html
Http://www.cocoachina.com/bbs/read.php?tid-112679-page-1.html

Relative to the underlying API reference: http://blog.csdn.net/midfar/article/details/7233454

4> Avaudioplayer Introduction

We can think of Avaudioplayer as an advanced player that supports a wide range of audio formats , as follows:

    • Aac

    • AMR (Adaptivemulti-rate, Aformatforspeech)

    • ALAC (applelossless)

    • ILBC (Internetlowbitratecodec, Anotherformatforspeech)

    • IMA4 (IMA/ADPCM)

    • LINEARPCM (Uncompressed)

    • MP3 (Mpeg-1audiolayer3)

5> Avaudioplayer Advantages

    • Support for more formats

    • Can play audio files of any length

    • Supports loop playback

    • Multiple audio files can be played synchronously

    • Control playback progress and start playback from any point in the audio

6> Avaudioplayer Development Steps

    • Step one:avaudioplayer is included in the avfoundation Framework, so when developing the framework for importing audio first avfoundation.framework

Introducing Header Files

#import <AVFoundation/AVFoundation.h>

    • Step two: Avaudioplayer The initialization of the time needed to give a playback file

Avaudioplayer *avaudioplayer = [[Avaudioplayer alloc] Initwithcontentsofurl: File path Error:nil];

    • Step Three: Important attributes

Set initial volume size Audioplayer.volume = 1; (0.0 ~ 1.0)

Set the number of music plays audioplayer.numberofloops =-1; (as long as the negative is a loop play)

Playback progress audioplayer.currenttime = 0;

    • Step Four: Important methods

Pre-play

[Audioplayer Preparetoplay];

Play

[Audioplayer play];

Time out

[Audioplayer pause];

Stop it

[Audioplayer stop];

    • Step Five: Proxy method

Protocol: Avaudioplayerdelegate

The proxy method that will be called when playback finishes

-(void) audioplayerdidfinishplaying: (Avaudioplayer *) player successfully: (BOOL) flag;

Playback decoding failed

-(void) Audioplayerdecodeerrordidoccur: (Avaudioplayer *) Player ERROR: (NSERROR *) error;

Step One:

2. Video

iOS Learning 45 Multimedia operations

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.