player.mxml==========================================================================================
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="260" height="160" initialize="System.useCodePage=true;listRequest.send()">
<mx:Style>
Application{
backgroundColor : #ffffff;
}
</mx:Style>
<mx:Script>
<![CDATA[
import mx.rpc.events.*;
import flash.utils.*;
import mx.controls.*;
private var soundFactory:Sound;
private var channel:SoundChannel;
private var positionTimer:Timer;
private var myXML:XML;
private var words:Array;
private var src:String;
[Bindable]
private var title:String;
[Bindable]
private var artist:String;
private var pausePosition:int;
private var isPlay:Boolean;
private function listResult(e:ResultEvent):void
{
myXML = new XML(e.result);
src = myXML.item[0].@src;
title = myXML.item[0].@title;
artist = myXML.item[0].@artist;
playSound();
}
private function setWords(e:Event):void
{
words = new Array(int(soundFactory.length/1000));
for(var i:int=0; i<words.length; i++)
{
if(myXML.item.letter[i])
{
words[int(myXML.item.letter[i].@s)] = myXML.item.letter[i].@words;
}
}
positionTimer = new Timer(50);
positionTimer.addEventListener(TimerEvent.TIMER, positionHandler);
positionTimer.start();
}
private function playSound():void
{
var req:URLRequest = new URLRequest(src);
soundFactory = new Sound();
soundFactory.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
soundFactory.addEventListener(Event.COMPLETE, setWords);
soundFactory.load(req);
channel = soundFactory.play();
channel.addEventListener(Event.SOUND_COMPLETE, completeHandler);
isPlay = true;
}
private function positionHandler(e:TimerEvent):void
{
playPosition.text = int(channel.position/1000).toString();
totalTime.text = int(soundFactory.length/1000) + "sec";
if(words[int(channel.position/1000)] != null)
{
txtSong.text = words[int(channel.position/1000)];
}
}
private function doPlay():void
{
if(isPlay)
{
pausePosition = channel.position;
channel.stop();
isPlay = false;
}
else{
channel = soundFactory.play(pausePosition);
isPlay = true;
}
}
private function completeHandler(e:Event):void
{
txtSong.text = "";
playSound();
}
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 ioErrorHandler(e:Event):void
{
Alert.show(e.toString());
}
]]>
</mx:Script>
<mx:HTTPService id="listRequest" url="http://shallaazm.tistory.com/attachment/gk170000000005.xml"
resultFormat="xml" useProxy="false" result="listResult(event)"/>
<mx:Canvas x="10" y="10" width="240" height="140" borderStyle="solid">
<mx:HSlider x="83" y="116" width="145" minimum="-1" maximum="1" value="0" toolTip="Pan"
liveDragging="true" change="setPan()" id="sdPan"/>
<mx:HSlider x="83" y="96" width="145" minimum="0" maximum="1" value="0.8" toolTip="Volume"
liveDragging="true" change="setVolume()" id="sdVolume"/>
<mx:Button x="10" y="96" width="65" height="32" buttonMode="true" label="▶/P" click="doPlay()"/>
<mx:Text x="10" y="68" textAlign="center" width="218" fontSize="12" id="txtSong"/>
<mx:HBox x="83" y="42" width="145" horizontalAlign="right">
<mx:Text id="playPosition"/>
<mx:Label text="/"/>
<mx:Text id="totalTime"/>
</mx:HBox>
<mx:HBox x="10" y="10" width="218">
<mx:Text height="24" fontSize="16" fontWeight="bold" text="{title}"/>
<mx:Text height="24" fontSize="16" fontWeight="normal" text="{artist}"/>
</mx:HBox>
</mx:Canvas>
</mx:Application>
=====================================================================================================
list_words.xml========================================================================================
<?xml version="1.0" encoding="euc-kr"?>
<items>
<item title="첫눈" artist="clazziquai" src="http://shallaazm.tistory.com/attachment/gk170000000004.mp3">
<letter s="15" words="손이 시렵도록 그 하얀눈이 오던날"/>
<letter s="21" words="아름다운 그녈 만났죠"/>
<letter s="29" words="하늘을 가득 수놓았던 하얀눈"/>
<letter s="36" words="포근하게 너와 나를 안아 주었죠"/>
<letter s="43" words="녹아가는 눈을 보며"/>
<letter s="49" words="흘러간 추억을 돌이켜 보지만"/>
<letter s="57" words="이미 지난 계절만큼 아련하게"/>
<letter s="62" words="흐르는 눈물 다시는 볼 수 없을"/>
<letter s="68" words="그 첫눈"/>
</item>
</items>
=====================================================================================================
**음원 출처 : DAUM
'OM' 카테고리의 다른 글
성적 그래프 프로그램 (0) | 2008.04.07 |
---|---|
테이블에 행을 추가/삭제하는 프로그램 (0) | 2008.04.06 |
htmlconverter (0) | 2008.04.04 |
에디트 플러스 자바설정 (0) | 2008.03.20 |
MP3 플레이어 (0) | 2008.03.13 |
그림판 (0) | 2008.03.13 |
Color Balance (0) | 2008.03.13 |
컬러 팔레트를 이용한 색칠공부 (0) | 2008.02.29 |
컬러 팔레트 (0) | 2008.02.28 |