使用TCP套接字通过代理本地视频 [英] Proxying Videos locally with a TCP Socket

查看:110
本文介绍了使用TCP套接字通过代理本地视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在增加对视频播客媒体浏览器的支持真的很感兴趣。

I've been really interested in adding support for video podcasts to Media Browser.

我想用户能够通过提供视频播客浏览,并从互联网络串流。这真的很容易引起媒体播放器等会高高兴兴地玩,生活在云中的文件。

I would like users to be able to navigate through the available video podcasts and stream them from the internets. That's really easy cause media player etc.. will happily play a file that lives in the cloud.

的问题是,我想在本地缓存这些文件相同的情节,所以后续的看房将不涉及流媒体,而是将播放本地文件。

The problem is that I want cache these files locally so subsequent viewings of the same episode will not involve streaming and instead will play the local file.

所以...我就在想,为什么不举办的HttpListener 和媒体播放器要求它的文件位,有的HttpListener 下载并存储在本地。下次用户播放该文件,我们将已经拥有的文件的部分本地。

So... I was thinking, why not host an HttpListener and as media player asks it for bits of the file, have the HttpListener download and store it locally. Next time a user plays the file we will already have portions of the file locally.

有谁知道使用的HttpListener 为代理的示例代码?

Does anyone know of example code that uses HttpListener for proxying?

修改

这个想法是只像MP3代理简单的流媒体内容或MOV。
赏金将进入实际实施

The idea would be only to proxy simple streamable content like MP3 or Mov. The bounty will go to an actual implementation.

下面是我想的API:

// will proxy a uri on the local port, if cacheFile exists it will resume the 
// download from cacheFile.
// while the file is downloading it will be name cacheFile.partial, after the 
// download is complete the file will be renamed to cacheFile.
// Example usage: ProxyFile("http://media.railscasts.com/videos/176_searchlogic.mov", 8000, @"c:\downloads\railscasts\176_searchlogic.mov")
//
// Directly after this call http://localhost:8000 will be the proxy stream, it will be playable locally. 
void ProxyUri(Uri uri, int port, string cacheFile) 

修改2

的HttpListener 正在寻找漂亮没出息的我可能需要做的工作在TCP套接字级别为的HttpListener 取值似乎需要程序运行作为将是真正棘手管理员。

HttpListener is looking pretty unpromising I will probably need to do the work at a TCP socket level as HttpListeners seem to require the program runs as admin which is going to be really tricky.

推荐答案

我没做过与的HttpListener 任何东西之前,我认为这将是一个可爱的小运动来让自己与它的速度 - 所以它证明。我实现了它作为一个单一的 ProxyListener 类,它的构造函数指定的 ProxyUri 函数的参数。一旦你获得一个实例,启动它侦听(和潜在下载),通过调用它的开始方法。当你用它做,叫清除

I hadn't done anything with HttpListener before, so I thought this would be a nice little exercise to bring myself up to speed with it - and so it proved. I implemented it as a single ProxyListener class whose constructor takes the parameters of the ProxyUri function you specified. Once you obtain an instance, you start it listening (and potentially downloading) by calling its Start method. When you're done with it, call Cleanup.

有一个或两个粗糙的边缘,但基本上它的工作原理根据你的问题。为了测试它,我把它建立与一个程序类,它接受输入线组成(URI,端口,文件名)的控制台应用程序,空格分隔,创建 ProxyListener 实例,并启动它们。您可以运行此控制台应用程序,请在合适的线,并下载器会启动(打印出进步控制台)。同时你可以如火了IE浏览器,并且可以从指定的端口的文件,然后你就可以下载它,而下载仍正常工作。在上传进步将被打印到控制台了。

There are one or two rough edges but basically it works as per your question. To test it, I built it up as a console application with a Program class which accepts input lines consisting of (uri, port, filename), space-separated, creates the ProxyListener instances and starts them. You can run this console application, type in a suitable line, and the downloader will start (printing out progress to console). Simultaneously you can e.g. fire up IE and fetch the file from the specified port, and you will be able to download it while the downloader is still working. The "uploader" progress will be printed to console, too.

我有一个有点麻烦,将其粘贴在这里,可能是由于大小(它不是那么大但更大的比你的片段通常在这里看到的 - 在 ProxyListener 类是在200线一点点)。听起来是不是有意思吗?如果是这样,我会把它张贴到引擎收录和更新这个答案的链接

I'm having a bit of trouble pasting it in here, maybe due to size (it's not that big, but bigger than the snippets you normally see here - the ProxyListener class is a tad under 200 lines). Does it sound interesting? If so, I'll post it to a pastebin and update this answer with a link.

更新:发布为的要点

请注意,您将需要管理员权限才能运行程序,因为的HttpListener 要求这

Note that you will need Administrator privileges to run the program, since HttpListener requires this.

更新2:在某些情况下,它是不是需要有管理员权限才能运行的HttpListener 。请参见此链接和的这个。我们的想法是,如果你能在安装时保留一个URL命名空间,那么用户不必拥有管理员权限,如果听反对的命名空间。

Update 2: Under certain circumstances, it is not necessary to have admin privileges to run HttpListener. See this link and this one. The idea is, if you can reserve an URL namespace during installation time, then the user does not have to have admin privileges if listening against that namespace.

这篇关于使用TCP套接字通过代理本地视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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