I’ve finally got my head around getting Quicktime to read XML files!
This has been a long and frustrating process as for a while any mention of XML would cause LiveStage Pro to unexpectedly quit. I’m still not sure what was going wrong there but I think the key to making everything work smoothly was using lots of strings to remember the paths to different information stored in the XML.
Here it is:
This movie, consists of a number of text tracks which, upon loading, read the content from this xml file and associate it with the track named “URL”.
TrackNamed(”URL”).SetListFromURL(”http://dpwolf.net/blog/sites.xml”, “”)
The content of the XML file is a series of website names and links formatted as such:
When you press the ‘Randomise’ button an entry is randomly chosen based on the number of entries in the XML file. A variable “ran”, is used to generate a random number between 1 and the number of elements in the file.
ran = Random(1, TrackNamed(”URL”).GetListElementCount(”"))
The appropriate information is copied into the ‘Name’ and ‘URL’ tracks. This is where the strings come in. I have used the string name “ListNamepath” to refer to the element which is to be randomly chosen and the string name “ListName” to hold the actual name of the site, as stored in the XML file.
LiveStage Pro addresses the information stored in an XML file in a somewhat similar manner to a URL except that instead of using “/” (slashes) it uses “.” (full stops). Thus the name of the site in the first element of my XML file is “Site[1].SiteName”. The random number is used to select the entry, ie. it is the number in the square brackets. To add the the “.SiteName” path to the end of the address a “strconcat” is used to combine the two strings.
SetString(ListNamepath, strconcat(TrackNamed(”URL”).GetListElementPath(”", ran), “.SiteName”))
Now that the path to the information has been defined and stored as “ListNamepath” it may be accessed and its content copied to the “ListName” string.
SetString(ListName, TrackNamed(”URL”).GetListElementValue(ListNamepath))
Finally, this string can be inserted into the text track.
TrackNamed(”Name”).ReplaceText(ListName, 0, TrackNamed(”Name”).GetTextLength)
The same process applies to the URL information, which is sent to the “URL” text track.
Since the content (the information in the XML file) and the structure (the Quicktime movie) are separate I can update the list of links on the server and the movie will always be up to date. With a lot more work a blog style content management system could be developed using these basic methods.
The LiveStage Pro source files can be found here.
Something about this (Randomise) crashes my Firefox instantly. I’ve had other experiences that suggest QT and Firefox 0.8 don’t play well together.
Thanks for the comment Justin. I tried it out in Firefox 0.8 and couldn’t get it to crash. I do have problems with Quicktime in Firefox quite often though, so I have gone back to using Safari primarily.