简体   繁体   English

浏览器如何加载 flash 文件? (瑞士法郎)

[英]How does a browser load a flash file? (swf)

How does the browser load flash files?浏览器如何加载 flash 文件? Do they load progressively, or does the browser wait until the entire flash file is loaded before displaying it?它们是逐步加载,还是浏览器等到整个 flash 文件加载完毕后再显示?

The reason is I have a tiny clip that is extremely high in quality, only a few seconds long, but it's over 4 mb.原因是我有一个质量非常高的小剪辑,只有几秒钟长,但超过 4 mb。

Will the user have to wait until all 4 mb is loaded before viewing?用户是否必须等到所有 4 mb 都加载完毕才能查看? Or does it load as the user watches it?还是在用户观看时加载?

I didn't do anything fancy, I just imported a.flv into Flash, and exported as a.swf.我没有做任何花哨的事情,我只是将a.flv导入Flash,并导出为a.swf。

Thank you in advanced谢谢先进

There are many parts to loading a flash file, and more generically, an HTML page.加载 flash 文件有很多部分,更一般地说,加载 HTML 页面。

I'm going to start from the top with the HTML page, and I urge others to correct any mistakes I may have made.我将从 HTML 页面从头开始,并敦促其他人纠正我可能犯的任何错误。

Loading a Page加载页面

When an HTML page is received, the browser parses it into the Document Object Model (DOM) so that it has a programmatic representation of every element.当收到 HTML 页面时,浏览器会将其解析为 Document Object Model (DOM),以便它具有每个元素的编程表示。 Browsers iterate over every node in the DOM tree and populate it as-needed.浏览器遍历 DOM 树中的每个节点并根据需要填充它。

For most nodes this is simply creating a new DOM element like a div , p , or a ;对于大多数节点,这只是创建一个新的 DOM 元素,例如divpa however some content requires loading or replacement.但是有些内容需要加载或替换。

form elements ( input , select , button , textarea ) are replaced with the browser-specific representation of those form fields.表单元素( inputselectbuttontextarea )被替换为这些表单字段的特定于浏览器的表示。

link elements used as stylesheets are asynchronously loaded.用作样式表的link元素是异步加载的。 The DOM continues to parse the page as the external resource is being loaded.在加载外部资源时,DOM 会继续解析页面。

script elements on the other hand, are synchronously loaded.另一方面, script元素是同步加载的。 The DOM is unable to continue parsing the tree until the script has finished loading and executing, with exceptions for if the loading failed or the execution had an error.在脚本完成加载和执行之前,DOM 无法继续解析树,除非加载失败或执行出错。

img elements are asynchronously loaded, but allow for the onload callback to determine when they have finished loading. img元素是异步加载的,但允许onload回调确定它们何时完成加载。 The DOM can't trigger the window's onload event until all img elements have finished loading (or failed).在所有img元素都完成加载(或失败)之前,DOM 无法触发窗口的onload事件。

Understanding the basic elements helps with understanding more involved elements like object , embed , and iframe , which are also replaced content.了解基本元素有助于理解更多涉及的元素,例如objectembediframe ,它们也被替换为内容。

Flash is typically embedded on a webpage using object , embed and iframe . Flash 通常使用objectembediframe嵌入到网页中。

As far as I'm aware, object and embed elements react similarly so I will shortcut and say object from here on out.据我所知, objectembed元素的反应类似,所以我会说object从这里开始。

There are distinct differences between loading flash in iframe and object elements.iframeobject元素中加载 flash 之间存在明显差异。

The object element is very similar to a script element where the content must be successfully loaded and executed before the DOM can continue to be parsed. object元素非常类似于script元素,其中必须成功加载并执行内容才能继续解析 DOM。

