gpt4 book ai didi

xml - AS3-我正在尝试通过XML播放列表播放声音文件,但似乎无法正常工作

转载 作者:行者123 更新时间:2023-12-03 02:10:52 24 4
gpt4 key购买 nike

我正在尝试通过XML播放列表播放声音文件,但似乎没有用。
我得到这个:错误#2044:未处理的IOErrorEvent :。 text =错误#2032:流错误。知道为什么吗?帮助非常感谢。

var soundURL:URLRequest;
var mySound:Sound = new Sound ();
var mySoundChannel:SoundChannel = new SoundChannel();
var playing:Boolean = true;
var resumeTime:Number = 0;
var myCurrentSong:Number = 0;
var currentSong:int = 0;
var loadedXML:XML

var myXMLLoader:URLLoader = new URLLoader();
var myURL:URLRequest = new URLRequest("playList.xml");
myXMLLoader.load(myURL);

myXMLLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void {
loadedXML = XML(e.target.data);
soundURL = new URLRequest(loadedXML.songFile[currentSong].@songURL);
mySound = new Sound(soundURL);
}

btnPlayPause.buttonMode = true;
btnStop.buttonMode = true;
btnNext.buttonMode = true;

btnPlayPause.addEventListener(MouseEvent.CLICK, playSound);
btnStop.addEventListener(MouseEvent.CLICK, stopSound);

function playSound(m:MouseEvent){
if (playing==true)
{
btnPlayPause.gotoAndStop("lbPause");
mySound.load(myURL);
mySoundChannel = mySound.play(resumeTime);
playing = false;
}
else
{
btnPlayPause.gotoAndStop("lbPlay");
resumeTime = mySoundChannel.position;
mySoundChannel.stop();
playing = true;
}
}

function stopSound(f:MouseEvent):void
{
mySoundChannel.stop();
}

最佳答案

您很亲密,但是在设置跟踪网址时遇到了一个小问题。

如果您的XML文件看起来像这样

< ?xml version="1.0" encoding="UTF-8"?>

<MP3s>

<songFile>


<songURL> Apakalypse_Exist.mp3 </songURL>


</songFile>

</MP3s>

然后代码应该工作。查看 function processXML的最后一行
var soundURL:URLRequest;
var mySound:Sound = new Sound ();
var mySoundChannel:SoundChannel = new SoundChannel();
var playing:Boolean = true;
var resumeTime:Number = 0;
var myCurrentSong:Number = 0;
var currentSong:int = 0;
var loadedXML:XML;

var myXMLLoader:URLLoader = new URLLoader();
var myURL:URLRequest = new URLRequest("playList.xml");

////Setup...
btnPlayPause.buttonMode = true;
btnStop.buttonMode = true;
btnNext.buttonMode = true;

btnPlayPause.addEventListener(MouseEvent.CLICK, playSound);
btnStop.addEventListener(MouseEvent.CLICK, stopSound);

myXMLLoader.load (myURL);
myXMLLoader.addEventListener(Event.COMPLETE, processXML);


//// Functions...
function processXML (e:Event):void
{
loadedXML = XML(e.target.data);
//trace("loaded XML" + loadedXML); //for test only

//soundURL = new URLRequest(loadedXML.songFile[currentSong].@songURL);
//mySound = new Sound(soundURL);

mySound = new Sound(new URLRequest(loadedXML.songFile[currentSong].songURL));
}

function playSound (m:MouseEvent)
{
if (playing==true)
{
btnPlayPause.gotoAndStop("lbPause");
//mySound.load(myURL);
mySoundChannel = mySound.play(resumeTime);
playing = false;
}
else
{
btnPlayPause.gotoAndStop("lbPlay");
resumeTime = mySoundChannel.position;
mySoundChannel.stop();
playing = true;
}
}

function stopSound (f:MouseEvent):void
{
mySoundChannel.stop();
}

关于xml - AS3-我正在尝试通过XML播放列表播放声音文件,但似乎无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24228065/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com