I am trying to create an audio that only uses the first entry in an xml file. I have most of the things working but I keep getting an error related to the audio file.
TypeError: Error #1034: Type Coercion failed: cannot convert “http://rivervalleychurch.net/sermonaudio/Podcast/06_Jesus_Save_Your_Church_First_Love.mp3” to flash.net.URLRequest.
at latestMessage_fla::MainTimeline/frame1()
I inserted the url for the file into error message so you can see if there is s problem with that. I was initially trying to use a variable to hold the url for me, because this xml file gets updated every week and I only want to access the most recent entry.
This is my first attempt at making an audio player in flash, so I am sure I have made a simple mistake, but for the life of me I cannot figure out what it is.
Here is the code I have so far: (Please Try not to Laugh, at least not out loud)
[INDENT]//Load the podcast.xml File
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
var audioFile:String;
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest(“http://www.rivervalleychurch.net/sermonaudio/Podcast/podcast.xml”));
function LoadXML(e:Event):void {
xmlData = new XML(e.target.data);
ParseBooks(xmlData);
}
//Load text into text fields
function ParseBooks(podcastInput:XML):void {
description_txt.text = (podcastInput.channel.item.description.text()[0]);
title_txt.text = (podcastInput.channel.item.title.text()[0]);
publish_txt.text = (podcastInput.channel.item.pubDate.text()[0]);
audioFile = (podcastInput.channel.item.link.text()[0]);
//trace (audioFile);
}
//Audio Player Controls and Stuff
var req:URLRequest = URLRequest(“audioFile”);
var sound:Sound = new Sound();
var controller:SoundChannel;
function soundLoaded(event:Event):void
{
controller = sound.play();
controller.stop();
play_btn.addEventListener(MouseEvent.CLICK, playSound);
pause_btn.addEventListener(MouseEvent.CLICK, stopSound);
}
function playSound(event:MouseEvent):void
{
controller = sound.play();
}
function stopSound(event:MouseEvent):void
{
controller.stop();
}
sound.addEventListener(Event.COMPLETE, soundLoaded);
sound.load(req);
//Event Listeners For buttons
itunes_btn.addEventListener(MouseEvent.CLICK, goItunes);
archives_btn.addEventListener(MouseEvent.CLICK, goArchives);
rss_btn.addEventListener(MouseEvent.CLICK, goRss);
//Functions For Buttons
function goItunes(e:MouseEvent):void{
navigateToURL(new URLRequest(“http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewPodcast?id=262248424”));
}
function goArchives(e:MouseEvent):void{
navigateToURL(new URLRequest(“http://www.rivervalleychurch.net/index.php?option=com_content&view=category&layout=blog&id=37&Itemid=91”));
}
function goRss(e:MouseEvent):void{
navigateToURL(new URLRequest(“http://www.rivervalleychurch.net/sermonaudio/Podcast/podcast.xml”));
}
[/INDENT]
One last question is in regards to using id3 tags versus xml tags to fill dynamic text fields in the player. Currently I am using the xml file to do this, are there any advantages one way or the other for this. The only reason I ask is that I am hoping to display an “album art” image from the id3 tag in the player. Would it be better to grab all of the information from the mp3 file?