The iframe element is very similar to an img element where the contents are loaded asynchronously, but a callback may be used to determine when the loading has finished (although I'm not sure about whether the callback is available for cross-domain requests) . iframe元素与异步加载内容的img元素非常相似,但可以使用回调来确定加载何时完成(尽管我不确定回调是否可用于跨域请求)

Loading Flash加载 Flash

The previous section discusses just the HTML side of content loading.上一节讨论了内容加载的 HTML 方面。 However, there are a number of nuances within flash that can severely affect the load time of a flash movie.但是,flash 中有许多细微差别会严重影响 flash 影片的加载时间。

As I stated before, script elements must be fully loaded and executed before the DOM can continue being parsed.正如我之前所说, script元素必须完全加载执行,然后才能继续解析 DOM。 A similar effect is found within Flash files (even when included via an iframe ).在 Flash 文件中发现了类似的效果(即使通过iframe包含在内)。 All resources embedded within the swf must be loaded before the swf can release its hold on the page loading progress.嵌入在swf中的所有资源必须先加载,然后swf才能释放对页面加载进度的保留。

If you've embedded a video directly into the timeline, the entire video must load before flash can be considered done with its initial execution.如果您已将视频直接嵌入到时间线中,则必须先加载整个视频,然后 flash 才能被视为已完成初始执行。

If, instead, you chose to use an asynchronous callback to start loading an external resource that happened to be a video, and used an asynchronous loader to load the video, you wouldn't have to wait for the video to be finished loading before the rest of the page could be loaded;相反,如果您选择使用异步回调来开始加载恰好是视频的外部资源,并使用异步加载器来加载视频,则您不必等待视频完成加载可以加载页面的rest; within flash, you'd still need to wait for the video to finish loading before beginning playback of the video.在 flash 中,您仍然需要等待视频完成加载,然后才能开始播放视频。

Alternatively, there are a number of means within flash to either stream videos, or progressively load a video from a server, which would enable the video to be played without being finished loading.或者,在 flash 到 stream 视频或从服务器渐进式加载视频时,有多种方法可以使视频在未完成加载的情况下播放。 My experience with that particular aspect of flash is minimal, so I won't explain how it's done .我对 flash 的特定方面的经验很少,所以我不会解释它是如何完成的

Using a library like swfobject allows the desired swf to be loaded asynchronously so that flash loading is non-blocking.使用类似swfobject之类的库可以异步加载所需的swf ,以便 flash 加载是非阻塞的。

tl; tl; dr:博士:

Flash files may be loaded progressively depending on how you've structured your HTML, and what code is running in the swf . Flash 文件可能会逐渐加载,具体取决于您构建 HTML 的方式以及swf中运行的代码。

You may want to look into swfobject你可能想看看swfobject

swf files are loaded progressively (hence loader bars, "50% loaded" messages and such). swf 文件是逐步加载的(因此加载器条、“50% 加载”消息等)。

Historically, Flash files are based on frames, and if the main timeline has multiple frames, they will be loaded and displayed in sequence, as soon as they are loaded, before the entire file is loaded.从历史上看,Flash 文件是基于帧的,如果主时间轴有多个帧,它们会在加载完成后依次加载和显示,然后再加载整个文件。 However, most Flash content nowadays is not constructed that way, and are more complex than a series of frames that are displayed in sequence.但是,现在大多数 Flash 内容都不是这样构建的,并且比按顺序显示的一系列帧更复杂。 Video playback also adds complexity beyond the basic frame model, with video codecs, audio synch and such.视频播放还增加了基本帧 model 之外的复杂性,包括视频编解码器、音频同步等。

So the answer to the question " Do they load progressively, or does the browser wait until the entire flash file is loaded before displaying it? " is that they load progressively and are displayed before the entire swf files is loaded.那么“它们是渐进式加载,还是浏览器等到整个 flash 文件加载完毕后再显示? ”的答案是它们渐进式加载并在加载整个 swf 文件之前显示。 But how this will effect how the users experience your video is hard to tell without seeing it or how it is constructed.但这将如何影响用户体验您的视频,如果没有看到它或它是如何构建的,就很难说清楚。

It will load the entire movie first.它将首先加载整个电影。 So make your video an external file that the movie loads when it runs.因此,让您的视频成为电影在运行时加载的外部文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM