IOS online audio playback FreeStreamer
Preface:AboveIn iOS recording practices, we useAVAudioPlayer to play a local audio file. However, in practical applications, we need to play network audio files,In iOS, how does one play network streaming media? The Audio Queue service in the AudioToolbox framework is used. This article will introduce the third-party excellent open-source framework FreeStreamer
1. FreeStreamer features
FreeStreamer is an audio playback engine for iOS and OS X, designed specifically for playing audio streams. This engine demonstrates that the UI is simple, efficient, and occupies less memory. It is written in C ++.
Function:
High efficiency and low memory usage (Objective-C method calls do not consume extra performance)
Support for ShoutCast and IceCast streaming media and standard HTTP protocol
Detection of streaming media formats
Support for ShoutCast metadata
Pause is supported, for example, pause playing because of a call.
Supports background playback.
Supports ID3v2
Support for Podcast RSS feeds
Content can be stored in files (view OS X app)
Example of PCM audio that can be accessed
Contains a frequency analyzer (you can view Additions and iOS Apps)
2. Usage
1. Use cocoapods to install FreeStreamer.
2 Examples
# Import ViewController. h # import FSAudioStream. h @ interface ViewController () @ property (nonatomic, strong) FSAudioStream * audioStream; @ end @ implementation ViewController-(void) viewDidLoad {[super viewDidLoad]; [self. audioStream play];}/*** obtain the local file path ** @ return file path */-(NSURL *) getFileUrl {NSString * urlStr = [[NSBundle mainBundle] pathForResource: @ ofofoftype: nil]; NSURL * url = [NSURL fileURLWithPath: urlStr]; return url;}-(NSURL *) getNetworkUrl {NSString * urlStr = @ video address;
NSURL * url = [NSURL URLWithString: urlStr]; return url;}/*** create a FSAudioStream object ** @ return FSAudioStream object */-(FSAudioStream *) audioStream {if (! _ AudioStream) {NSURL * url = [self getNetworkUrl]; // create the FSAudioStream object _ audioStream = [[FSAudioStream alloc] initWithUrl: url]; _ audioStream. onFailure = ^ (FSAudioStreamError error, NSString * description) {NSLog (@ error occurred during playback, error message: % @, description) ;}; _ audioStream. onCompletion = ^ () {NSLog (@ playback completed !); }; [_ AudioStream setVolume: 0.5]; // sets the sound} return _ audioStream;} @ end