构建用于从GridFS mongodb流式传输音频/视频的API [英] build an API for streaming audio/video from GridFS mongodb

查看:209
本文介绍了构建用于从GridFS mongodb流式传输音频/视频的API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了链接流音频中给出的解决方案浏览器上来自gridFS的/video文件

当我使用我的代码时,仍然会下载文件或使用默认的浏览器播放器播放文件. 我的代码是:

Still when I use my code the file gets downloaded or it plays with the default browser player. My code is as:

header('Content-type: audio/mpeg;');

$stream = $file->getResource();
while (!feof($stream)) {
      echo fread($stream, 8192);
      }

我实际上想要一个构建API的解决方案,以便我可以从mongodb GridFS检索音频/视频并从电话应用程序中播放流.

I actually want a solution to build an API so that I can retrieve the audio/video from mongodb GridFS and play it streaming from a phone application.

迫切需要帮助.欢迎对该主题提供任何帮助.

Help is urgently needed. Any help on the topic would be welcome.

推荐答案

我找到了一种方法,可以使HTML音频视频图像小部件中直接从mongoDB GridFS播放文件的API成为可能.唯一的问题是它将从mongoDB检索的数据用作base64数据.现在,在此链接中讨论了我正在谈论的问题:

I found a way to make an API for playing the file straight from the mongoDB GridFS in a HTML audio video image widget. The only problem with it is that it uses the data retrieved from mongoDB as a base64 data. Now the problem that i am talking about is discussed in this link:

http://davidbcalhoun.com/2011/何时对base64编码图像和何时不对.

我希望您在决定使用我正在使用的解决方案之前发现它有用.我的解决方法如下:

I hope you find that useful before deciding to use the solution I am using. My solution is as follows:

$stream = $file->getResource();
$stringcoded = stream_get_contents($stream); //converts the stream to string data
$encoded = base64_encode($stringcoded);  //encodes string data to base64

现在,您已将音频,视频或图像数据编码为base64,只需在html5小部件的"src"部分中回显数据即可.

Now that you have the audio, video or image data encoded in base64, you just have to echo the data in the 'src' portion of the html5 widget.

我从一个非常有用的博客获得了此解决方案.如果您需要更多帮助,请按照以下步骤操作:

I got this solution from a very useful blog. If you need more help on it please go through it:

http://www.iandevlin. com/blog/2012/09/html5/html5-media-and-data-uri

任何对此问题的增强解决方案都非常受欢迎.

Any enhanced solution to this problem is more than welcome.

这篇关于构建用于从GridFS mongodb流式传输音频/视频的API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