Flash内容下载
我一直想知道一些事情,像 youtube(pandora 做 mp4)这样的网站
- 通过 Flash 播放器播放音乐
- 在播放每首曲目时
,它们被下载到用户的计算机上,例如 /tmp/FlashXX*****这允许用户可以将 flv 移出该文件夹以便稍后播放。
但是,当用户将 flv 移出 /tmp 文件夹时,播放器会继续相当愉快地播放音乐/视频。 Flash 播放器如何处理文件的删除以及为什么它不会因此抛出错误?
更重要的是,如果玩家在没有 flv 的情况下也能玩得很开心,为什么首先要下载这些 flv 给用户呢?
I've been wondering something, websites like youtube (pandora does mp4s)
- play their music through a flash player
- while each track is played, they're downloaded to the user's computer, e.g., /tmp/FlashXX*****
This allows users to go and move the flv out of that folder for later playback.
However, when the user moves the flv out of the /tmp folder, the player continues to play the music/video quite happily. How does the flash player handle the removal of its file and why doesn't it throw errors from this?
More importantly, why are the flvs downloaded to the user in the first place if the player plays happily without them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这实际上与缓存无关。相反,它的工作原理取决于 Unix 文件系统的工作方式。打开文件时,会读取其索引节点并指示数据在磁盘上的位置。当文件被移动或删除(“取消链接”)时,inode 会被移动到新位置或从目录中删除。但是,直到不存在对该 inode 的引用之前,它指向的数据才会失效。换句话说,只要文件保持打开状态,删除或移动它就不会影响读取该文件的程序。
这不是 Windows 文件系统的工作方式,这会导致在尝试删除正在使用的文件时出现常见的“文件被锁定”问题。 (免责声明:对于支持硬链接的 NTFS 来说可能不是这样,但我很确定 FAT 上也是如此。)
它工作得非常好,有时程序甚至会使用一种技巧,通过创建文件来自动清理自身 。一个文件并立即“删除”它,同时保持其打开状态。这样,临时文件可以继续使用,直到程序使用完毕为止,此时它会自动“消失”。
顺便说一句,如果您移动临时文件,那些希望能够关闭和重新打开临时文件的程序将会感到困惑。您可以通过使用硬链接进行“复制”来避免这种情况。
此命令将在当前目录中创建 Flash 为临时文件引用的 inode 的副本。它实际上并不复制文件的内容,只是创建对磁盘上相同数据的第二个引用。这样,当 Flash 关闭时,您仍然有一个指向它释放的数据的“指针”。
我有一段时间没有研究这个主题了,我可能弄错了一些术语,所以我建议如果你想进一步了解,请阅读 inode 以及如何硬链接有效。
从维基百科链接:
This actually has nothing to do with caching. Rather, it works due to the way Unix filesystems work. When a file is opened, its inode is read and indicates where the data is located on the disk. When a file is moved or deleted ("unlinked"), the inode is moved to a new location or removed from the directory. However, the data it points to is not invalidated until no reference to that inode exists. In other words, as long as a file remains open, deleting or moving it has no effect on a program reading that file.
This is not how Windows filesystems work, and that is was leads to the common "file is locked" problems when trying to delete files that are in use. (Disclaimer: This may not be true with NTFS, which supports hard links, but I'm pretty sure it was the case on FAT.)
It works so well that sometimes programs will even use a trick to automatically clean up after itself by creating a file and "removing" it right away, while keeping it open. That way, the temporary file can continue to be used until the program is done with it, at which time it automatically "disappears".
By the way, programs that expect to be able to close and reopen a temporary file will get confused if you move them. You can avoid this by making a "copy" using a hard link.
This command will create copies of the inode referenced by Flash for the temporary file into the current directory. It doesn't actually copy the content of the file, only creates a second reference to the same data on disk. That way when Flash closes, you still have a "pointer" to the data that it released.
I haven't studied this topic in some time and I might have gotten some terminology wrong, so I suggest if you want to understand further, read up on inodes and how hard links work.
From that Wikipedia link:
即使从临时文件夹中删除文件后,内容也会继续播放,因为 Flash 已将文件读入内存以便显示。从概念上讲,这与为什么如果将本地存储的图像拖到浏览器中,然后删除该文件,浏览器不会停止显示该图像的原因相同。
至于为什么存储该文件,它只是被缓存,就像浏览器显示的任何其他文件一样,因此,如果您重新加载页面,您将(不一定)必须重新加载媒体文件。
不过,对于视频来说,所有这些可能都有一些警告 - 例如,如果您在视频中向前或向后搜索,我不能发誓如果缓存版本已被删除,视频是否会从内存中播放......而且我可以想象,在某些情况下,Flash 不会将整个电影保留在内存中。但作为一般情况的答案,事情应该如此处所述。
The content keeps playing even after you remove the file from the temp folder because Flash has read the file into memory in order to display it. It's conceptually the same reason as why, if you drag a locally-stored image into a browser, the browser doesn't stop displaying the image if you then delete the file.
As for why the file gets stored, it's simply being cached, like any other file your browser displays, so that if you reload the page, you won't (necessarily) have to reload the media file.
For video there may be caveats to all this, though - for example, if you seek forward or backwards in a video I couldn't swear to whether the video will be played from memory if the cached version has been removed... and I would imagine that there are situations where Flash doesn't keep the entire movie in memory. But as a general case answer things should be as described here.
我假设您正在描述 *nix 系统上的行为?
他们可能只是使用类似 这个,或 inotify< /a> 或此 .NET 事件。如果现代版本的 Windows 允许您移动临时 .flv 文件,我会感到惊讶,如果闪存没有因此而失效,那就太疯狂了。
但是,是的,我的猜测是,在您的操作系统上,当文件移动时,Flash 播放器不会受到影响,因为它会收到新路径的句柄,以防需要再次从文件中读取。如果您在播放长视频(例如约一小时)时故意更改权限或损坏或删除 .flv,会发生什么情况?
I assume you're describing behavior on a *nix system?
They might just be watching the file system using something like this, or inotify, or this .NET event. I would be surprised if a modern version of Windows allowed you to move the temporary .flv file, and it would be nuts if flash didn't wig out because of it.
But yeah, my guess is that on your operating system, flash player isn't fazed when the file moves because it receives a handle to the new path in case it needs to read from the file again. What happens if you deliberately change permissions or corrupt or delete the .flv while a long (say, ~ one hour) video is playing?