用BxScript写一个音乐播放器

BxScript增加新功能,支持语音播放(mp3),扩展接口在全局对象Voice下,代码比较简洁且简单。

图一

图二

Win.create("BxScript", 800, 650, true, false, true);
Win.add([
    { type: "image", id: "img", title: "-", width: 800, height: 550, x: 0, y: 0, fontSize: "10", font: "微软雅黑" },
    { type: "label", id: "mp3Name", title: "未播放", width: 100, height: 30, x: 50, y: 560, fontSize: "10", font: "微软雅黑" },
    { type: "button", id: "nextBtn", title: "下一首", width: 100, height: 30, x: 350, y: 560, fontSize: "10", font: "微软雅黑" },
]);

var index = 1;
var base = "C:\\Users\\Administrator\\Desktop\\1\\"
var mp3list = ["38.6", "9420 - 麦小兜", "双截棍"]

Voice.open(base + mp3list[index] + ".mp3")
Win.mp3Name.setText("正在播放: " + mp3list[index])
Win.img.src(base + mp3list[index] + ".jpg")
Voice.play();

Win.nextBtn.onClick = function(){
    if(index >= mp3list.length - 1){
        index = 0;
    } else {
        index++;
    }
    Voice.close()
    Voice.open(base + mp3list[index] + ".mp3")
    Win.mp3Name.setText("正在播放: " + mp3list[index])
    Win.img.src(base + mp3list[index] + ".jpg")
    Voice.play();
}

Win.loop();

解释器:BxScript: 本项目主要处于学习目的而开发,灵感来源主要是otto开源项目,语法主要是JavaScript语法,但是有部分特色(见下方),JavaScript的prototype等没有支持;未来支持桌面应用开发

开发套件:BxScriptIDE: 为BxScript开发的一个开源ide