FreeStreamer

https://github.com/muhku/FreeStreamer

Introduction

FreeStreamer is an audio player engine for iOS and OS X, designed for playing audio streams. The engine has a minimal UI for demonstration. Respectfully, see the FreeStreamerDesktop directory for OS X, and,FreeStreamerMobile for the iOS UI.

FreeStreamer 是一个为 iOS 和 OS X 编写的音频播放引擎,用来播放音频流的。这个引擎有一个极简单的 UI 用来示范。你直接查看为 OS X 编写的 FreeStreamerDesktop ,以及为 iOS 编写的 FreeStreamerMobile 。

The engine is written in C++ and the FSAudioController Objective-C class wraps the implementation.

这是用 C++ 写的引擎,用 FSAudioController 类来封装了实现。

FreeStreamer has the following features:

FreeStreamer 有着如下的一些特性:

  • Fast and low memory footprint (no overhead of Objective-C method calls)
  • Supports ShoutCast and IceCast audio streams + standard HTTP
  • Can detect the stream type based on the content type
  • Supports ShoutCast metadata
  • Supports interruptions (for example a phone call during playing the stream)
  • Supports backgrounding
  • Supports a subset of the ID3v2 tag specification
  • Supports Podcast RSS feeds
  • The stream contents can be stored in a file (see the OS X application for an example)
  • It is possible to access the PCM audio samples (useful if you want your own audio analyzer, for instance)
  • Includes a frequency analyzer and visualization, see Additions and the iOS application
  • 快速低耗的打印信息(不是 OC 上层方法的调用)
  • 支持 ShoutCast 和 IceCast 音频流 + 标准 HTTP
  • 能检测流类型,基于包的内容
  • 支持 ShoutCast 元数据
  • 支持中断(例如,播放音频流的时候打进来了一个电话)
  • 支持后台
  • 支持 ID3v2 标签子集说明
  • 支持广播 RSS feed
  • 流内容可以保存到文件中(看看 OS X 应用的例子)
  • 他可以处理 PCM 音频
  • 包含一个频率分析器并可视化,可以参考 Additions 的例子

API documentation

See here.

Using the player in your own project

Please follow the following steps to use the player in your own project:

请按照以下的步骤来把它添加到你的工程当中:

  1. Make sure you have the following frameworks linked to your project:(包含如下的框架)

    • CFNetwork.framework
    • AudioToolbox.framework
    • AVFoundation.framework
    • libxml2.dylib (add $(SDKROOT)/usr/include/libxml2 to the header search path, if not found)
    • MediaPlayer.framework (iOS only)
  2. Add the Common and astreamer directories to your project. Try building the project now and it should compile successfully.(把文件夹 Common 和 astreamer)添加到你的工程当中,试着编译一下看会不会出错。

  3. iOS only: If you want to support background audio, add App plays audio to the target's Required background modes. You can find the property by clicking on the target on Xcode and opening the Info tab.仅支持 iOS :如果你想支持后台音乐,你可以在 Xcode 的 info tab 中找到相关信息。

You can now stream an audio file like this. Declare the stream in your header file:

你可以这么使用,在你的头文件中声明一下:

@class FSAudioStream;

@interface MyClass : NSObject {
FSAudioStream *_audioStream;
}

Initialize and use the stream in your implementation:

在你的实现文件中初始化:

#import "FSAudioStream.h"

_audioStream = [[FSAudioStream alloc] init];
[_audioStream playFromURL:[NSURL URLWithString:@"http://www.example.com/audio_file.mp3"]];

Note that FSAudioStream must exist during the playback of the stream. Do not declare the class as a local variable of a method or the stream will be deallocated and will not play.

注意,FSAudioStream 必须在播放音频的期间一直存在。不要把它定义成一个实例变量,一个 alloc init 只能播放一个流媒体。

Some servers may send an incorrect MIME type. In this case, FreeStreamer may not be able to play the stream. If you want to avoid the content-type checks (that the stream actually is an audio file), you can set the following property:

许多服务器也许会给你发送错误的 MIME 类型。这种情况下,FreeStreamer 也许就不能播放这个音频了。如果你想避免 content-type 检查(但是这个 steam 依然是音频文件),你可以设置如下的属性:

