开发者

How to combine javascript Souncloud player and flash visualization

I have set up a nice Flash audio visualization which can load an audio file and play it and display a spectrum of flashing coloured bars in time to the music. I don't want to have to list and control the playback of songs from with in the swf though. I wold prefer to have the songs listed in the HTML of the page, preferably in a non-flash format. I am hosting my audio on Soundcloud and have found their javascript player, which suits my purposes nicely. Now how could I integrate these two things?

It seems that either I would need a way to pipe the audio that is produced by the javascript player into the swf, if that is even possible, or else mute the sound in one of the two locations (preferably the js so that the vis is optimally in sync) and pass all play/stop/seek commands from the js player to the flash vis. Is this going to be too difficult to even bother with?

Update: Let me be more specific. Assuming that the "piping audio into the swf" approach couldn't work, I will need to pass many different messages between swf and js. I understand how to start the swf audio from js I think. Would somebody be able to demonstrate how to do the f开发者_JAVA百科ollowing?

  • signal from flash back to js that the audio has started
  • signal from flash to js the current time of the audio
  • pause or stop the flash audio from js

You can assume the following code is present:

var url:String = "mysong.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(33000);
  song.addEventListener(Event.SOUND_COMPLETE, soundCompleteHandler);   
  s.removeEventListener( Event.COMPLETE, onLoadComplete );
}  

function soundCompleteHandler(event:Event):void 
{    
   song.removeEventListener( Event.SOUND_COMPLETE, soundCompleteHandler );
}

I don't understand the strange separation between the Sound class and the SoundChannel class and why different methods seem to be scattered between them.


Wow! Thanks to some awesome Adobe voodoo my flash audio visualizer is actually picking up audio that is played on the same webpage automatically! I assume it has to do with the fact that I am using SoundMixer.computeSpectrum(). I didn't even understand how that works but apparently it can see outside flash itself to whatever audio is playing in the browser window. So I don't have to worry about "piping audio into flash" or passing functions between the swf and javascript at all!

Usually programming endeavors require getting all sorts of variables to just right for anything to work at all. How awesome is it when everything works without even trying!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