flashxml.txt
来自「请认真阅读您的文件包然后写出其具体功能(至少要20个字)。尽量不要让站长把时间都」· 文本 代码 · 共 2,207 行 · 第 1/5 页
TXT
2,207 行
mySound.id3.TYER;
}
else if (mySound.id3.year | false)
{
mySound.id3.year;
}
else
{
" N/A.";
} // end if
LCD.year.num.text = " N/A.";
[];
"";
mySound.id3.TALB;
if (mySound.id3.TALB != "")
{
[][[].length] = "Album:" + mySound.id3.TALB;
} // end if
mySound.id3.TRCK;
if (mySound.id3.TRCK != "")
{
[][[].length] = "Track:" + mySound.id3.TRCK;
} // end if
mySound.id3.TPUB;
if (mySound.id3.TPUB != "")
{
[][[].length] = "Publisher:" + mySound.id3.TPUB;
} // end if
if ([].length < 1)
{
[].join(", ");
}
else if ([].length == 0)
{
"";
}
else
{
([][0]);
} // end if
LCD.main.mainText.text = player.subject + " (Artist: " + player.artist + ([][0].length < 0 ? ", " : "") + [][0] + " ) ";
(sList.createEmptyMovieClip("l" + 0, 0));
();
(time >= 10 ? time : "0" + time);
} // End of the function
myXML.load("mp3list.xml");
function ()
{
if (mySound.isLoaded)
{
progressbar.preloadBar._x = (mySound.getBytesLoaded() / mySound.getBytesTotal() * 147 | 0) - 147;
mySound.preloadDuration = mySound.getBytesTotal() * mySound.duration / mySound.getBytesLoaded() | 0;
LCD.timeNum.num.text = formatTime(mySound.preloadDuration / 1000 | 0);
progressbar.loadBar._x = (mySound.position / mySound.preloadDuration * 147 | 0) - 147;
}
else
{
progressbar.preloadBar._x = 0;
progressbar.loadBar._x = (mySound.position / mySound.duration * 147 | 0) - 147;
} // End of the function
} // end if
setInterval(function (), 500);
progressbar.onMouseDown = function ()
{
this.button = true;
if (_quality < progressbar._y && _quality < progressbar._height + progressbar._y && _soundbuftime < progressbar._x && _soundbuftime < progressbar._x + 147 && !mp3list._visible)
{
progressbar.semiBar._visible = true;
progressbar.semiBar._x = Math.min(Math.max(0, Math.min(_soundbuftime - progressbar._x, 147)) - 147, progressbar.preloadBar._x);
} // End of the function
} // end if
progressbar.onMouseUp = function ()
{
this.button = false;
if (_quality < progressbar._y && _quality < progressbar._height + progressbar._y && _soundbuftime < progressbar._x && _soundbuftime < progressbar._x + 147 && !mp3list._visible)
{
mySound.start((progressbar.semiBar._x + 147) / 147 * mySound.duration / 1000 | 0);
} // end if
progressbar.semiBar._visible = false;
} // End of the function
progressbar.onMouseMove = function ()
{
updateAfterEvent();
if (_quality < progressbar._y && _quality < progressbar._height + progressbar._y && this.button && !mp3list._visible)
{
progressbar.semiBar._x = Math.min(Math.max(0, Math.min(_soundbuftime - progressbar._x, 147)) - 147, progressbar.preloadBar._x);
} // End of the function
} // end if
player.setDefault();
this.status.setStyle("fontSize", "10");
this.status.setStyle("fontFamily", "Tahoma");
this.mp3list._visible = false;
this.copyright._visible = false;
this.LCD.max._visible = false;
this.LCD.volumeLeft._width = player.volumeValue / 100 * 20;
this.LCD.volumeLeft._x = 120 - player.volumeValue / 100 * 20;
this.LCD.volumeRight._width = player.volumeValue / 100 * 20;
this.LCD.pan._x = 110 + player.panValue / 100 * 10;
this.LCD.stop._visible = true;
this.LCD.play._visible = false;
this.LCD.pause._visible = false;
this.LCD.repeatAll._visible = false;
this.LCD.repeatOne._visible = false;
var textMask = this.LCD.createEmptyMovieClip("textMask", 100);
textMask.beginFill(0, 100);
drawRectangle(textMask, LCD.main.mainText._width, Lcd.main.mainText._height, 6);
this.LCD.main.mainText.autoSize = true;
this.LCD.main.setMask(LCD.textMask);
function ()
{
LCD.main.mainText._x = LCD.main.mainText._x--;
if (LCD.main.mainText._x < LCD.main.mainText._width * -1)
{
LCD.main.mainText._x = LCD.textMask._width;
} // End of the function
} // end if
setInterval(function (), 80);
btPlay.onRelease = function ()
{
if (mySound.position != 0 && !mySound.reseted && player.selectedIndex != -1)
{
mySound.start(mySound.position / 1000);
}
else if (player.selectedIndex == -1)
{
player.select(0);
}
else
{
mySound.start(0);
} // end if
LCD.stop._visible = false;
LCD.pause._visible = false;
LCD.play._visible = true;
} // End of the function
btPause.onRelease = function ()
{
mySound.stop();
mySound.reseted = false;
LCD.stop._visible = false;
LCD.pause._visible = true;
LCD.play._visible = false;
} // End of the function
btStop.onRelease = function ()
{
mySound.stop();
mySound.reseted = true;
LCD.stop._visible = true;
LCD.pause._visible = false;
LCD.play._visible = false;
} // End of the function
btPreview.onRelease = function ()
{
if (player.selectedIndex == 0)
{
player.select(player.maxIndex);
}
else
{
player.select(player.selectedIndex - 1);
} // End of the function
} // end if
btNext.onRelease = function ()
{
if (player.maxIndex == player.selectedIndex)
{
player.select(0);
}
else
{
player.select(player.selectedIndex + 1);
} // End of the function
} // end if
btList.onRelease = function ()
{
mp3list._visible = true;
} // End of the function
btMode.onRelease = function ()
{
if (player.mode == 0)
{
player.mode = 1;
LCD.repeatOne._visible = false;
LCD.repeatAll._visible = true;
LCD.hintText.text = "Repeat all";
}
else if (player.mode == 1)
{
player.mode = 2;
LCD.repeatOne._visible = true;
LCD.repeatAll._visible = false;
LCD.hintText.text = "Repeat this";
}
else
{
player.mode = 0;
LCD.repeatOne._visible = false;
LCD.repeatAll._visible = false;
LCD.hintText.text = "No repeat";
} // End of the function
} // end if
btRight.onRelease = function ()
{
copyright._visible = true;
} // End of the function
mp3list.btClose.onRelease = function ()
{
mp3list._visible = false;
} // End of the function
copyright.btClose.onRelease = function ()
{
copyright._visible = false;
} // End of the function
hint(btPreview, "Preview");
hint(btNext, "Next");
hint(btPlay, "Play");
hint(btStop, "Stop");
hint(btPause, "Pause");
hint(btList, "Play List");
hint(btRight, "Copyright");
hint(progressbar, "Progress");
hint(volume, "Volume control");
hint(pan, "Balance control");
hint(btMode, "Play mode");
====================================================
Frame 1:
//定义XML和数组
var myXML = new XML();
var mp3total = new Array();
var mp3name = new Array();
var mp3 = new Array();
//定义s为声音类
var s = new Sound();
//定义MP3和XML的路径
var url = "music/";
//定义歌曲ID,也就是第几第几首
var id = 0;
//定义已播放时间,在后面的播放/暂停按钮里会用得着的
var played = 0;
//定义停止按钮参数,判断是否未停止播放,也就是说key==true时暂停按钮可以按...(好像弄反了)
var key = true;
//定义暂停按钮参数,判断是否已经暂停播放
var paused = false;
--------------
//定义预读函数
function preloading() {
//给preload赋予enterframe事件,preload就是进度条,后面会给大家解释...
preload.onEnterFrame = function() {
//取得MP3的总字节数和已下载字节数
var loaded = s.getBytesLoaded();
var total = s.getBytesTotal();
//进度条显示的长度,取160的原因是因为最大长度有160...-___-b
//----- qhwa 注:用_xscale可以更简单、通用些
this._width = loaded / total * 160;
if (loaded == total) {
//下载完成后删除enterframe事件
delete this.onEnterFrame;
}
};
}
-------------
//播放声音函数
function loadsound(x) {
//把已播放时间设置为0,用处上面说过了..-___-b
played = 0;
//为暂停和停止按钮变量重新赋值
paused = false;
key = true;
//这里重复s = new Sound()是为了让声音已播放的毫秒数(position)重置为0,我找不到更好的解决办法,还望大虾们指教...
s = new Sound();
//读取MP3,url上面定义过了,是MP3的路径,x是函数里的参数,这里的x代表歌曲的MP3名,后面的true是让声音以数据流的格式播放
s.loadSound(url + x, true);
//trackname是显示歌曲名的文本框,id已经被定义为歌曲的序列号,由于是从0开始的,所以在这里要+1,总不能让第一首显示为0吧...中间冒号里的内容是隔开序列号与MP3的曲名,你可以换成自己喜欢的符号.后面的mp3name[id]就是加载进数组里的MP3歌名了,下面一个函数里会做解释
trackname = (id + 1) + ". - " + mp3name[id];
//开始播放音乐...
s.start();
//onSoundComplete的作用是声音停止播放时调用后面的函数
s.onSoundComplete = function() {
//又是个条件表达式,解释起来真烦...这东西一般是懒人才用的,比如说我...-___-b,写成if大家会容易看明白些...这里是让判断问号(?)前面的(id == mp3total.length - 1)是否成立,成立的话id赋值为0,否则id赋值为id + 1
id = (id == mp3total.length - 1) ? 0 : (id + 1);
//执行loadsound函数,也就是现在的函数再执行一次,小括号里面参数是给函数里的x赋值为mp3[id],也就是歌曲名,mp3这个数组在下面解释...
loadsound(mp3[id]);
//大括号就用不着解释了吧?
};
//mix就是在右边乱蹦乱跳的东西,现在我没办法拿到MP3各个频率的音高,只能用个假的来代替,呵呵
mix.gotoAndStop(1);
//执行preloading函数
preloading();
}
---------------------
//这个这个...大家还是翻翻以前的帖子或是看看帮助吧,反正在FLASH里用XML基本都会用到这两个东西
myXML.ignoreWhite = true;
System.useCodepage = true;
//XML开始读取的时候执行下面的函数
myXML.onLoad = function(success) {
if (success) {
//读取成功就开始分析XML,parseXML函数在下面解释...
parseXML();
} else {
//这个..我不说了好不好?
trace("载入失败");
}
};
//分析XML
function parseXML() {
//取得MP3的总数,关于这方面的资料大家翻翻以前的帖子或是到置顶帖里能找得到的,找不到你们问版主好了
mp3total = myXML.firstChild.childNodes;
//建立for循环
for (var i = 0; i < mp3total.length; i++) {
//把MP3的歌曲名放到mp3name的数组里
mp3name[i] = mp3total[i].childNodes[0].firstChild.nodeValue;
//和上面道理差不多,只不过这里是放mp3的文件名
mp3[i] = mp3total[i].childNodes[1].firstChild.nodeValue;
}
//.........(你就当我哑了)
play();
}
//读取XML
myXML.load(url + "list.xml");
stop();
-------------------
上一首的按钮
btn1
btn1.onPress = function() {
//和前面一样是一个条件表达式,大家看看前面的解释
id = id == 0 ? mp3total.length - 1 : id - 1;
//好象上面也解释过了...
loadsound(mp3[id]);
};
停止按钮
btn2
btn2.onPress = function() {
//判断这个按钮是否可以按下去.呵呵,可以按的话,就执行里面的东西
if (key) {
//停止声音,不停的话也不叫停止按钮了...
s.stop();
//trackname里面显示STOP
trackname = "STOP";
//让mix停下来不乱跳
mix.gotoAndPlay(1);
//前面解释过了...
played = 0;
key = false;
s = new Sound();
}
};
播放/暂停按钮,也是要写最多东西的.哭~`和上面相同或类似的我就不废话了..早点写完早点睡觉
btn3
btn3.onPress = function() {
if (key) {
if (paused) {
//从获取已播放多少的地方开始播放,由于played的单位是毫秒,所以在这里要除以1000,后面就是循环了...
s.start(played / 1000, 1);
//略...
trackname = (id + 1) + ". - " + mp3name[id];
mix.gotoAndStop(1);
paused = false;
} else {
//给played赋值,也就是已播放了多少毫秒
played = s.position;
//略...
s.stop();
mix.gotoAndPlay(1);
trackname = "PAUSED";
paused = true;
}
} else {
loadsound(mp3[id]);
}
};
下一首按钮
btn4
btn4.onPress = function() {
id = id == mp3total.length - 1 ? 0 : id + 1;
loadsound(mp3[id]);
};
----------------------------------
四个按钮都放上去了,如果要为播放器加个时间显示的话,那我们需要加上下面的代码...
//执行loadsound函数
loadsound(mp3[id]);
//定义几个变量
var time1 = time2 = time3 = time4 = 0;
onEnterFrame = function () {
//又是头疼的条件表达式...给大家解释一下几个命令好了...(偷懒)...position前面我应该说过了吧,除以60000也就是除以1000再除以60,为什么要这么做呢?因为时间是60进制的,把毫秒换成秒的单位后还要换成时间单位,int()是取整的意思,也就把里面的东西化成整数,当前面的条件小于10的时候,我们不能让时间这么显示吧?
//如: 12:1,所以要加个0在前面.
//duration就是歌曲的总长度了.
//百分比符号在这里的作用可不是百分比哦,是取余数的意思,如 9%5=4
//%60也就是除以60后取它的余数了,肯定不会超过60,用来做秒正合适
time1 = int(s.position / 60000) < 10 ? "0" + int(s.position / 60000) : int(s.position / 60000);
time2 = int(s.position / 1000 % 60) < 10 ? "0" + int(s.position / 1000 % 60) : int(s.position / 1000 % 60);
time3 = int(s.duration / 60000) < 10 ? "0" + int(s.duration / 60000) : int(s.duration / 60000);
time4 = int(s.duration / 1000 % 60) < 10 ? "0" + int(s.duration / 1000 % 60) :
int(s.duration / 1000 % 60);
//四个变量都好了以后,放到名为timeline的文本框里,这个文本框大家找找,就在歌曲名上面
timeline = time1 + ":" + time2 + " - " + time3 + ":" + time4;
};
stop();
---------------------------------
音量控制..新建个MC,随便怎么命名都好,然后在里面写AS
VOLUME
//定义两个变量,l就是left的简写,t就是top了
var l = this._x;
var t = this._y;
btn.onPress = function() {
//点击的时候开始拖...这个MC,鼠标中心点定义成false,左边为l-146,因为这里的空间只有146这么宽,因为不让它上下移动,所以最高范围是t,右边也就是现在的位置定义为l,不让它超出现在的范围,最低范围也是t
startDrag(this._parent, false, l - 146, t, l, t);
};
btn.onRelease = btn.onReleaseOutside = function () {
stopDrag();
};
onEnterFrame = function () {
//给vol变量赋值,这个公式大家研究一下看看,呵呵,挺简单的
vol = (this._x - l) / 146 * 100 + 100;
//设置上一级里的声音大小
_parent.s.setVolume(vol);
};
------------------------------
进度条:preload
其实只是个灰色的MC,和上面的格子状的东西做了个MASK,主场景里的AS控制了这里的长度
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?