Wowza Community

Example of how to use ComputeSpectrum with Wowza Pro

Here is an example of how to use ComputeSpectrum with Wowza Pro. This example requires that the FastPlayVideoStreaming example be installed. Once this example is installed, edit the file [install-dir]/conf/fastplay/Application.xml and change the Client/Access/StreamAudioSampleAccess to *.

The basic ActionScript 3.0 code looks like this:

var nc:NetConnection;
var ns:NetStream;
var serverUrl:String = "rtmp://localhost/fastplay";
function ncOnStatus(infoObject:NetStatusEvent)
{
	trace("ncOnStatus: "+infoObject.info.code);
	if (infoObject.info.code == "NetConnection.Connect.Success")
	{
		doPlay();
	}
}
function doConnect()
{
	nc = new NetConnection();
	nc.addEventListener(NetStatusEvent.NET_STATUS, ncOnStatus);
	var ncClientObj:Object = new Object();
	nc.client = ncClientObj;
	
	
	trace("connect: "+serverUrl);
	nc.connect(serverUrl);
}
function nsOnStatus(infoObject:NetStatusEvent)
{
	trace("nsOnStatus: "+infoObject.info.code);
	if (infoObject.info.code == "NetStream.Play.Start")
	{
		setInterval(doCompute, 500);
	}
}
function doPlay()
{
	ns = new NetStream(nc);
	ns.addEventListener(NetStatusEvent.NET_STATUS, nsOnStatus);
	var nsClientObj:Object = new Object();
	ns.client = nsClientObj;
	
	nsClientObj.onPlayStatus = function(infoObject:Object)
	{
		trace("onPlayStatus: "+infoObject.info.code);
	}
	ns.bufferTime = 3;
	ns.play("Extremists");
}
function doCompute()
{
	trace("doCompute: ");
	var spectrum : ByteArray = new ByteArray();
	SoundMixer.computeSpectrum(spectrum, true);
	
	var spectrumStr:String = "";
	var index:Number = 0;
	
	var channelOffset:Number = 0;
	for(var i=0;i<2;i++)
	{
		if (i == 0)
			spectrumStr += "Left\n";
		else
			spectrumStr += "Right\n";
		
		for(var j=0;j<16;j++)
		{
			var line:String = "";
			for(var k=0;k<16;k++)
			{
				if (line.length > 0)
					line += " ";
					
				var currVal:Number = spectrum.readFloat();
				line += ""+currVal;
								
				index++;
			}
			
			spectrumStr += line + "\n";
		}
	}
	
	trace(spectrumStr);
}
doConnect();

Here a link to a working example:

ComputeSpectrum.zip

Charlie

Hey charlie,

first of all if this example really works I’m one damn lucky guy :slight_smile:

But I do have a problem when running it.

Stream starts to play and all, but this error keeps coming up every time the computeSpectrum function is called:

SecurityError: Error #2135: Security sandbox violation: file:///Macintosh%20HD/Users/…/Desktop/ComputeSpectrum/client/computespectrum.swf cant access rtmp://localhost/fastplay. RTMP-contents cant be accessed with this API.

The [install-dir]/conf/fastplay/Application.xml is edited to StreamAudioSampleAccess * and StreamVideoSampleAccess * … so I dont get where the error is coming from.

I’m gladful for any help. Regards, Hannes

Are you running Flash player 9.x or 10.x. I know this feature does not work 100% in Flash player 9.x.

Charlie

#######

Update: crossdomain.xml doesn’t help with this problem. You have to edit these two lines in the application’s Application.xml:

<StreamAudioSampleAccess></StreamAudioSampleAccess>
<StreamVideoSampleAccess></StreamVideoSampleAccess>

Change to:

<StreamAudioSampleAccess>*</StreamAudioSampleAccess>
<StreamVideoSampleAccess>*</StreamVideoSampleAccess>

Don’t bother with crossdomain.xml

#######

Richard

If the problem was sandbox/security error it should fix it too.

Richard

That crossdomain.xml file looks very restrictive. Try one that is permissive to see if that is the problem, then you can work on making it restrictive again as required.

Richard

I tried too, but I think this only works for video on demand, a Wowza application with stream type “default” and static files.

Richard

Actually, I’m wrong about that. It does work with shoutcast and live. You just have to set a bufferTime on the netstream, in the doPlay() function:

function doPlay()
{
	ns = new NetStream(nc);
	ns.bufferTime = 3; // add this

Richard

Hi,

I just tested few minutes ago this ComputeSpectrum and it’s work fine with fastplay and flv file. A very interresting functionnality.

But I need to have this ComputeSpectrum with LiveVideoStreaming and shoutcast in place of FastPlayVideoStreaming. The problem is that I made the same modification to those application.xml for live and shoutcast. And for both of them, it doesn’t seems to send any informations about audiosample to the player.

There is any way to make this example work for anything else than FastPlay?

Thanks a lot, we just try it and it seems that setting a buffer during the flash connection resolve the problem.

Alright, you might delete my posts … figured it was a cross domain problem. Ran the flash direct out of Flash Develop Environment, so it was rooted locally and the stream was on the server … through the browser it works just fine.

Thanks anyway. Hannes

Hello, I have exactly the same problem with cross-domain.xml? How exactly did you fix it ? The exact error is:

[HTML]SecurityError: Error #2123: Security sandbox violation: SoundMixer.computeSpectrum: file:///Macintosh%20HD/Applications/MAMP/htdocs/ComputeSpectrum/client/computespectrum.swf cannot access rtmp://localhost/fastplay. No policy files granted access.[/HTML]

It worked like a charm. Thank you for the prompt reply, Richard. Do you think that this method could be applied on an audio player streaming from Wowza ?

Hello again. I managed to get it running but when I publish it only ComputeSpectrum for Netstream objects works through my webserver. And someone tries to access it accross the network none of the equalizers work(Sound and NetStream). What do you think that the problem could be ? My cross-domain policy file now looks like this:

I am permitting the host “192.168.2.15” to stream from me and it streams but the equalizer just does not appear(although it appears when I compile the movie in Flash CS4).

I have placed the files in wowzamediaserverpro root directory in the “conf” directory and in the “shoutcast” directory which I am trying to stream from.

I really don’t know how to get this fixed and I am looking for some assistance. It looks like the problem is still with cross-domain-policy, although it works fine when I compile it.

Also I have put this line for System.security in my mainline:

Security.allowDomain(“localhost”);

I changed the file but it is the same again. I repeated the process in the following steps:

  1. I republished my movie.

  2. The equalizer for both NetStream and Sound objects were working properly when I compiled the movie. I also ran the html in firefox and they were working properly again.

  3. I started my webserver and uploaded the files to the www root.

And the result is that only the equalizer for NetStream objects is visualized. For the sound object it is not visualizing at all.

I am really running out of ideas and the strangest thing is that it is working properly when it is compiled and from the browser, but when I put it on the server NetStream computeSpectrum is visualized.

@charlie:

I compiled the movie in Flash CS4 with flashplayer 10 and it is still the same story. I noticed that the equalizer still works only with netstream which is permitted in the cross-domain.xml.

If anyone has any suggestions for workaround, please let me know. I am bumping my head against a very solid brick wall.