musicPlayer.mxml====================================================================================
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="560" height="630" initialize="System.useCodePage=true;init()">
<mx:Style>
Application{
backgroundColor : #ffffff;
fontSize : 12;
}
</mx:Style>
<mx:Script>
<![CDATA[
import mx.controls.*;
import flash.utils.*;
[Bindable]
private var soundFactory:Sound;
private var channel:SoundChannel;
private var positionTimer:Timer;
private var pausePosition:int;
private var src:String;
private var bytes:ByteArray = new ByteArray();
private var PLOT_HEIGHT:int = 150;
private var CHANNEL_LENGTH:int = 256;
private var isPlay:Boolean;
private function init():void
{
listRequest.send();
src = "http://shallaazm.tistory.com/attachment/ek170000000001.mp3";
playSound();
}
private function playSound():void
{
var req:URLRequest = new URLRequest(src);
soundFactory = new Sound();
soundFactory.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
soundFactory.load(req);
channel = soundFactory.play();
this.addEventListener(Event.ENTER_FRAME, fnEnterFrame);
positionTimer = new Timer(50);
positionTimer.addEventListener(TimerEvent.TIMER, positionHandler);
positionTimer.start();
playPause.label = "pause";
isPlay = true;
}
private function positionHandler(e:Event):void
{
pgs.label = int(channel.position/1000) + "/" + int(soundFactory.length/1000) + "초";
pgs.setProgress(channel.position, soundFactory.length);
}
private function doPlay():void
{
if(isPlay)
{
pausePosition = channel.position;
channel.stop();
playPause.label = "play";
isPlay = false;
}
else{
channel = soundFactory.play(pausePosition);
playPause.label = "pause";
isPlay = true;
}
}
private function doStop():void
{
pausePosition = 0;
channel.stop();
playPause.label = "play";
isPlay = false;
}
private function setVolume():void
{
var transform:SoundTransform = channel.soundTransform;
transform.volume = sdVolume.value;
channel.soundTransform = transform;
}
private function setPan():void
{
var transform:SoundTransform = channel.soundTransform;
transform.pan = sdPan.value;
channel.soundTransform = transform;
}
private function changeMusic():void
{
channel.stop();
src = dg1.selectedItem.src;
playSound();
txtTitle.text = dg1.selectedItem.title;
txtArtist.text = dg1.selectedItem.artist;
}
private function fnEnterFrame(e:Event):void
{
SoundMixer.computeSpectrum(bytes, true, 1);
var g:Graphics = cv1.graphics;
g.clear();
g.lineStyle(0, 0x6600CC);
g.beginFill(0x6600CC);
g.moveTo(0, PLOT_HEIGHT);
var n:Number = 0;
for (var i:int = 0; i < CHANNEL_LENGTH; i++)
{
n = (bytes.readFloat()*PLOT_HEIGHT);
g.lineTo(i*2, PLOT_HEIGHT - n);
}
g.lineTo(CHANNEL_LENGTH*2, PLOT_HEIGHT);
g.endFill();
g.lineStyle(0, 0xCC0066);
g.beginFill(0xCC0066, 0.5);
g.moveTo(CHANNEL_LENGTH*2, PLOT_HEIGHT);
for (i = CHANNEL_LENGTH; i > 0; i--)
{
n = (bytes.readFloat()*PLOT_HEIGHT);
g.lineTo(i*2, PLOT_HEIGHT - n);
}
g.lineTo(0, PLOT_HEIGHT);
g.endFill();
}
private function ioErrorHandler(e:Event):void
{
Alert.show(e.toString());
}
]]>
</mx:Script>
<mx:HTTPService id="listRequest" url="http://shallaazm.tistory.com/attachment/ek170000000005.xml" useProxy="false"/>
<mx:Panel x="0" y="0" width="560" height="630" layout="absolute" title="MP3Player">
<mx:VBox x="0" y="0" height="100%" width="100%">
<mx:Canvas width="100%" height="300">
<mx:Label x="10" y="222" text="File Download"/>
<mx:Label x="10" y="260" text="Play Time"/>
<mx:ProgressBar x="111" y="222" width="209" source="{soundFactory}"/>
<mx:ProgressBar x="111" y="260" width="209" mode="manual" id="pgs"/>
<mx:HSlider x="328" y="246" minimum="0" maximum="1" value="0.8" toolTip="Volume"
liveDragging="true" change="setVolume()" id="sdVolume" width="196"/>
<mx:HSlider x="328" y="272" minimum="-1" maximum="1" value="0" toolTip="Pan"
liveDragging="true" change="setPan()" id="sdPan" width="196"/>
<mx:Canvas x="10" y="53" width="514" height="150" id="cv1"/>
<mx:HBox x="328" y="211" width="196" horizontalAlign="right">
<mx:Text textAlign="right" text="Greetings(Intro)" id="txtTitle"/>
<mx:Text textAlign="right" fontWeight="bold" text="S.O.F.T PJ" id="txtArtist"/>
</mx:HBox>
</mx:Canvas>
<mx:DataGrid width="100%" height="242"
dataProvider="{listRequest.lastResult.items.item}" itemClick="changeMusic()" id="dg1">
<mx:columns>
<mx:DataGridColumn headerText="Title" dataField="title"/>
<mx:DataGridColumn headerText="Artist" dataField="artist"/>
</mx:columns>
</mx:DataGrid>
</mx:VBox>
<mx:ControlBar>
<mx:HBox width="50%">
<mx:Button width="66" height="24" buttonMode="true" click="doPlay()" id="playPause"/>
<mx:Button width="66" height="24" buttonMode="true" label="Stop" click="doStop()"/>
</mx:HBox>
<mx:HBox width="50%" horizontalAlign="right">
<mx:LinkButton label="Created by Shallaa" fontSize="10"
click="navigateToURL(new URLRequest('http://shallaazm.tistory.com'));"
textDecoration="underline" alpha="0.20"/>
</mx:HBox>
</mx:ControlBar>
</mx:Panel>
</mx:Application>
=====================================================================================================
MP3List.xml==========================================================================================
<?xml version="1.0" encoding="euc-kr"?>
<items>
<item title="Greetings(Intro)" artist="S.O.F.T PJ" src="http://shallaazm.tistory.com/attachment/ek170000000001.mp3"/>
<item title="Move On" artist="S.O.F.T PJ" src="http://shallaazm.tistory.com/attachment/ek170000000002.mp3"/>
<item title="I Can Fly" artist="S.O.F.T PJ" src="http://shallaazm.tistory.com/attachment/fk170000000001.mp3"/>
<item title="죽은이에게" artist="S.O.F.T PJ" src="http://shallaazm.tistory.com/attachment/ek170000000003.mp3"/>
<item title="Everybody" artist="S.O.F.T PJ" src="http://shallaazm.tistory.com/attachment/fk170000000002.mp3"/>
<item title="Life For Me" artist="S.O.F.T PJ" src="http://shallaazm.tistory.com/attachment/gk170000000001.mp3"/>
<item title="I Love You Song" artist="S.O.F.T PJ" src="http://shallaazm.tistory.com/attachment/gk170000000002.mp3"/>
<item title="그저 그런 생각" artist="S.O.F.T PJ" src="http://shallaazm.tistory.com/attachment/ek170000000004.mp3"/>
<item title="작별인사(Outro)" artist="S.O.F.T PJ" src="http://shallaazm.tistory.com/attachment/ek170000000000.mp3"/>
</items>
=====================================================================================================
** 음원 출처 : hiphopplaya
'OM' 카테고리의 다른 글
테이블에 행을 추가/삭제하는 프로그램 (0) | 2008.04.06 |
---|---|
htmlconverter (0) | 2008.04.04 |
에디트 플러스 자바설정 (0) | 2008.03.20 |
가사가 표시되는 MP3 Player (0) | 2008.03.15 |
그림판 (0) | 2008.03.13 |
Color Balance (0) | 2008.03.13 |
컬러 팔레트를 이용한 색칠공부 (0) | 2008.02.29 |
컬러 팔레트 (0) | 2008.02.28 |
색칠공부 (4) | 2008.02.23 |