| Action Script |
|---|
this.stop(); maxSong = 30; _soundbuftime = 2; playNow = false; timelineDraging = false; scrollDraging = false; soundLoading = true; shuffle = false; repeat = false; loadWait = 0; totalSong = 0; nowSong = 1; playedSong = 0; listMargine = 18; txtPos = "00:00"; txtArtist = "プレイリストの読み込み中"; txtSongtitle = "しばらくお待ちください"; pos = 0; oldPos = 0; loadingCheck = 0; dur = 0; stopPos = 0; scrollNum = 0; shuffleList = new Array(); playSound = new Sound(); checkSound = new Sound(); btPlay._visible = btRepeatOn._visible=btShuffleOn._visible=false; loadingBar._width = 0; playList.playList.listMc._visible = false; playList.setMask(playListMask); btPlay.enabled = btStop.enabled=btRew.enabled=btFf.enabled=btTimeline.enabled=false; for (var lp = 1; lp<=maxSong; lp++) { if (this["song"+lp] == undefined) { totalSong = lp-1; trace(totalSong); break; } else if (lp == maxSong) { totalSong = maxSong; trace(totalSong); } } if (totalSong<=12) { btScroll.enabled = false; } for (var lp = 1; lp<=totalSong; lp++) { duplicateMovieClip("playList.playList.listMc", "listMc"+lp, lp); with (playList.playList["listMc"+lp]) { _y = (lp-1)*listMargine; if (lp<=9) { txtNumber = "0"+lp+"."; } else { txtNumber = lp+"."; } txtSong = this["song"+lp]; listBt.enabled = false; } if (sysOS == "Mac") { playList.playList["listMc"+lp].listTxt._y -= 2; } playList.playList["listMc"+lp].btNumber = lp; playList.playList["listMc"+lp].listBt.onRelease = function() { songChange(this._parent.btNumber); }; } function checkSoundLoaded() { if (loadWait == 0) { trace("checkSound.onID3の実行"); trace("読み込まれたmp3ファイルは、[ "+nowSong+" : "+this["song"+nowSong]+" ]"); playList.playList["listMc"+nowSong].txtSong = checkSound.id3.TIT2; loadWait = 2; nowSong++; } } function songChange(state) { trace("曲が替わります。state = "+state); if (timelineDraging == true) { delete sliderTimeline.onMouseMove; timelineDraging = false; } if (state == "soundCmp" and repeat == true) { trace("同じ曲をリピート"); playSound.start(0); } else { if (state == "btRew") { if (playedSong == 1) { trace("リストの1曲目より前に移動したので、最後から再生します"); playedSong = totalSong; if (shuffle == true) { nowSong = Math.floor(Math.random()*totalSong+1); songShuffle(); } } else { playedSong--; } } else if (state == "btFf" or state == "soundCmp") { if (playedSong == totalSong) { playedSong = 1; trace("最初に戻って再生します"); if (shuffle == true) { nowSong = Math.floor(Math.random()*totalSong+1); songShuffle(); } } else { playedSong++; } } else { trace("プレイリストから直接選ばれました"); nowSong = state; if (shuffle == false) { playedSong = nowSong; } else { playedSong = 1; songShuffle(); } } if (shuffle == true) { nowSong = shuffleList[playedSong-1]; } else { nowSong = playedSong; } soundLoading = true; newPlaySound(); playSound.loadSound(this["song"+nowSong], true); if (playNow == false) { playSound.stop(); stopPos = 1; } playList.playList.selectBar._y = (nowSong-1)*18; } playSound.setVolume((sliderVolume.slider._x/sliderVolume.sliderMax)*100); } function newPlaySound() { playSound = new Sound(); playSound.onID3 = function() { //id3tagの情報読み込み txtArtist = playSound.id3.TPE1; //演奏者 txtSongtitle = playSound.id3.TIT2; //タイトル txtComment = playSound.id3.COMM; //コメント txtLyric = playSound.id3.TCOP; //本来は著作権情報だがエディターの関係で歌詞に利用 }; playSound.onSoundComplete = function() { songChange("soundCmp"); }; } function timeChanger(totalMilli) { var totalSec = Math.floor(totalMilli/1000); var sec = totalSec%60; var min = (totalSec-sec)/60; if (String(sec).length<2) { sec = "0"+sec; } if (String(min).length<2) { min = "0"+String(min); } return (min+":"+sec); } function soundPlaying() { if (playSound.getBytesTotal() == playSound.getBytesLoaded() and playSound.getBytesLoaded()>1000) { soundLoading = false; } else { soundLoading = true; } oldPos = pos; pos = playSound.position; if (oldPos == pos) { loadingCheck++; } else { loadingCheck = 0; } if (playNow == true) { if (loadingCheck<10) { dispState.gotoAndStop("play"); } else { dispState.gotoAndStop("load"); } } else { dispState.gotoAndStop("stop"); } txtPos = timeChanger(pos); dur = (playSound.duration*playSound.getBytesTotal())/playSound.getBytesLoaded(); loadedDur = playSound.duration; if (dur>0) { btTimeline.enabled = true; } else { btTimeline.enabled = false; } if (timelineDraging == false) { sliderTimeline.slider._x = Math.round((pos/dur)*sliderTimeline.sliderMax); } loadingBar._xscale = (playSound.getBytesLoaded()/playSound.getBytesTotal())*100; loadingBar._width = loadingBar.Math.round(loadingBar._width); } function songShuffle() { shuffleList = new Array(); var dummyArray = new Array(); for (var lp = 1; lp<=totalSong; lp++) { if (lp != nowSong) { dummyArray.push(lp); } } while (dummyArray.length>0) { var randomNum = Math.floor(Math.random()*dummyArray.length); shuffleList.push(dummyArray[randomNum]); dummyArray.splice(randomNum, 1); } shuffleList.unshift(nowSong); trace("新規シャッフルリストの作成 "+shuffleList.join()); } this.onEnterFrame = function() { if (loadWait == 1) { if (nowSong == totalSong+1) { playNow = true; nowSong = 0; songChange("btFf"); delete checkSound; btPlay.enabled = btStop.enabled=btRew.enabled=btFf.enabled=true; for (var lp = 1; lp<=totalSong; lp++) { playList.playList["listMc"+lp].listBt.enabled = true; } this.onEnterFrame = function() { soundPlaying(); }; } else { loadWait = 0; checkSound.loadSound(this["song"+nowSong], true); checkSound.stop(); } } else if (loadWait>1) { loadWait--; } }; checkSound.onID3 = function() { checkSoundLoaded(); }; btPlay.onRelease = function() { playSound.start(stopPos/1000); playNow = true; loadingCheck = 0; this._visible = false; btStop._visible = true; }; btStop.onRelease = function() { playSound.stop(); stopPos = pos; playNow = false; this._visible = false; btPlay._visible = true; }; btRew.onRelease = function() { songChange("btRew"); }; btFf.onRelease = function() { songChange("btFf"); }; btRepeatOff.onRelease = function() { repeat = true; this._visible = false; btRepeatOn._visible = true; }; btRepeatOn.onRelease = function() { repeat = false; this._visible = false; btRepeatOff._visible = true; }; btShuffleOff.onRelease = function() { shuffle = true; playedSong = 1; songShuffle(); this._visible = false; btShuffleOn._visible = true; }; btShuffleOn.onRelease = function() { shuffle = false; playedSong = nowSong; this._visible = false; btShuffleOff._visible = true; }; btTimeline.onPress = function() { timelineDraging = true; with (sliderTimeline) { slider._x = Math.min(sliderMax, _xmouse); slider._x = Math.round(Math.max(sliderMin, slider._x)); if (soundLoading == true) { slider._x = Math.min(slider._x, sliderMax*(playSound.getBytesLoaded()/playSound.getBytesTotal())-1); } } sliderTimeline.onMouseMove = function() { this.slider._x = Math.min(this.sliderMax, this._xmouse); this.slider._x = Math.round(Math.max(this.sliderMin, this.slider._x)); if (soundLoading == true) { this.slider._x = Math.min(this.slider._x, this.sliderMax*(playSound.getBytesLoaded()/playSound.getBytesTotal())-1); } updateAfterEvent(); }; }; btTimeline.onRelease = btTimeline.onReleaseOutside=function () { delete sliderTimeline.onMouseMove; timelineDraging = false; playSound.start((dur*(sliderTimeline.slider._x/sliderTimeline.sliderMax))/1000); if (playNow == false) { playNow = true; btPlay._visible = false; btStop._visible = true; } }; btVolume.onPress = function() { with (sliderVolume) { slider._x = Math.min(sliderMax, _xmouse); slider._x = Math.round(Math.max(sliderMin, slider._x)); playSound.setVolume(100*(slider._x/sliderMax)); } sliderVolume.onMouseMove = function() { this.slider._x = Math.min(this.sliderMax, this._xmouse); this.slider._x = Math.round(Math.max(this.sliderMin, this.slider._x)); playSound.setVolume(100*(this.slider._x/this.sliderMax)); updateAfterEvent(); }; }; btVolume.onRelease = btVolume.onReleaseOutside=function () { delete sliderVolume.onMouseMove; }; btScroll.onPress = function() { scrollNum = listMargine*(totalSong-12)/sliderScroll.sliderMax; scrollDraging = true; with (sliderScroll) { slider._y = Math.min(sliderMax, _ymouse); slider._y = Math.round(Math.max(sliderMin, slider._y)); } playList.playList._y = -scrollNum*sliderScroll.slider._y; sliderScroll.onMouseMove = function() { this.slider._y = Math.min(this.sliderMax, this._ymouse); this.slider._y = Math.round(Math.max(this.sliderMin, this.slider._y)); playList.playList._y = Math.round(-scrollNum*this.slider._y); updateAfterEvent(); }; }; btScroll.onRelease = btScroll.onReleaseOutside=function () { scrollDraging = false; delete sliderScroll.onMouseMove; }; checkSound.loadSound(song1, true); checkSound.stop(); |
|