Flash Helps: AS3 (actionScript 3) Podcast Player

Here’s a little something called a AS3 Flash actionScript 3 Podcast player. This little sample uses similar Flash AS3 methods in past posts like the for loop, xml loading, and the Flash AS3 Video Player.

The thing to remember when working with data that doesn’t reside or sit on your own server, is that Flash won’t necessarily load it (see crossdomain stuff here). It will load just fine if the podcast rss file feed resides on your own server. So, a thing to remember in the sample files is that if you click on them and they load in the browser…they may not work. Download the files and test them in Flash and you’ll be fine.

In this sample I’ve used the Sound class to load the mp3 from the podcast feed. It’s easy enough to do. There are eventListeners just like in the past video player sample.

You’ll need to drag two AS3 components to the stage: the list component and the progress bar component. Give the the List component an instance name of ‘myList’ and the progress bar component an instance name of ‘pb’. You will also need a couple of dynamic text fields on the stage: myPodcast and myTitle.

Here’s the code to use:

import flash.events.Event;
import flash.media.Sound;
import flash.net.URLRequest;
import fl.controls.ProgressBar;
pb.visible = false;
myLoadingTxt.visible = false;

var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onLoaded);

myList.addEventListener(Event.CHANGE, itemChange);
var xml:XML;
function onLoaded(e:Event):void {

xml = new XML(e.target.data);
var ti:XMLList = xml.channel.title;

var il:XMLList = xml.channel.item;
var at:XMLList = xml.channel.item.enclosure;

for (var i:uint=0; i<il.length(); i++) {
myList.addItem({label:il.description.text()[i],
data:at.attribute("url")[i]});

myPodcast.htmlText = "<b>"+ti + "</b> Select an item from the list";

}
}
function itemChange(e:Event):void {
pb.visible = true
myLoadingTxt.visible = true
flash.media.SoundMixer.stopAll();
var sp:Sound = new Sound();
trace("change")
var req:URLRequest = new URLRequest(myList.selectedItem.data);
sp.load(req);
SoundMixer.bufferTime=8;
trace("sm: "+SoundMixer.bufferTime)
var dataPath:String = myList.selectedItem.data;
var loader:URLLoader = new URLLoader();
loader.load(new URLRequest(dataPath));
sp.play();
pb.source = loader;
addChild(pb);
myTitle.text = myList.selectedItem.label

}

function onPbarComplete(event:Event):void
{
pb.visible = false;
myLoadingTxt.visible = false;
}
pb.addEventListener(Event.COMPLETE,onPbarComplete);

//your podcast here:
loader.load(new URLRequest("http://www.smithmediafusion.com/podcastProxy.asp"));
You'll see there at the end that I have made a proxy page in php that loads a the rss file from the podcast provider. If you have the podcast on your site you won't need to do it like this. Just copy and paste your podcast feed into that line.


The files:

podcastPlayer.fla
podcastPlayer.swf

podcastPlayer.html

Related Posts:

  • No Related Posts

Comments are closed.