audioStream.strictContentTypeChecking = NO;
// Optionally, set the content-type where to fallback to
audioStream.defaultContentType = "audio/mpeg";

For streaming playlists, you need to use the FSAudioController.h class. The class has some additional logic to resolve the playback URLs. Again, declare the class:

为了设置播放列表,你可以使用 FSAudioController.h 类。这个类有着一些额外的逻辑来解决回放问题,声明使用与上面的类似:

@class FSAudioController;

@interface MyClass : NSObject {
FSAudioController *_audioController;
}

And use it:

这么使用:

#import "FSAudioStream.h"

_audioController = [[FSAudioController alloc] init];
_audioController.url = @"http://www.example.com/my_playlist.pls";
[_audioController play];

It is also possible to check the exact content of the stream by using the FSCheckContentTypeRequest.h andFSParsePlaylistRequest.h classes:

你也可以精确的检查包的内容,使用  FSCheckContentTypeRequest.h 和 FSParsePlaylistRequest.h 这两个类:

FSCheckContentTypeRequest *request = [[FSCheckContentTypeRequest alloc] init];
request.url = @"http://www.example.com/not-sure-about-the-type-of-this-file";
request.onCompletion = ^() {
if (self.request.playlist) {
// The URL is a playlist; now do something with it...
}
};
request.onFailure = ^() {
}; [request start];

That's it! For more examples, please take a look at the example project. For instance, you may want to observe notifications on the audio stream state.

就这些了!更多例子,请参考示例工程。例如,你也许需要监测视频流的状态。

FAQ

See here.

Debugging

To enable debug logging, enable the following line in astreamer/audio_stream.cpp:

#define AS_DEBUG 1

After enabling the line, compile the code and run it.

It is also possible to check the lastError property in the FSAudioStream class:

NSLog(@"Last error code: %i", audioStream.lastError);

Or if you are using the FSAudioController class, then:

NSLog(@"Last error code: %i", audioController.stream.lastError);

Reporting bugs and contributing

For code contributions, please create a pull request in Github.

For bugs, please create a Github issue. I don't have time for private email support, so usually the best way to get help is to interact in Github.

最新文章

  1. [项目]WebService涉及到的部分核心代码
  2. [转]EL表达式和JSTL表达式实例
  3. NVelocity用法(转)
  4. linux下的gcc编译器
  5. linux琐碎知识点
  6. 求1+2+……+n(位运算)
  7. 旅行家的预算 1999年NOIP全国联赛普及组NOIP全国联赛提高组
  8. SQLServer DMV Query
  9. 利用DescriptionAttribute实现枚举字符串
  10. URAL 2070 Interesting Numbers (找规律)
  11. SkinSharp用法
  12. WCF与Web API 区别(应用场景)
  13. boost------asio库的使用1(Boost程序库完全开发指南)读书笔记
  14. UITextFiled自动补全输入,选中补全内容。NSRange和UITextRange的相互转换。-b
  15. ios显示手机信息
  16. [转]java构造方法的访问修饰符
  17. C 打印格式小记
  18. 消息 4900,级别 16,状态 2,第 1 行 对表 'XX.XXX' 执行 ALTER TABLE SWITCH 语句失败。对于已启用更改跟踪的表,不可能切换其分区。请先禁用更改跟踪,再使用 ALTER TABLE SWITCH。
  19. SQLServer之创建DML AFTER INSERT触发器
  20. RESTful学习笔记

热门文章

  1. Kafka集成SparkStreaming
  2. centos6.5/6.3升级安装ImageMagick7.0.1-1
  3. 解决ASP.NET MVC(post数据)Json请求太大,无法反序列化(The JSON request was too large to be deserialized)
  4. spring boot之使用通用Mapper批量添加数据
  5. Pig的安装和简单使用
  6. (转)python随机数用法
  7. Ionic入门六:按钮
  8. C#连接操作MySQL数据库详细步骤 帮助类等(二次改进版)
  9. 图形文件元数据管理工具exiv2
  10. 微信小程序 --01