录制来自在线广播的流媒体音频

时间:2022-03-01 19:01:00

I am working on a application where I am playing a live radio from a url. I want to record the radio and save it to local file system.

我正在开发一个应用程序,我正在从网址播放直播电台。我想记录收音机并将其保存到本地文件系统。

1 个解决方案

#1


2  

This might help:

这可能有所帮助:

iPhone Coding: Recording Audio

iPhone编码:录制音频

You need to use CFURLRef to point to the file you want to record to. For example:

您需要使用CFURLRef指向要记录的文件。例如:

NSMutableString *fullpathname = @"/var/root/foo.amr";
CFURLRef url;
CFStringRef sref;

sref = CFStringCreateWithCString(nil, 
[fullpathname cStringUsingEncoding:
[NSString defaultCStringEncoding]],
kCFStringEncodingASCII);

url = CFURLCreateWithFileSystemPath(nil, sref, 
kCFURLPOSIXPathStyle, 0);

Start recording by initializing. Once you get this far, it's just a matter of bookkeeping to get your recorder started. Here's the relevant code. Allocate and initiate the recorder instance, activate it and assign it the CFURLRef URL you've created. Then tell it to start. Recording starts instantly.

通过初始化开始录制。一旦你做到这一点,只需要记账就可以让你的录音机启动。这是相关的代码。分配并启动录像机实例,激活它并为其分配您创建的CFURLRef URL。然后告诉它开始。录音立即开始。

// Start recording
recorder = [[AVRecorder alloc] init];
[recorder activate:self];
[recorder setFilePath:url];
[recorder start];

Stop the recording with "stop". When you're ready to finish recording, just send a stop message to your recorder and deactivate it. The file has already saved automatically to disk. If you want, you can query the number of bytes written before deactivating by sending a recordedFileSizeInBytes message.

用“停止”停止录音。当您准备完成录制时,只需向录制器发送停止信息并停用即可。该文件已自动保存到磁盘。如果需要,可以通过发送recordedFileSizeInBytes消息来查询在停用之前写入的字节数。

[recorder stop];
[recorder deactivate];

#1


2  

This might help:

这可能有所帮助:

iPhone Coding: Recording Audio

iPhone编码:录制音频

You need to use CFURLRef to point to the file you want to record to. For example:

您需要使用CFURLRef指向要记录的文件。例如:

NSMutableString *fullpathname = @"/var/root/foo.amr";
CFURLRef url;
CFStringRef sref;

sref = CFStringCreateWithCString(nil, 
[fullpathname cStringUsingEncoding:
[NSString defaultCStringEncoding]],
kCFStringEncodingASCII);

url = CFURLCreateWithFileSystemPath(nil, sref, 
kCFURLPOSIXPathStyle, 0);

Start recording by initializing. Once you get this far, it's just a matter of bookkeeping to get your recorder started. Here's the relevant code. Allocate and initiate the recorder instance, activate it and assign it the CFURLRef URL you've created. Then tell it to start. Recording starts instantly.

通过初始化开始录制。一旦你做到这一点,只需要记账就可以让你的录音机启动。这是相关的代码。分配并启动录像机实例,激活它并为其分配您创建的CFURLRef URL。然后告诉它开始。录音立即开始。

// Start recording
recorder = [[AVRecorder alloc] init];
[recorder activate:self];
[recorder setFilePath:url];
[recorder start];

Stop the recording with "stop". When you're ready to finish recording, just send a stop message to your recorder and deactivate it. The file has already saved automatically to disk. If you want, you can query the number of bytes written before deactivating by sending a recordedFileSizeInBytes message.

用“停止”停止录音。当您准备完成录制时,只需向录制器发送停止信息并停用即可。该文件已自动保存到磁盘。如果需要,可以通过发送recordedFileSizeInBytes消息来查询在停用之前写入的字节数。

[recorder stop];
[recorder deactivate];