[翻译] 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.

 

目录
相关文章
|
4月前
|
Web App开发 Windows
FFmpeg开发笔记(十五)详解MediaMTX的推拉流
MediaMTX是开源轻量级流媒体服务器,提供RTSP, RTMP, HLS, WebRTC和SRT服务。启动后,它在不同端口监听。通过FFmpeg的推拉流测试,证明了MediaMTX成功实现HLS流媒体转发,但HLS播放兼容性问题可能因缺少音频流导致。推流地址为rtsp://127.0.0.1:8554/stream,RTMP地址为rtmp://127.0.0.1:1935/stream,HLS播放地址为http://127.0.0.1:8888/stream(Chrome)和http://127.0.0.1:8888/stream/index.m3u8(其他播放器可能不支持)。
491 2
FFmpeg开发笔记(十五)详解MediaMTX的推拉流
|
4月前
|
编解码 API 开发工具
FFmpeg获取音视频流信息
FFmpeg获取音视频流信息
87 1
FFmpeg获取音视频流信息
|
编解码 缓存 Linux
对话音视频牛哥:如何设计功能齐全的跨平台低延迟RTMP播放器
对话音视频牛哥:如何设计功能齐全的跨平台低延迟RTMP播放器
144 0
|
文字识别 自然语言处理 Ubuntu
跨平台工具集JamTools:支持截屏、录屏、文字识别、翻译、传输等
一个跨平台的小工具集类软件,支持Windows7/8/10/11、Macos、ubuntu系统(其他系统可以直接从源码编译打包)。包含了(滚动/区域)截屏、录屏、文字识别、多种语言互译、多媒体格式转换、鼠标键盘动作录制播放、局域网文件传输、聊天机器人等功能
2845 0
|
存储 编解码 数据可视化
漏刻有时数据可视化语音留言墙开发日志(微信录音&七牛云amr转换成mp3存储转码)
漏刻有时数据可视化语音留言墙开发日志(微信录音&七牛云amr转换成mp3存储转码)
74 0
|
Web App开发 监控 前端开发
如果监控摄像头不支持Web Socket,猿大师播放器还能在网页中播放RTSP流吗?
猿大师播放器在前端用web socket是浏览器和中间件及播放程序之间的通讯协议,和实际播放无关,只要浏览器支持web socket就可以播放,现在大部分浏览器都支持web socket,所以就算监控设备不支持Websocket,用猿大师播放器播放RTSP也是是没问题的。
207 0
如果监控摄像头不支持Web Socket,猿大师播放器还能在网页中播放RTSP流吗?
|
自然语言处理 人机交互 语音技术
阿里云智能语音交互中录音文件识别服务的简单使用
智能语音交互产品基于语音识别、语音合成、自然语言理解等技术,实现“能听、会说、懂你”式的智能人机交互体验,适用于智能客服、质检、会议纪要、实时字幕等多个企业应用场景,识别是针对已经录制完成的录音文件,进行离线识别的服务。录音文件识别是非实时的,识别的文件需要提交基于HTTP可访问的URL地址,不支持提交本地文件。此篇文章简单介绍下javasdk的调用
912 0
阿里云智能语音交互中录音文件识别服务的简单使用
|
算法
【音频处理】Melodyne 导入音频 ( 使用 Adobe Audition 录制音频 | 在 Melodyne 中打开录制的音频 | Melodyne 对音频素材的操作 | 音频分析算法 )
【音频处理】Melodyne 导入音频 ( 使用 Adobe Audition 录制音频 | 在 Melodyne 中打开录制的音频 | Melodyne 对音频素材的操作 | 音频分析算法 )
853 0
【音频处理】Melodyne 导入音频 ( 使用 Adobe Audition 录制音频 | 在 Melodyne 中打开录制的音频 | Melodyne 对音频素材的操作 | 音频分析算法 )
|
编译器
QT软件开发: 获取媒体详细信息(视频/音频)
QT软件开发: 获取媒体详细信息(视频/音频)
313 0
QT软件开发: 获取媒体详细信息(视频/音频)
QT应用编程: 调用系统语音引擎完成文字转语音播报
QT应用编程: 调用系统语音引擎完成文字转语音播报
517 0