AVAudioPlayer Streaming Support
Q:
Does the AVAudioPlayer
provide support for streaming audio content?
A: The AVAudioPlayer
class does not provide support for streaming audio based on HTTP URL's. The URL used with initWithContentsOfURL:
must be a File URL (file://
). That is, a local path.
As mentioned in Core Audio Essentials, the AVAudioPlayer
class is ideal for applications that require a simple Objective-C interface for audio playback, are not concerned about audio positioning or precise synchronization, and are not playing audio from a network stream.
To play streamed audio, connect to a network stream using the CFNetwork
interfaces from Core Foundation, such as those in CFHTTPMessage
. Parse the network packets into audio packets using Audio File Stream Services (AudioToolbox/AudioFileStream.h
) and play the audio packets using Audio Queue Services (AudioToolbox/AudioQueue.h
). You may also use Audio File Stream Services to parse audio packets from an on-disk file.
AVPlayer
(available in iOS 4.0 and later) may also be used to stream audio content.
Reference
A sample called AudioFileStreamExample
demonstrates the use of Audio File Stream APIs and can be found in the Mac OS X Reference Library.
SpeakHere - Demonstrates Audio Queue Services.
Document Revision History
Date | Notes |
---|---|
2013-04-04 | Editorial |
2011-06-28 | Editorial |
2009-09-16 | Editorial |
2009-01-29 | New document that Discusses AVAudioPlayer and support for streaming audio. |
Copyright © 2013 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2013-04-04