如何在 Actionscript 3 中播放与 SWF 不在同一目录中的声音?

发布于 2024-07-04 21:08:52 字数 564 浏览 4 评论 0原文

我有一个包含大量外部声音到 SWF 的项目。 我想播放它们,但是每当我尝试将新 URL 加载到声音对象中时,它都会失败,

错误#2068:无效声音

或引发 ioError

错误 #2032 流错误

// 尝试使用前缀为“http://..”、“file://..”、“//..”和“..”的路径)

var path:String = "http://../assets/the_song.mp3";

var url:URLRequest = new URLRequest( path );

var sound:Sound = new Sound();

sound.addEventListener( IOErrorEvent.IO_ERROR, ioErrorHandler);

sound.addEventListener( SecurityErrorEvent.SECURITY_ERROR, secHandler);

sound.load(url);

I have a project with a bunch of external sounds to a SWF. I want to play them, but any time I attempt load a new URL into the sound object it fails with either,

Error #2068: Invalid Sound

or raises an ioError with

Error #2032 Stream Error

// Tried with path prefixed with "http://.." "file://.." "//.." and "..")

var path:String = "http://../assets/the_song.mp3";

var url:URLRequest = new URLRequest( path );

var sound:Sound = new Sound();

sound.addEventListener( IOErrorEvent.IO_ERROR, ioErrorHandler);

sound.addEventListener( SecurityErrorEvent.SECURITY_ERROR, secHandler);

sound.load(url);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

给妤﹃绝世温柔 2024-07-11 21:08:53

好吧,我刚刚做了一个测试,将 mp3 放入一个目录:soundTest/assets/song.mp3,然后创建一个调用另一个目录中的 mp3 的 swf:soundTest/swfs/ soundTest.swf ,当我使用 var path:String = "../assets/song.mp3"; 时,它编译时没有错误。

你的实际目录结构是什么?

Well, I've just done a test by putting an mp3 in a directory: soundTest/assets/song.mp3 then creating a swf that calls the mp3 in another directory: soundTest/swfs/soundTest.swf and when I use var path:String = "../assets/song.mp3"; then it compiles with no errors.

What is your actual directory structure?

三岁铭 2024-07-11 21:08:53

除非您要输入完整的 url,否则不要使用 http:// 或 file://

Sound 可以从完整或相对 url 加载 mp3 文件。 您只需确保您的网址正确且有效。

例如,如果文件的完整路径为 http://www.something.com/assets /the_song.mp3,“/assets/the_song.mp3”路径即可。

Unless you're going to put a full url, don't use http:// or file://

Sound can load an mp3 file from a full or relative url. You just need to make sure your url is correct and valid.

For example, if the full path to the file is http://www.something.com/assets/the_song.mp3, a path of "/assets/the_song.mp3" would work.

长安忆 2024-07-11 21:08:53

您确实应该下载适用于 FireFox 的 httpfox。 这个嗅探器允许您查看浏览器中流过哪些数据。 您可以查看其加载的文件,包括每个文件的路径,甚至可以嗅探 POST 和 GET 变量。 这将向您显示文件的提取位置,并据此您可以相应地修复相对路径。

https://addons.mozilla.org/en-US/firefox/addon/ 6647

重要提示

从 SWF 调用的所有外部资源都与在 Web 上加载时加载它们的 html 文件相关,而不是与 SWF 相关。 唯一的例外是从 AS3 开始的,FLV 是相对于 SWF 的,而不是像其他所有资源一样加载 SWF 的 HTML 文档。 这就是为什么 SNIFFERS 是一个重要的工具,我挠了挠头,直到我注意到嗅探器中的 URL 调用了一个奇怪的路径。

以下是加载声音的方法。

var soundRequest:URLRequest = "path/to/file.mp3";
var s:Sound = new Sound(soundRequest);
var sChannel = s.play(0, int.MAX_VALUE); //Causes it to repeat by the highest possible number to flash.
//Above starts the sound immediatly (Streaming);

//现在等待完成,假装我们之前没有启动它。 s.addEventLister(Event.SOUND_COMPLETE, onSComplete, false, 0, true); 函数 onSComplete(e:Event):void { var sChannel = s.play(0, int.MAX_VALUE); //使其尽可能重复 }

You should really download httpfox for FireFox. This SNIFFER allows you to see what data is flowing through the browswer. You can see the files its loading, including the paths to each, and you can even sniff POST and GET variables. This will show you where the files are being pulled from and based off of that you can fix your relative paths accordingly.

https://addons.mozilla.org/en-US/firefox/addon/6647

Important:

All external assets called from the SWF are relative to the html file loading them when loaded on the web, not the SWF. The only exception, and this is something that started with AS3, FLV's are relative to the SWF, not the HTML document loading the SWF like every other asset. This is why SNIFFERS are an important tool, I scratched my head for a while until I noticed the URL in the sniffer was calling a weird path.

Below is how you can load sound.

var soundRequest:URLRequest = "path/to/file.mp3";
var s:Sound = new Sound(soundRequest);
var sChannel = s.play(0, int.MAX_VALUE); //Causes it to repeat by the highest possible number to flash.
//Above starts the sound immediatly (Streaming);

//Now to wait for completion instead, pretend we didnt start it before. s.addEventLister(Event.SOUND_COMPLETE, onSComplete, false, 0, true); function onSComplete(e:Event):void { var sChannel = s.play(0, int.MAX_VALUE); //Causes it to repeat by the highest possible }

月棠 2024-07-11 21:08:53

在这两种协议中,RTMP & HTTP,路径应该是--“path/to/mp3:file.mp3”或“path/to/mp3:file”。 我能记住。 请检查两者。

In both protocol, RTMP & HTTP, the path should be -- "path/to/mp3:file.mp3" or "path/to/mp3:file". I can remember. Please check both.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文