使用JavaScript和swf播放mp3

时间:2010-02-23 23:09:05

标签: javascript flash mp3

是否有Flash MP3播放器允许我执行以下操作,将URL传递给mp3文件并自动播放。为了帮助解答 - 这里有详细的代码,描述了我想要做的事情:

<object id="mp3PlayerSwf" type="application/x-shockwave-flash" data="mp3Player.swf">
 <param name="movie" value="mp3Player.swf">
</object>

<input type="button" id="soundPlay1" value="Sound Play 1" />

<script type="text/javascript">
    function eventHandler1(sender) {
        var mp3Player = document.getElementById("mp3PlayerSwf");
        mp3Player.playSound("http://myUrl.com/my.mp3");
    }

    var soundPlay1 = document.getElementById('soundPlay1');
    if (soundPlay1.addEventListener) {
        soundPlay1.addEventListener('click', eventHandler1, false);
    }
    // IE
    else if (soundPlay1.attachEvent) {
        soundPlay1.attachEvent('onclick', eventHandler1);
    }
</script>

约束是我不能使用具有JavaScript初始化的库 - 例如SoundManager2 - http://www.schillmania.com/content/projects/soundmanager2/

感谢您的帮助!

2 个答案:

答案 0 :(得分:5)

尝试使用露水:http://www.alsacreations.fr/dewplayer-en

您可以像这样使用它(从链接中获取的示例代码):


<object type="application/x-shockwave-flash" data="dewplayer.swf" width="200" height="20" id="dewplayer" name="dewplayer">
<param name="movie" value="dewplayer.swf" />
<param name="flashvars" value="mp3=test.mp3" />
<param name="wmode" value="transparent" />
</object>

答案 1 :(得分:2)

另一位玩家将是http://musicplayer.sourceforge.net