Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You might want to use the AVAudioPlayer instead of AudioServices.</p> <p>The following code will take an audio file (.m4a) and play the audio file 1 time. Don't forget to release "audioPlayer" when you're done with it.</p> <pre><code>NSString *urlAddress = [[NSBundle mainBundle] pathForResource:@"filename" ofType:@"m4a"]; NSURL *url = [NSURL fileURLWithPath:urlAddress]; NSError *error; AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&amp;error]; audioPlayer.numberOfLoops = 0; if (audioPlayer == nil) { NSLog([error description]); } else { [audioPlayer play]; } </code></pre> <p>Hope this example helps you with playing audio on the actual device. It might also be a good idea to increase the device audio when the file is playing.</p> <p>Note: You will need to add the AVFoundation framework to your project if you have not already done so. As well as import the header file.</p> <p><code>#import &lt;AVFoundation/AVFoundation.h&gt;</code> </p> <p><strong>Update:</strong></p> <p>From Apple's Core Audio Overview <a href="http://developer.apple.com/iphone/library/documentation/MusicAudio/Conceptual/CoreAudioOverview/WhatsinCoreAudio/WhatsinCoreAudio.html" rel="nofollow noreferrer">Document</a></p> <p><strong>Audio Session Services</strong></p> <p>Audio Session Services lets you manage audio sessions in your application—coordinating the audio behavior in your application with background applications on an iPhone or iPod touch. Audio Session Services consists of a subset of the functions, data types, and constants declared in the AudioServices.h header file in AudioToolbox.framework.</p> <p><strong>The AVAudioPlayer Class</strong></p> <p>The AVAudioPlayer class provides a simple Objective-C interface for playing sounds. If your application does not require stereo positioning or precise synchronization, and if you are not playing audio captured from a network stream, Apple recommends that you use this class for playback. This class is declared in the AVAudioPlayer.h header file in AVFoundation.framework.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload