Blog of the Month Chronicling the adventures of Studio of the Month.

Live from beautiful Logan Square in Chicago, this is blogofthemonth. We, the members of Studio of the Month like to poke our heads around in many things so subscribe or check back often to stay up-to-date. Read about company projects, involvement in happenings around the city and progress in learning the jedi design ways.

Another one today…

Rudy @ February 18, 2010 2:25 pm

(technically the previous one was from last night)

Its Thursday Again

Rudy @ February 18, 2010 9:14 am

Q…

The Hardcover…

Rudy @ February 17, 2010 12:03 pm

Its been awhile since I have had a hardcover copy in my possession — I left the only one I had back in Colorado as a present to my folks — but here it is again in my hands and i was able to take some photos for our website. I must say it was a thrill to have such an opportunity — and even more of a thrill to see it realized. Much thanks to Chris Mahoney at Pariah Publishing. You may also like to see more images from the hardcover here.

Firestorm Hairdos…

Rudy @ February 16, 2010 10:42 am

… or ketchup and mustard. You be the judge…

Making a randomly looping video player in AS3

Chase @ February 16, 2010 1:48 am

Occasionally a project comes along that sounds SO easy, but turns out to be a big challenge. SotM loves a good challenge so we were excited when a good friend recently came to us with just such a project. The client had a folder filled with 40+ .flv files and they needed a video player that would infinitely play these videos at random. Sounds easy enough but the challenge was making this seemless so the video came across as one never ending clip.

Our first thought was the obvious simple logic. Load and play a video, then when a video completes load and play the next video. The problem with that is the slight gap you get while the request is made for the next file. The solution logic is to have two video players stacked (fp1 and fp2). One player plays a video while the second player is hidden loading the next video. Once the visible player completes, it is hidden and begins loading the next video. Meanwhile the other player is made visible and begins playing.

This is what we will be making. Let’s have a look at the code. You can download all of our source files for this simple project here.

// set a path to video files
var path:String = "flvs/";

// generate array of file names
var fileNames:Array = ["one","two","three","four"];

First create a variable ‘path’ to the flv directory. Then create an array of all the flv file names. In our final player we load these up via php and flashVars to allow the client to simply upload videos into a directory. For this example, however, we will add the names manually in an array called fileNames.

// random whole number generator
function rand(high:Number):Number {
    return int(Math.random() * high);
}

We want the videos to load at random so next we create a very simple random whole number generator.

// assign initial video source
fp1.source = path + fileNames[rand(fileNames.length)] + ".flv";

// create event listeners
fp1.addEventListener("complete", nextVideo);
fp2.addEventListener("complete", nextVideo);

Next we setup a few things. We have 2 flvPlayback components on the stage, one named fp1 and another named fp2. We want to set the initial source of fp1 to the first video in the fileNames array. The we give both flvPlaybacks event listeners that will fire our nextVideo function on complete.

var firstPlayer = true;

A boolean variable is created to tell the player which flvPlayback is currently visible and playing. If firstPlayer is true, fp1 is playing. If firstPlayer is false, fp2 is playing.

// load next random video into open player
function nextVideo(e):void {

	// var flv is created and set to a random filename in fileNames array
	var flv = rand(fileNames.length);

	// var p (play) and l (load) are set to equal fp1 and fp2.
	var p = fp1;
	var l = fp2;

	// switch var p and l if the firstPlayer is not playing.
	if (!firstPlayer) {
		p = fp2;
		l = fp1;
	}

	// toggle firstPlayer variable
	firstPlayer = !firstPlayer;

	// set p to visible and play
	p.alpha = 1;
	p.play();

	// set l to invisible,begin loading the next video and set to stop.
	l.alpha = 0;
	l.source = path + fileNames[flv] + ".flv";
	l.stop();
}

Now for the function. It’s actually pretty simple so I think the comments should explain it pretty well.

nextVideo(null);

Finally the nextVideo function is called when the .swf first loads. We have to send an argument of null because nextVideo is expecting an event via the listeners.

What we get is a simple Flash based video player that will infinitely play videos at random. Additionally we created a play/pause button, created a check to keep files from repeating back-to-back and added functionality to load file names from a directory via php. I’m happy to explain these process, just let me know.

Of course one of the neat things about coding is there is always 5-6 ways of solving any problems. What would your solution be?

We should note that there is a bit of a concern over bandwidth with a player like this. If you have 50 videos and a user leaves the browser window open, the videos will all load. If a couple thousand people do that you could easily eat up 200-300 gigs of transfer. Be careful!

Shire Update…

Rudy @ February 15, 2010 11:26 am

Lucas has been working like crazy in order to get the Shire ready for the coming growing season. The seeds are on their way and the soil is just waiting in anticipation. During my time home for the holidays I was able to help begin the greenhouse construction — and now it has been covered and is maintaining 95 degrees. The trailer shown here will be positioned on the lower acres of the garden near the bike trail and will contain all the veggies that are for sale and pick-up.  Luke has also made a lot of connections recently with the folks he wishes to bring into his vision of the garden as a place for learning, sharing and gathering. Some events in the works include dinners to be hosted by ShireCSA, serving food grown only feet away, featuring speakers presenting on a wide range of green topics. More to come in the future…

ACK!

Rudy @ February 14, 2010 3:33 pm

I missed a couple of days — my deepest and robust apologies. But here we are — back again. I can’t remember the last time i drew a superhero — but i recently ran into a friend from SCAD and his work inspired me in this super way. I encourage all to take a look at his work — he’s pretty much a badass: Robert Grabe.

Its Thursday…

Rudy @ February 11, 2010 11:13 am

Boris Pasternak

Rudy @ February 10, 2010 11:47 am

Thanks for Zhivago… On a side note — scanner went wonky — but i liked it.

Not sure why…

Rudy @ February 9, 2010 5:43 pm

…but this just happened in the studio today. I blame Chase.