自己写的一个Flash mp3播放器代码

      :: Flash :: 2005-1-3 11:13
//遇到一个问题,就是动态文本的alpha不知道怎么改变???
//郁闷的说
songTitle.setMask(mask);
//////////////////////////系统初始化
playinfo.info.text = "loading...";
mylist._visible = false;
processbar._xscale = 1;
load_bar._xscale = 1;
var listsongs = false;
var loadlist = false;
var load_song = false;
var mySound = new Sound();
var songs = new Array();
var nowSong, nextIndex, playtime, nowTitle, nowIndex, songNum;
var sTemp;
///////////////////
var songlist = new XML();
songlist.ignoreWhite = true;
songlist.load("playlist.xml");
songlist.onLoad = function(e) {
    if (e) {
        sTemp = songlist.firstChild.firstChild;
        songs.push([sTemp.attributes.title, sTemp.attributes.url]);
        while (sTemp.nextSibling != null) {
            sTemp = sTemp.nextSibling;
            songs.push([sTemp.attributes.title, sTemp.attributes.url]);
        }
        for (var k = 0; k<songs.length; k++) {
            mylist.mysong.addItem({label:songs[k][0], data:songs[k][1]});
        }
        nowSong = songs[0][1];
        nowTitle = songs[0][0];
        nowIndex=0;
        songNum = songs.length;
        loadlist = true;
        mylist.mysong.addEventListener("change", myplay);
        playinfo.info.text = "load complete!";
    } else {
        trace("error");
    }
};
var myplay = new Object();
myplay.change = function(e) {
    clearInterval(mymove);
    clearInterval(myload);
    processbar._xscale = 1;
    load_bar._xscale = 1;
    songTitle._x = 160;
    load_song = false
    nowSong = e.target.selectedItem.data;
    nowTitle = e.target.selectedItem.label;
    nowIndex = e.target.selectedIndex;
    trace(nowIndex);
    playinfo.info.text = "loading...";
    mySound.stop();
    doPlay(nowSong);
};
//Functions for doing play....
function doPlay(url:String) {
    songTitle.title.text = nowTitle;
    mymove = setInterval(moveTitle, 150);
    myload = setInterval(loadbar, 50);
    if (load_song == true) {
        mySound.start(playtime/1000);
    } else {
        loadsong(url);
    }
}
function doStop() {
    mySound.stop();
    clearInterval(mymove);
    clearInterval(myload);
    playinfo.info.text = "Stop";
    playtime = 0;
}
//getNextsongs
function getNext() {
    mySound.stop();
    load_song = false;
    clearInterval(mymove);
    clearInterval(myload);
    processbar._xscale = 1;
    load_bar._xscale = 1;
    playinfo.info.text = "loading...";
    songTitle._x = 160;
    nextIndex = nowIndex+1;
    if (nextIndex>songNum-1) {
        nextIndex = 0;
    }
    trace(nextIndex);
    nowSong = songs[nextIndex][1];
    nowTitle = songs[nextIndex][0];
    trace(nowSong);
    doPlay(nowSong);
}
function getLast() {
    mySound.stop();
    load_song = false;
    clearInterval(mymove);
    clearInterval(myload);
    processbar._xscale = 1;
    load_bar._xscale = 1;
    playinfo.info.text = "loading...";
    songTitle._x = 160;
    nextIndex = nowIndex-1;
    if (nextIndex<0) {
        nextIndex = songNum-1;
    }
    nowSong = songs[nextIndex][1];
    nowTitle = songs[nextIndex][0];
    doPlay(nowSong);
}
function moveTitle() {
    songTitle._x = songTitle._x-2;
    if (songTitle._x<-150) {
        songTitle._x = 160;
    }
}
function doPause() {
    if (playinfo.info.text != "Pause") {
        mySound.stop();
        clearInterval(mymove);
        clearInterval(myload);
        playinfo.info.text = "Pause";
        playtime = mySound.position;
    } else {
        mymove = setInterval(moveTitle, 150);
        playinfo.info.text = "Play";
        myload = setInterval(loadbar, 50);
        mySound.start(playtime/1000);
    }
}
//Functions for show playing info
function loadsong(url:String) {
    mySound.stop();
    mySound.loadSound(url, true);
    mySound.onLoad = function(e) {
        if (e) {
            load_song = true;
        } else {
            playinfo.info.text = "load Error";
        }
    };
    mySound.onSoundComplete = function() {
        trace("over");
        getNext();
    };
}
function loadbar() {
    m = mySound.getBytesLoaded();
    n = mySound.getBytesTotal();
    if (n>0) {
        loadinfo = m/n*100;
        load_bar._xscale = m/n*100;
    }
    if (mySound.position>1000) {
        playinfo.info.text = "Play";
    }
    playtime = mySound.position;
    processbar._xscale = mySound.position/mySound.duration*100;
}
//为按钮定义事件
list_ck.onPress = function() {
    if (listsongs == false) {
        listsongs = true;
        mylist._visible = true;
    } else {
        mylist._visible = false;
        listsongs = false;
    }
};
pause_ck.onPress = doPause;
stop_ck.onPress = doStop;
last_ck.onPress = getLast;
next_ck.onPress = getNext;
play_ck.onPress = function() {
    if (loadlist == true) {
        clearInterval(myload);
        clearInterval(mymove);
        playinfo.info.text = "loading";
        doPlay(nowSong);
    }
};
标签集:TAGS:
回复Comments() 点击Count()

回复Comments

{commentauthor}
{commentauthor}
{commenttime}
{commentnum}
{commentcontent}
作者:
{commentrecontent}