Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Play Audio Once with Cookie
Old 01-28-2008, 05:41 PM Play Audio Once with Cookie
Novice Talker

Posts: 7
Name: David Hodgson
Trades: 0
Hi Guys and Gals...

I have just started to learn the delights of PHP and implemented some code on a site I am building.

The code is basically a cookie that lets an audio file play once per visitor session.

The coding I have used displays the media player controls on the home page and plays the file automatically, if a viewer navigates away from the page and then returns the file is not played again. The cookie clears when the browser is closed.

The problem I have with the code is when the viewer returns to the home page, the media player controls have dissapeared however I would like them to be on the screen to give the viewer the option to listen to the file again.

Here is the code I have used

<?php setcookie("firsttime","no") ?>

<?php
$firsttime = $_COOKIE[firsttime];
if (@$firsttime != "no") {echo"<embed src='Infinity Group - Work Smarter - New Financial Year (30s).mp3' width='325' height='32' />"; }
?>

the first entry is at the very top of the page and the second is where I want the media controls to appear.

If anyone has any suggestions I would greatly appreciate some help.

Regards

David
dhodgson1980 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-29-2008, 02:10 AM Re: Play Audio Once with Cookie
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
I don't understand what is your problem. If a cookie is not set you output the code to embed the mp3, if a cookie is set, you do not. Your code is correct and working.

If you need to embed the file every time but autoplay it only on first load then you should change your code to something like following:
PHP Code:
<embed blah="blah" blah <?= $firsttime == "no" "noautoplay" ""?> />
Find the correct attribute to prevent autoplay yourself, I don't know how it looks and obviously it is not a php issue.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 01-29-2008, 04:21 AM Re: Play Audio Once with Cookie
Novice Talker

Posts: 7
Name: David Hodgson
Trades: 0
Hi,

I am quite new with PHP and cookies, so not sure what I should be looking for.

If you take a look at our site http://www.infinityb2b.co.uk you will see that the sound file will play (this is what I want to happen), if you navigate to another page in the site and then back to the home page you will notice that the sound does not play (this is what I want to happen) and the embedded player does not display (I dont want this to happen).

I need the player to display giving the viewer the option to play the sound file again if they want to.

Any thoughts?
dhodgson1980 is offline
Reply With Quote
View Public Profile
 
Old 01-29-2008, 08:07 AM Re: Play Audio Once with Cookie
Skilled Talker

Posts: 94
Trades: 0
It depends on flash version you are using if you can set the it to pause on load. The best method would be to create another SWF and make it so that file does not auto play. So you final code may look like this.

PHP Code:
if ($_COOKIE['firsttime'] == 'no'
$SRC 'Infinity Group - Work Smarter - New Financial Year (30s).mp3';
else
$SRC 'Infinity Group - Work Smarter - New Financial Year (30s)-NoAuto.mp3';

echo 
'<embed src="'.$SRC.'" width="325" height="32" />'
__________________
Sell Templates? Try our
Please login or register to view this content. Registration is FREE
! See a live
Please login or register to view this content. Registration is FREE
ChadR is offline
Reply With Quote
View Public Profile
 
Old 01-29-2008, 08:17 AM Re: Play Audio Once with Cookie
Novice Talker

Posts: 7
Name: David Hodgson
Trades: 0
The media controls are not flash, they are the MS Media Player plugin applet.

Will the code you have provided still work?

Thanks
dhodgson1980 is offline
Reply With Quote
View Public Profile
 
Old 01-29-2008, 08:23 AM Re: Play Audio Once with Cookie
Skilled Talker

Posts: 94
Trades: 0
http://msdn2.microsoft.com/en-us/lib...commands__embi

For Windows Media Player you would do something like this.

PHP Code:
if ($_COOKIE['firsttime'] == 'no')
$AutoPlay '<PARAM NAME="AutoStart" VALUE="False">';
else
$AutoPlay '<PARAM NAME="AutoStart" VALUE="True">';

//Then do
echo $AutoPlay;
echo 
"<embed src='Infinity Group - Work Smarter - New Financial Year (30s).mp3' width='325' height='32' />"
__________________
Sell Templates? Try our
Please login or register to view this content. Registration is FREE
! See a live
Please login or register to view this content. Registration is FREE
ChadR is offline
Reply With Quote
View Public Profile
 
Old 01-29-2008, 09:30 AM Re: Play Audio Once with Cookie
Novice Talker

Posts: 7
Name: David Hodgson
Trades: 0
Thanks I'll give that a go and let you know how I get on with it.
dhodgson1980 is offline
Reply With Quote
View Public Profile
 
Old 01-29-2008, 10:06 AM Re: Play Audio Once with Cookie
Novice Talker

Posts: 7
Name: David Hodgson
Trades: 0
Hi,

I have just tried that and it did not work, code used...

<?php setcookie("firsttime","no") ?>

<?php
if ($_COOKIE['firsttime'] == 'no')
$AutoPlay = '<PARAM NAME="AutoStart" VALUE="False">';
else
$AutoPlay = '<PARAM NAME="AutoStart" VALUE="True">';
//Then do
echo $AutoPlay;
echo "<embed src='Infinity Group - Work Smarter - New Financial Year (30s).mp3' width='325' height='32' />";
?>

Any other suggestions or did I do something wrong with the code?
dhodgson1980 is offline
Reply With Quote
View Public Profile
 
Old 02-05-2008, 11:42 PM Re: Play Audio Once with Cookie
Extreme Talker

Posts: 238
Location: United States
Trades: 0
I think your question is more HTML-related than PHP. If you want the controls to show, then you probably need add a parameter or an attribute to your embed tag.

It's also important to note that the HTML you are using will default to Windows Media Player in IE, but in Firefox it will default to Apple Quicktime. WMP and Quicktime have different parameters for showing the controls. WMP uses "ShowControls" and Quicktime uses "controller". For this reason, it may be best to choose one of the players and make it use the same plugin for all browsers. Ideally, you wouldn't use the embed tag at all, since it is not standard, but it's currently the most widely supported tag. The more proper <object> element is not fully supported by IE6 if I remember correctly.

The website below gives examples on how to embed audio specifically for WMP, Quicktime, or RealPlayer.
http://casweb.okstate.edu/index.php?...118&Itemid=200
frost is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Play Audio Once with Cookie
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.28765 seconds with 12 queries