[翻译] FreeStreamer 在线流媒体播放

简介:

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 的例子

 

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 and FSParsePlaylistRequest.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.

 

目录
相关文章
|
前端开发 HTML5 移动开发
推荐15个在线多媒体(图片、音频、视频)编辑器
  在处理多媒体文件的时候,我们通常都是使用自己电脑上已安装好的桌面应用程序,如果某天我们在使用的公共电脑上没有我们需要的软件,更坏的情况是,这些公共电脑不允许安装软件,这时候就需要在线的编辑器了。最近几年,Web应用程序越来越受到关注,原因在于它的简单、方便和轻巧,只要你有一个连接到互联网的浏览器,就可以马上处理你的图片、音频和视频。
1533 0
|
29天前
|
弹性计算 JSON 自然语言处理
语音交互产品通过WebSocket协议对外提供实时语音流语音转写功能
阿里云智能语音交互产品通过WebSocket协议提供实时语音转写功能,支持长语音。音频流以Binary Frame上传,指令和事件为Text Frame。支持单声道、16 bit采样位数的PCM、WAV等格式,采样率8000Hz/16000Hz。可设置返回中间结果、添加标点、中文数字转阿拉伯数字,并支持多语言识别。服务端通过临时Token鉴权,提供外网和上海ECS内网访问URL。交互流程包括StartTranscription、StopTranscription指令及多种事件反馈。
|
编解码 缓存 Linux
对话音视频牛哥:如何设计功能齐全的跨平台低延迟RTMP播放器
对话音视频牛哥:如何设计功能齐全的跨平台低延迟RTMP播放器
173 0
|
7天前
|
人工智能 JSON 数据管理
做了一个非结构化数据处理助手,可以自由处理网页、处理文本、音视频等等
Supametas.AI 是一款专注于非结构化数据处理的工具,支持从多种来源(API、网页、文件、图像、音频、视频)提取并标准化输出为JSON和Markdown格式。它与LLM RAG无缝集成,提供用户友好界面和数据隐私保障,帮助企业快速将AI想法落地,提升开发效率。适用于AI医疗、法律、营销、SEO、客服等多个领域,助力企业加速项目成功和迭代。 网址:[https://supametas.ai](https://supametas.ai/)
87 7
做了一个非结构化数据处理助手,可以自由处理网页、处理文本、音视频等等
QT应用编程: 调用系统语音引擎完成文字转语音播报
QT应用编程: 调用系统语音引擎完成文字转语音播报
621 0
|
2月前
|
人工智能 搜索推荐 API
Cobalt:开源的流媒体下载工具,支持解析和下载全平台的视频、音频和图片,支持多种视频质量和格式,自动提取视频字幕
cobalt 是一款开源的流媒体下载工具,支持全平台视频、音频和图片下载,提供纯净、简洁无广告的体验
360 9
Cobalt:开源的流媒体下载工具,支持解析和下载全平台的视频、音频和图片,支持多种视频质量和格式,自动提取视频字幕
|
开发工具
推荐15个在线多媒体(图片、音频、视频)编辑器,互联网营销
  在处理多媒体文件的时候,我们通常都是使用自己电脑上已安装好的桌面应用程序,如果某天我们在使用的公共电脑上没有我们需要的软件,更坏的情况是,这些公共电脑不允许安装软件,这时候就需要在线的编辑器了。最近几年,Web应用程序越来越受到关注,原因在于它的简单、方便和轻巧,只要你有一个连接到互联网的浏览器,就可以马上处理你的图片、音频和视频。
2770 0
|
图形学
Unity游戏语音(富文本消息)解决方案GVoice
腾迅云-GVoice https://www.qcloud.com/document/product/556/7673   集成1-2天内可搞定,博主亲测 Unity5.4.4f1     今天又试了下语音转文字,SpeechToText在使用这个要注意SetMode要改为Translate, //m_voiceengine.
直播源码技术文字聊天功能的配置
我们要开发直播源码平台,直播源码技术文字聊天功能就务必要有,为什么会这么说那?直播源码技术文字聊天功能又该如何去实现那?接下里就进入到我们今天的知识分享:直播源码技术文字聊天功能的配置。
直播源码技术文字聊天功能的配置
|
9月前
|
存储 编解码 算法
在线音频转换工具 - 免费
云库工具是一款强大的音频格式转换器,支持AAC、AC3、MP3、FLAC等多种格式,具备快速高效、简便易用、高质量输出和批量转换的技术优势。适用于多设备兼容、存储优化和专业音频处理场景。无论新手或专业人士,都能轻松满足音频格式转换需求。尝试云库工具,体验高效便捷的转换服务。
443 0
在线音频转换工具 - 免费

热门文章

最新文章