加载 mp3 播放器时出现 xml 错误

发布于 2024-12-27 17:53:14 字数 1973 浏览 3 评论 0原文

我在加载 mp3 播放器时遇到错误,这是按 Ctrl+Enter 时得到的结果。

TypeError:错误 #1090:XML 解析器失败:元素格式错误。
  在 moviesound_fla::MainTimeline/getsongs()
  在 flash.events::EventDispatcher/dispatchEventFunction()
  在 flash.events::EventDispatcher/dispatchEvent()
  在 flash.net::URLLoader/onComplete()

这是我使用的 xml

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

<song atitle="Blind Willie" aurl="blind_willie.mp3" />

<song atitle="Wayfaring Stranger" aurl="wayfaring_stranger.mp3" />

<song atitle="Come, Thou Fount of Every Blessing" aurl="come_thou_fount.mp3" />

<song atitle="Give Me Jesus" aurl="give_me_jesus.mp3" />

</songs>

</xml>

这是我的操作脚本

var getfile:URLLoader=new URLLoader(new URLRequest('song.xml'));

var amountofsongs:int=0;
var currentsong:int=0;
var songlist:XML = new XML();
var sc:SoundChannel=new SoundChannel();

getfile.addEventListener(Event.COMPLETE, getsongs);
n_btn.addEventListener(MouseEvent.MOUSE_DOWN,n_song);
b_btn.addEventListener(MouseEvent.MOUSE_DOWN,b_song);

function getsongs(e:Event):void {
    songlist = XML(e.target.data);
    amountofsongs = songlist.song.length()-1;
    playsong();
}

function n_song(e:MouseEvent):void {
    currentsong++;
    playsong();
}
function b_song(e:MouseEvent):void {
    currentsong--;
    playsong();
}

function playsong():void{
    sc.stop();
    if (currentsong>amountofsongs){
        currentsong=0;
    }if (currentsong<0){
        currentsong=amountofsongs;
    }
    song_txt.text=songlist.song[currentsong].@atitle;
    var song:Sound=new Sound(new URLRequest(songlist.song[currentsong].@url));
    sc=song.play();
    sc.addEventListener(Event.SOUND_COMPLETE,songend);
}
function songend(e:Event):void {
    e.target.stop();
    currentsong++;
    playsong();
}

只有两个按钮,即上一个 (b_btn) 和下一个 (n_btn)

此操作脚本是否有任何错误,或者只有将其放在网页上后才能工作?

I'm having an error while loading an mp3 player, here is what I getting when hitting Ctrl+Enter.

TypeError: Error #1090: XML parser failure: element is malformed.
  at moviesound_fla::MainTimeline/getsongs()
  at flash.events::EventDispatcher/dispatchEventFunction()
  at flash.events::EventDispatcher/dispatchEvent()
  at flash.net::URLLoader/onComplete()

This is the xml I used

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

<song atitle="Blind Willie" aurl="blind_willie.mp3" />

<song atitle="Wayfaring Stranger" aurl="wayfaring_stranger.mp3" />

<song atitle="Come, Thou Fount of Every Blessing" aurl="come_thou_fount.mp3" />

<song atitle="Give Me Jesus" aurl="give_me_jesus.mp3" />

</songs>

</xml>

Here is my action script

var getfile:URLLoader=new URLLoader(new URLRequest('song.xml'));

var amountofsongs:int=0;
var currentsong:int=0;
var songlist:XML = new XML();
var sc:SoundChannel=new SoundChannel();

getfile.addEventListener(Event.COMPLETE, getsongs);
n_btn.addEventListener(MouseEvent.MOUSE_DOWN,n_song);
b_btn.addEventListener(MouseEvent.MOUSE_DOWN,b_song);

function getsongs(e:Event):void {
    songlist = XML(e.target.data);
    amountofsongs = songlist.song.length()-1;
    playsong();
}

function n_song(e:MouseEvent):void {
    currentsong++;
    playsong();
}
function b_song(e:MouseEvent):void {
    currentsong--;
    playsong();
}

function playsong():void{
    sc.stop();
    if (currentsong>amountofsongs){
        currentsong=0;
    }if (currentsong<0){
        currentsong=amountofsongs;
    }
    song_txt.text=songlist.song[currentsong].@atitle;
    var song:Sound=new Sound(new URLRequest(songlist.song[currentsong].@url));
    sc=song.play();
    sc.addEventListener(Event.SOUND_COMPLETE,songend);
}
function songend(e:Event):void {
    e.target.stop();
    currentsong++;
    playsong();
}

There are only two buttons which is previous (b_btn) and next (n_btn)

Is there any errors on this action script or it may only work after placed it on a webpage?

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

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

发布评论

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

评论(1

耳根太软 2025-01-03 17:53:14

正确的 XML 文件是:

<?xml version="1.0" encoding="UTF-8"?>
<songs>
    <song atitle="Blind Willie" aurl="blind_willie.mp3" />
    <song atitle="Wayfaring Stranger" aurl="wayfaring_stranger.mp3" />
    <song atitle="Come, Thou Fount of Every Blessing" aurl="come_thou_fount.mp3" />
    <song atitle="Give Me Jesus" aurl="give_me_jesus.mp3" />
</songs>

无需使用

A correct XML-file is:

<?xml version="1.0" encoding="UTF-8"?>
<songs>
    <song atitle="Blind Willie" aurl="blind_willie.mp3" />
    <song atitle="Wayfaring Stranger" aurl="wayfaring_stranger.mp3" />
    <song atitle="Come, Thou Fount of Every Blessing" aurl="come_thou_fount.mp3" />
    <song atitle="Give Me Jesus" aurl="give_me_jesus.mp3" />
</songs>

There is no need to use </xml>

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