Flash mp3 播放器抛出错误 2032 - 认为 URLRequest 是罪魁祸首?
我正在尝试为我正在开发的网站设置音频播放器,但我不断遇到错误 2032。 .swf 与我的歌曲列表文件一起位于我的主文件夹中。歌曲文件本身位于名为“songs/”的子文件夹中,
我不确定是什么原因导致此问题,任何输入都会有所帮助。
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.collections.ArrayList;
import mx.collections.XMLListCollection;
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.utils.ArrayUtil;
private var sound:Sound; // Mp3 File
private var soundChannel:SoundChannel; // Reference to playing channel
private var pausePosition:Number; // Current play position (time)
private var percent:Number; // Current played percentage
private var isPlaying:Boolean = false; // Is the mp3 playing?
private var isLoaded:Boolean = false; // Is the mp3 loaded?
//private var updateSeek:Timer = new Timer(500); // Timer for updating the seek bar
private var currentSong:String;
private var index:int;
private var start:Boolean = true;
private var songs:Array;
private function init():void {
grabSongs();
}
private function grabSongs():void{
var theLoader:URLLoader = new URLLoader();
var theRequest:URLRequest = new URLRequest("songlist.txt");
theLoader.load(theRequest);
theLoader.addEventListener(Event.COMPLETE, loadComplete);
}
private function loadComplete(theEvent:Event):void{
songs = theEvent.target.data.split("\n");
currentSong = songs[0];
index = 0;
}
private function playPause(e:Event = null):void {
// Song playing?
if(isPlaying) {
// Save the current position in the track, stop playback, change button icon
pausePosition = soundChannel.position;
soundChannel.stop();
this.btnPlay.label = "Play";
// If the URL has been changed but not loaded, hide seekbar
// Song is not playing?
} else {
if(!isLoaded) {
// If the song isn't loaded yet, set up a new sound load request
if(start == true){
start = false;
}
sound = new Sound();
sound.load(new URLRequest("songs/" + currentSong));
// Add an event listener to check for song load complete event
sound.addEventListener(Event.COMPLETE, songLoaded);
this.btnPlay.label ="Pause";
} else {
// The song IS loaded, so play it
soundChannel = sound.play(pausePosition);
this.btnPlay.label = "Pause";
}
}
// Regardless of playing state, change it now to the opposite
isPlaying = !isPlaying;
}
private function songLoaded(e:Event):void {
// Remove load event listener
sound.removeEventListener(Event.COMPLETE, songLoaded);
// Play the song
soundChannel = sound.play(0);
// Song is loaded
isLoaded = true;
}
private function prev(e:Event = null):void {
if(start == false){
if(index == 0){
index = songs.length - 1;
}else{
index--;
}
currentSong = songs[index];
isPlaying = true;
isLoaded = false;
playNew(e);
}
}
private function next(e:Event = null):void {
if(start == false){
if(index == songs.length - 1){
index = 0;
}else{
index++;
}
currentSong = songs[index];
isPlaying = true;
isLoaded = false;
playNew(e);
}
}
private function playNew(e:Event = null):void {
soundChannel.stop();
sound = new Sound();
sound.load(new URLRequest("songs/" + currentSong));
// Add an event listener to check for song load complete event
sound.addEventListener(Event.COMPLETE, songLoaded);
this.btnPlay.label = "Pause";
}
]]>
</fx:Script>
<s:Button id="btnPrev" label="Previous" chromeColor="#000000" focusColor="#000000" color="#8D1111" enabled="true" click="{prev(event)}" height="20" width="80" x="0" y="0"/>
<s:Button id="btnPlay" label="Play" chromeColor="#000000" focusColor="#000000" color="#8D1111" enabled="true" click="{playPause(event)}" height="20" width="80" x="81" y="0"/>
<s:Button id="btnNext" label="Next" chromeColor="#000000" focusColor="#000000" color="#8D1111" enabled="true" click="{next(event)}" height="20" width="80" x="162" y="0"/>
这在我的笔记本电脑上本地工作,但是当我上传 swf 时,它会抛出错误 2032。
感谢
更新
因此,设置与 FlexFiend 的回答完全一样,以及 http://localhost/FlexStuff/songs/ 我尝试检查 Flash 调试器的日志文件,这是我的消息:
错误 #2032:流错误。网址:http://www.mywebsite.com/framework_4.0.0.14159.swf
我非常不熟悉这意味着什么,但也许它导致了我的问题?
I am trying to set up an audio player for a website I am working on, and I keep running into this Error 2032.
The .swf is located in my main folder along with my songlist file. The song files themselves are located in a subfolder called songs/
I am not sure what could be causing this, and any input would be helpful.
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.collections.ArrayList;
import mx.collections.XMLListCollection;
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.utils.ArrayUtil;
private var sound:Sound; // Mp3 File
private var soundChannel:SoundChannel; // Reference to playing channel
private var pausePosition:Number; // Current play position (time)
private var percent:Number; // Current played percentage
private var isPlaying:Boolean = false; // Is the mp3 playing?
private var isLoaded:Boolean = false; // Is the mp3 loaded?
//private var updateSeek:Timer = new Timer(500); // Timer for updating the seek bar
private var currentSong:String;
private var index:int;
private var start:Boolean = true;
private var songs:Array;
private function init():void {
grabSongs();
}
private function grabSongs():void{
var theLoader:URLLoader = new URLLoader();
var theRequest:URLRequest = new URLRequest("songlist.txt");
theLoader.load(theRequest);
theLoader.addEventListener(Event.COMPLETE, loadComplete);
}
private function loadComplete(theEvent:Event):void{
songs = theEvent.target.data.split("\n");
currentSong = songs[0];
index = 0;
}
private function playPause(e:Event = null):void {
// Song playing?
if(isPlaying) {
// Save the current position in the track, stop playback, change button icon
pausePosition = soundChannel.position;
soundChannel.stop();
this.btnPlay.label = "Play";
// If the URL has been changed but not loaded, hide seekbar
// Song is not playing?
} else {
if(!isLoaded) {
// If the song isn't loaded yet, set up a new sound load request
if(start == true){
start = false;
}
sound = new Sound();
sound.load(new URLRequest("songs/" + currentSong));
// Add an event listener to check for song load complete event
sound.addEventListener(Event.COMPLETE, songLoaded);
this.btnPlay.label ="Pause";
} else {
// The song IS loaded, so play it
soundChannel = sound.play(pausePosition);
this.btnPlay.label = "Pause";
}
}
// Regardless of playing state, change it now to the opposite
isPlaying = !isPlaying;
}
private function songLoaded(e:Event):void {
// Remove load event listener
sound.removeEventListener(Event.COMPLETE, songLoaded);
// Play the song
soundChannel = sound.play(0);
// Song is loaded
isLoaded = true;
}
private function prev(e:Event = null):void {
if(start == false){
if(index == 0){
index = songs.length - 1;
}else{
index--;
}
currentSong = songs[index];
isPlaying = true;
isLoaded = false;
playNew(e);
}
}
private function next(e:Event = null):void {
if(start == false){
if(index == songs.length - 1){
index = 0;
}else{
index++;
}
currentSong = songs[index];
isPlaying = true;
isLoaded = false;
playNew(e);
}
}
private function playNew(e:Event = null):void {
soundChannel.stop();
sound = new Sound();
sound.load(new URLRequest("songs/" + currentSong));
// Add an event listener to check for song load complete event
sound.addEventListener(Event.COMPLETE, songLoaded);
this.btnPlay.label = "Pause";
}
]]>
</fx:Script>
<s:Button id="btnPrev" label="Previous" chromeColor="#000000" focusColor="#000000" color="#8D1111" enabled="true" click="{prev(event)}" height="20" width="80" x="0" y="0"/>
<s:Button id="btnPlay" label="Play" chromeColor="#000000" focusColor="#000000" color="#8D1111" enabled="true" click="{playPause(event)}" height="20" width="80" x="81" y="0"/>
<s:Button id="btnNext" label="Next" chromeColor="#000000" focusColor="#000000" color="#8D1111" enabled="true" click="{next(event)}" height="20" width="80" x="162" y="0"/>
This works locally on my laptop, but when I upload the swf it throws error 2032.
Thanks
Update
So the setup is exactly as FlexFiend answered, along with http://localhost/FlexStuff/songs/ I tried checking the log file of the flash debugger and this was my message:
Error #2032: Stream Error. URL: http://www.mywebsite.com/framework_4.0.0.14159.swf
I am very unfamiliar with what this means, but maybe its causing my problems?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
验证“songlist.txt”的路径是否位于本地服务器上。如果是在远程服务器上,那么就必须调查跨域问题。但如果是这样的话,它甚至不会尝试阅读它,而是会让您知道我认为违反了政策。
“songlist.txt”文件应与您在服务器上访问的 swf 位于同一目录中。 IE
Verify the path of "songlist.txt" as being on the local server. If it is on a remote server, then you have to investigate cross-domain issues. But if that were the case, it wouldn't even try to read it but would instead let you know of the policy violation I assume.
The "songlist.txt" file should be in the same directory as the swf you are accessing on your server. i.e
“framework_4.0.0.14159.swf”是大约 6 个 swf 文件之一,我显然还必须将其上传到我的服务器才能使该 swf 文件正常工作...我认为没有必要?
然而一旦上传,它就可以工作。这真的很奇怪,因为我的印象是我只需要上传我创建的 swf,而不是一堆帮助文件......
The 'framework_4.0.0.14159.swf' was one of about 6 swf files that I apparently had to also upload to my server to get this swf file to work...which I did not think was necessary??
Once uploaded however it does work. This is really weird since I was under the impression I just had to upload the swf I created, not a bunch of helper files...