2011-09-13 6 views
0

다음 AS3 코드로 인해 오디오가 여러 번 재생되는 경우가 있습니다. 그것은 일반적으로 그 URL로 잘 작동하지만 내가 https://soundcloud.com URL을 사용할 때 항상 괴물. 드문 경우이지만 로컬 파일에서도 문제가 발생했다고 생각합니다. 나는이 코드를 다른 곳에서 복사 했으므로 완전히 이해하지 못했다. 이 구현에 문제가 있거나 플래시가 미친 것입니까?플래시의 오디오 스트리밍이 여러 번 재생 중입니다.

var url:String = "http://md9.ca/portfolio/music/seaforth.mp3"; 

var request:URLRequest = new URLRequest(url); 
var s:Sound = new Sound(); 
s.addEventListener(Event.COMPLETE, completeHandler); 
s.load(request); var song:SoundChannel = s.play(); 
song.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler); 


var time:Timer = new Timer(20); 
time.start(); 

function completeHandler(event:Event):void {  
    event.target.play(); 
} 

function soundCompleteHandler(event:Event):void { 
    time.stop(); 
} 

답변

2

당신은 Sound 개체를 두 번 play()을 요구하고있다. 한 번 변수 song을 만들 때 파일로드가 완료되면 다시로드하십시오.

코드를 다르게 구조 할 수 있습니다.

var url:String = "http://md9.ca/portfolio/music/seaforth.mp3"; 

var song:SoundChannel; 
var request:URLRequest = new URLRequest(url); 
var s:Sound = new Sound(); 
s.addEventListener(Event.COMPLETE, onLoadComplete); 
s.load(request); 

function onLoadComplete(event:Event):void 
{  
    song = s.play(); 
    song.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler); 
    s.removeEventListener(Event.COMPLETE, onLoadComplete); 
} 

function soundCompleteHandler(event:Event):void 
{ 
    trace('sound is complete'); 
    song.removeEventListener(Event.SOUND_COMPLETE, soundCompleteHandler); 
} 

기능을 수행하지 않았으므로 Timer 코드를 삭제했습니다.

+0

감사합니다. 완벽한 작품입니다. 나는 놀이가 두 번 벌어지는 것을 보았어야했다. – Moss