Solved

How to load dynamic playlist into SWFobject (Flash Player)?

Posted on 2008-09-29
6
6,596 Views
Last Modified: 2012-05-05
Quick question: How do I take the dynamic variables on my page, and load them into a Flash Player (SWFObject)?

Now, the long version with all the details of what I'm trying to do:


The JW Player (http://www.jeroenwijering.com/?item=JW_FLV_Media_Player) SWFobject can be included on a web page to play audio and video files. I have it working on a page, if I send a single song or a single video file to the player, and that song or video file can be dynamic. It works slick, and all is well. (So you know I have the audio files uploaded correctly, as well as the required files for the player.)

So, I want to make the jump from one audio file to several audio files, in a playlist. Kind of like a musician's site on MySpace, where they have a static list of a few audio files, however, now I want to use a dynamic playlist. I want to configure an instance of the SWFobject to play multiple audio (MP3) files. Evidently, that is not a problem if the list is static, and you write out the "playlist" as an XML file, and that file satisfies a parameter of the SWF object to load the playlist.

Since I was able to load a single audio file or a single video file dynamically, I figured, hey what the heck, it would be easy to add a dynamic playlist. That was MANY, MANY hours ago, and I'm stuck.

Maybe I'm missing a semicolon, or a single quote - it seems like I am close to getting this!

I do not want to write out a "real" XML file to my server, and then read it back to glean the data, for a number of reasons, it will cause problems. Besides, I already have the dynamic data from a database and it is already on the page! It looks like the Player is geared up and ready for an XML file to parse its data. I'm thinking that a "real" XML file, and a chunk of text that appears identical to an XML file, should both "look" the same to the Player. If that is wrong, then I need to find a way to get dynamic data to the player another way.


The first big question is:
Can send a "fake" XML stream to the player, masquerading as an XML file? I altered my code so that the fake XML string looks like this:
==================================================
<playlist version="1" xmlns="http://xspf.org/ns/0/">
<trackList>
<track>
<location>http://www.MySite.org/Gallery/DennisLeahy/Wilderness.mp3</location>
<title>1</title>
</track>

<track>
<location>http://www.MySite.org/Gallery/DennisLeahy/DTL_TooManyBushesNotEnoughTrees.mp3</location>
<title>2</title>
</track>

<track>
<location>http://www.MySite.org/Gallery/DennisLeahy/DTL_AngelinasLullabye.mp3</location>
<title>3</title>
</track>

<track>
<location>http://www.MySite.org/Gallery/DennisLeahy/Great_Spirit_(Dennis_Leahy)_EQ2.mp3</location>
<title>4</title>
</track>
</trackList>
</playlist>

==================================================

And I see that it validates as valid XSPF (at http://validator.xspf.org/)

But, when I try the following:
==================================================
<script type='text/javascript' src='Videos/swfobject.js'></script>
<div id="audiofiles">This text is replaced by the player</div>
<script type="text/javascript">
var strXSPF = '<%=strPlaylist%>';
var so = new SWFObject('Videos/player.swf','mpl','400','32','9');
so.addParam('allowscriptaccess', 'always');
so.addParam('allowfullscreen', 'false');
so.addVariable("file", strXSPF);
so.addVariable('playlist', 'bottom');
so.write('audiofiles');
</script>
==================================================
I get the player to show, but I get a 0: Error #2032 error, so I know the playlist is not loading.


If I fire the page, then view source, I see that the fake XML string looks perfect:

<script type='text/javascript' src='Videos/swfobject.js'></script>
<div id="audiofiles">File not found</div>
<script type="text/javascript">
var strXSPF = var strXSPF = '<playlist version="1" xmlns="http://xspf.org/ns/0/"><trackList><track><location>http://www.MySite.org/Gallery/DennisLeahy/Wilderness.mp3</location><title>1</title></track><track><location>http://www.MySite.org/Gallery/DennisLeahy/DTL_TooManyBushesNotEnoughTrees.mp3</location><title>2</title></track><track><location>http://www.MySite.org/Gallery/DennisLeahy/DTL_AngelinasLullabye.mp3</location><title>3</title></track><track><location>http://www.MySite.org/Gallery/DennisLeahy/Great_Spirit_(Dennis_Leahy)_EQ2.mp3</location><title>4</title></track></trackList></playlist>';
var so = new SWFObject('Videos/player.swf','mpl','400','32','9');
so.addParam('allowscriptaccess', 'always');
so.addParam('allowfullscreen', 'false');
so.addVariable("file", strXSPF);
so.addVariable('playlist', 'bottom');
so.write('audiofiles');
</script><br>

==================================================
I have tried formatting the var strXSPF string within JavaScript several ways (removed the single quote delimiters surrounding the string, as well as including or excluding parts of a real XML header, and none of that seemed to help.

So, can someone help me figure out how to load a dynamic playlist into the JW Player?

Thanks for reading all of this!!

Dennis
0
Comment
Question by:dtleahy
  • 4
  • 2
6 Comments
 
LVL 18

Accepted Solution

by:
Antonio Estrada earned 500 total points
ID: 22656830
Three points:

1. I'm not familiar with the JW Player, but for the purpose of getting a broader view, can you post the code that you use for the single file? (the one that works).

2. What happens if you write a static XML in order to test the ability of the JW Player to actually gather the data and make a working playlist?

3. Maybe JW Player's code is somehow strict and requires an XML header in order for it to show up... so why don't you add this:

<%
strPlaylist = "<?xml version=1.0 encoding=utf-8?>"
strPlaylist = strPlaylist & "all the other stuff you had there"
%>

-V
0
 
LVL 18

Expert Comment

by:Antonio Estrada
ID: 22656841
Also, you have this:

<trackList>
...
</trackList>

and it should be this:

<tracklist>
...
</tracklist>

-V
0
 
LVL 18

Expert Comment

by:Antonio Estrada
ID: 22656856
Third comment in a row...

The code below is the "example" of the JW Player, there are some differences which might be the issue...

-V
<playlist version="1" xmlns="http://xspf.org/ns/0/">

	<title>Example XSPF playlist for the JW Player</title> <!-- This doesn't exist on your file, and may be required -->

	<info>http://www.jeroenwijering.com</info> <!-- This doesn't exist either but doesn't seem that important... If I were you, I would add a blank element for that (<info />) -->

	<tracklist>
 

		<track>

			<title>Big Buck Bunny - MP3 Audio with thumb</title> <!-- Maybe all these elements are required. If you don't need them, again I'd add them as a blank element (<title />, <creator />, <info />, <annotation />, <image />) -->

			<creator>the Peach Open Movie Project</creator>

			<info>http://www.bigbuckbunny.org/</info>

			<annotation>Big Buck Bunny is a short animated film by the Blender Institute, part of the Blender Foundation. Like the foundation's previous film Elephants Dream, the film is made using free and open source software.</annotation>

			<location>http://www.jeroenwijering.com/upload/bunny.mp3</location>

			<image>http://www.jeroenwijering.com/upload/bunny.jpg</image>

		</track>
 

		<track>

			<title>Big Buck Bunny - FLV Video with captions</title>

			<creator>the Peach Open Movie Project</creator>

			<info>http://www.bigbuckbunny.org/</info>

			<annotation>Big Buck Bunny is a short animated film by the Blender Institute, part of the Blender Foundation. Like the foundation's previous film Elephants Dream, the film is made using free and open source software.</annotation>

			<location>http://www.jeroenwijering.com/upload/bunny.flv</location>

			<meta rel="captions">http://www.jeroenwijering.com/upload/bunny.xml</meta>

		</track>
 

		<track>

			<title>Big Buck Bunny - JPG Image with start</title>

			<creator>the Peach Open Movie Project</creator>

			<info>http://www.bigbuckbunny.org/</info>

			<annotation>Big Buck Bunny is a short animated film by the Blender Institute, part of the Blender Foundation. Like the foundation's previous film Elephants Dream, the film is made using free and open source software.</annotation>

			<location>http://www.jeroenwijering.com/upload/bunny.jpg</location>

			<meta rel="duration">20</meta>

			<meta rel="start">10</meta>

			<meta rel="type">image/jpeg</meta>

		</track>
 

	</tracklist>

</playlist>

Open in new window

0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:dtleahy
ID: 22781639
Vulturous, I apologize for not getting back to you. I monitored this question for a few days, and thought no one would post. I thought the subsequent emails I received were just telling me again no one had respoonded, and I deleted them without reading.

I normally do check back frequently, and do appreciate your help.

First of all, I was in the bad situation for a couple of reasons:
The puzzle has two pieces: there is a player, and there is a javascript file. There were several versions of the player code (including a major legacy release still supported), and 2 versions of the javascript file, and the code "didn't play together nice" (an understatement)

There was also an automatic configurator on-site that produced code that was incompatible with the components I had.

There were numerous code samples posted, only a few of which happened to mention which version of the 2 critical files the code would work with.

Despite the insistence that the 2 critical files, as well as the MP3 and FLV files could be located anywhere on the same site, (with a full URL), that proved not to be true. Even though I don't like keeping anything but page code on the root of the site, the player and javascript file work flawlessly if on the root, and either not at all or erratically if anywhere else.

The player code was in flux, and I happened to jump in at a bad time. Now, a few weeks later, a new point release was made, with numerous bug fixes and features added. (My code works now.)

------------------------------------------

So, I'm going to sort of answer my own question, and award points (with an asterisk), for your efforts.

No, you cannot fake the XML file on the client computer. The player will not work, and I am now pretty sure that is by design and a security measure in the player's underlying code from Adobe.

>Maybe JW Player's code is somehow strict and requires
>an XML header in order for it to show up... so why don't you add this:

<%
strPlaylist = "<?xml version=1.0 encoding=utf-8?>"
strPlaylist = strPlaylist & "all the other stuff you had there"
%>

So, yes, I need a real XML file, and yes, it needs the XML header (so I'll mark your first answer as correct, and award the points.)

(I knew I didn't want a 2-way trip to write an XML file, then retrieve the XML file. My workaround - and probably the best solution for this site - is that an XML file is automatically written at the server when a multimedia item is added to the database that feeds the playlists. So the site visitor never has to wait for an XML to be created - just retrieved.)

In your second comment above, you mention that <tracklist> is correct, but according the XSPF.org site, <trackList> is correct, and is case sensitive.

Thank you again for your valuable time! I really do appreciate it!

Dennis
0
 

Author Closing Comment

by:dtleahy
ID: 31501469
I posed a question that was just about impossible for anyone to answer - except for maybe 1 or 2 gurus at the JW Player site. That site's experts (also volunteers) gave only tiny snippets of the big picture, and I needed to see the whole. It required trial and error and trial and error.. to figure it out. Plus, waiting for stable code to be released.

But, I sure do appreciate your efforts!

Thanks,

Dennis
0
 
LVL 18

Expert Comment

by:Antonio Estrada
ID: 22799109
The important part is that you got it working, I'm glad I could be a bit helpful :). Thanks for the points!

-V
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now