Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem using XAJAX+PHP+JS+FLASH Component

Status
Not open for further replies.

southbeach

Programmer
Jan 22, 2008
879
US
Here is what I want to get done


except that it should be inside a layer container placed there via AJAX (I use XAJAX). For the life of me, no matter what I try, I cannot get the MP3 player to appear.

If you look at the code for the above link, you should find this block of code
Code:
<div id="trackID0">Play it!</div>
<script type="text/javascript">
var so = new playonetrack("playonetrack.swf", "mymovie", "75", "30", "7", "#FFFFFF");
so.addVariable("autoPlay", "no");
so.addVariable("overColor","#660000");
so.addVariable("playerSkin","5")
so.addVariable("soundPath", "./media/soundtrack/song.mp3");
so.write("trackID0");
</script>
You can learn more about this mp3 player here

I have tried everything I can think of and I just cannot get this thing to work via AJAX. I have tried writing the html code to disk and then loading the file back using include().

My most recent failed attempt is this
Code:
			case 'LZTRACKS':
				$content = getResolved(APPINCLUDE.'lztracks.php');
				$track = new track; 
				$tracklist = $track->listtracks(); $tempfile=uniqid('').'.htm';
				$fopen=fopen($tempfile,"a+");
				$fwrite=fwrite($fopen, $tracklist); $fclose=fclose($fopen);
				$thelist = getResolved($tempfile); @unlink($tempfile);
				//include($tempfile); echo $tempfile; @unlink($tempfile);

				$objResponse = new xajaxResponse();
				$objResponse->assign("content","innerHTML",$content);
				$objResponse->assign("tracklist","innerHTML",$thelist);
				$objResponse->assign("dumb","value",$thelist);
				$sql = 'SELECT * FROM `lzsoundtrack` WHERE 1;';
				$query=getQuery($sql); 
				while($row = mysql_fetch_assoc($query)) {
				$objResponse->script('
					<script type="text/javascript">
					   var so = new swfobject("playonetrack.swf", "track'.$row['id'].'", "75", "30", "7", "#FFFFFF");
					   so.addVariable("autoPlay", "no");
					   so.addVariable("overColor","#660000")
					   so.addVariable("soundPath", "./'.$row['trackfile'].'");
					   so.write("trackID'.$row['id'].'");
					</script>');
				}
				return $objResponse;
				break;
I get everything I want on the page except for the mp3 player next to the document to allow visitors listen to our sound tracks.

You may notice that I have resolved to looping through my sound track table to to push the required JS code to load the player on each of the set containers (trackID[NNNN]).

The UDF getResolved is simply this
Code:
function getResolved($page) {
	ob_start();
	include $page;
	$content = ob_get_contents();
	ob_end_clean();
	return ($content);
}
It is my way of never having to remember something I learned here (thanks to jpadie!).

It is almost as if the object playonetrack.js is not loaded but it is ...

Please excuse the long post but I figure you may need as much information as possible to help with this one.

Thank you all in advance for your assistance!


--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
the current behaviour, so far as i can see, is that the flash player for each row is 'GET' by the main page on each refresh/load. so you are performing R GET requests for each page load (where R is the number of table Rows filled with data rather than headings).

so if i have correctly understood your question, you want to replace these get requests with javascript hooks that, when clicked, deliver the music in the flash player. Is that correct?
 
by the way, there is something in that script that is murdering system resources in both FF and Safari. perhaps another script might be more browser friendly.
 
That is correct. The js object playonetrack() will setup the hook using a flash movie. The movie in turn, will load the track and provide the UI to play the track as shown on the page
Which script is killing system resources?
The snippet I posted above or link to test.php?
How do you measure this? I use YSlow ...



--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
Came across a flash component which does exactly what I am looking for and it loads just fine ...


I do not use wordpress but having found this article


I was lead to me to the solution.

Thanks!


--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
the page you directed us to sent my browser consumption of system resources up to about 110% (on a dual core). normal resource usage for ordinary browsing is about 15% across all apps.
 
Could it be that this is due to the number of objects loaded (the mp3 player that is)?

I am working on a different version where the player itself is not loaded until user clicks on PLAY image.

How do you measure this? Is it a plug in or an OS based utility?

Thanks


--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
it is an OS based utility.

i did not spend time analysing where the problem arose. only that it was present in both browsers that i habitually use and that it was restricted to your page.
 
Thanks jpadie!

I have changed my approach and instead of showing a flash movie object for each sound track on the page, I am showing a button which will open the mp3 player upon request.

This should ease the load and have only one flash node open at a time.

I might put this new page online late and send you a link for your review and advise ...

Regards,


--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
that seems like a better approach, yes. happy to look at it but i know virtually nothing about js and flash.
 
Not to look at it in that sense, but to see if going about this way reduces the resource load.

--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top