Jump to content

Recommended Posts

Hey guys,

 

It's been frustrating me for a bit, and I'm not sure what I've been doing wrong.  I'm sure it is probably a really small mistake that I'm overlooking.  What I'm trying to do is make a video uploader for my site.  A user fills out a form, creating the title, description, where they got the video from (e.g. YouTube) and the direct link of the video.  I have a small function that checks the video source, and depending on that source, will send out a different embed code for that video.

 

So for example, if I were trying to embed this link: http://www.youtube.com/watch?v=LsH-XXSZ2ys

 

It would run through my function called determine_video_host.  It takes two arguments, the video source (in this case, YouTube) and the link.  It runs through some conditional statements to find the correct video source.

 

So for the YouTube source, this is what I have:

 

<?php
function determine_video_host($videoType, $link){
... //other video type code here
if($videoType == "YouTube"){
		return "<object width='425' height='344'><param name='movie' value='".$link."'></param>
<param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param>
<embed src='".$link."' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='425' height='344'>
</embed></object>";
}
... //more video code
}
?>

 

When I try this, I see a white box with the given dimensions.  It's interesting to note that if I take the original embed code from YouTube and only modify the first $link, it still works.  I'm probably making a really novice mistake somewhere, but anyone care to shed some light?

 

Thanks again!

Link to comment
https://forums.phpfreaks.com/topic/204602-embed-youtube-links/
Share on other sites

i've done something similar to this in the past...the link you see at the top of the you tube page, in the address bar is not the link you can use to embed the video (maybe you already know this?)

 

you can get the get the embed code from the video while on the regular youtube channel...it sits below the video.  and the src part of it looks something like this:

 

 

you'll notice if you put that in the browser it will just play a full screen video(firefox) or prompt you to download/open the file (explorer) which is precisley what you want when embedding the video...a link to the actual video file.

Link to comment
https://forums.phpfreaks.com/topic/204602-embed-youtube-links/#findComment-1071306
Share on other sites

Hmm, I see.  Well that's weird, because when I check the embed code, I get this:

 

<object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/LsH-XXSZ2ys&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src="http://www.youtube.com/v/LsH-XXSZ2ys&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385">
</embed></object>

 

So I figured I could just take the original video link and paste it accordingly.  I even included the &hl=en_US&fs=1& stuff at the end, but still no avail. :\

Link to comment
https://forums.phpfreaks.com/topic/204602-embed-youtube-links/#findComment-1071310
Share on other sites

This code you pasted:

<object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/LsH-XXSZ2ys&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/LsH-XXSZ2ys&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object>

 

...works fine, i just tested it. 

So at this point I'm not sure what troubles you are having?

Link to comment
https://forums.phpfreaks.com/topic/204602-embed-youtube-links/#findComment-1071326
Share on other sites

Well, it does work in its raw format.  But what I'm trying to do is generate the embed code through php given a youtube link.  That is to say, if I had the same link, http://www.youtube.com/watch?v=LsH-XXSZ2ys, and I assigned it to $link as such:

 

$link = "http://www.youtube.com/watch?v=LsH-XXSZ2ys";

 

Then when I pass it through a function, I want it to return

 

	

return "<object width='425' height='344'><param name='movie' value='".$link."&hl=en_US&fs=1&'></param>
<param name='allowFullScreen' value='true'></param><param name='allowscriptaccess' value='always'></param>
<embed src='".$link."&hl=en_US&fs=1&' type='application/x-shockwave-flash' allowscriptaccess='always' allowfullscreen='true' width='425' height='344'>
</embed></object>";

 

where $link is concatenated inside the embed code.  It doesn't seem to show the movie at all.

 

 

Link to comment
https://forums.phpfreaks.com/topic/204602-embed-youtube-links/#findComment-1071354
Share on other sites

again, the two paths are different...look closely at them:

 

http://www.youtube.com/watch?v=LsH-XXSZ2ys (won't work)

is not the same as

http://www.youtube.com/watch?v=LsH-XXSZ2ys&hl=en_US&fs=1& (will work)

 

what ever you are doing with your code, processing, combining strings, altering strings whatever...the src part of the embed code needs to look like the second path i posted.  look closely at your html source code and make sure this is the case.

Link to comment
https://forums.phpfreaks.com/topic/204602-embed-youtube-links/#findComment-1071405
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.