用Ruby操作音频文件

用Ruby操作音频文件,ruby,ruby-on-rails-3,html,ruby-1.9.3,Ruby,Ruby On Rails 3,Html,Ruby 1.9.3,在内部服务器上传输mp3和ogg文件并进行身份验证。 试图将文件流式传输到HTML5播放器,但Chrome Seek功能出现问题 设置好所有标题,但如何打开二进制文件,查找位置并只从该点发送数据到末尾 i.e. Given an mp3 file that is 119132474 long, And A request comes in asking for the new start point of the file be at 21012274 How can I s

在内部服务器上传输mp3和ogg文件并进行身份验证。 试图将文件流式传输到HTML5播放器,但Chrome Seek功能出现问题

设置好所有标题,但如何打开二进制文件,查找位置并只从该点发送数据到末尾

i.e. Given an mp3 file that is 119132474 long,
     And A request comes in asking for the new start point of the file be at 21012274
     How can I send a new binary file with only information from 21012274 to 119132474
这里有一些类似于我想做的事情,但是在Node.js中

-------更新日期:2014年2月15日--------


我安装了Redis,并将Redis用作二进制数据的临时缓存服务器。然后使用Redis的GETRANGE。请参见

您可以以二进制模式打开文件,并使用
IO
模块中的方法读取字节。例如:

file_size = File.size('filename')
File.open('filename', 'rb') do |file| # read in binary mode
  file.seek(position)
  file.read(file_size - position) # return all bytes until the end
end
还有一个应该可以工作,但我没有测试流媒体。该方法为“binread”,比第一种方法简单:

File.binread('filename', start_pos, offset)

它应该有用

对于其他人,从读取创建tmp文件,写入tmp文件,向请求发送tmp文件,并确保删除tmp文件。当然,有更好的方法可以做到这一点,这样您就不需要创建tmp文件。