SpacePyro Posted June 12, 2010 Share Posted June 12, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/204602-embed-youtube-links/ Share on other sites More sharing options...
fivestringsurf Posted June 13, 2010 Share Posted June 13, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/204602-embed-youtube-links/#findComment-1071306 Share on other sites More sharing options...
SpacePyro Posted June 13, 2010 Author Share Posted June 13, 2010 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. :\ Quote Link to comment https://forums.phpfreaks.com/topic/204602-embed-youtube-links/#findComment-1071310 Share on other sites More sharing options...
fivestringsurf Posted June 13, 2010 Share Posted June 13, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/204602-embed-youtube-links/#findComment-1071326 Share on other sites More sharing options...
SpacePyro Posted June 13, 2010 Author Share Posted June 13, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/204602-embed-youtube-links/#findComment-1071354 Share on other sites More sharing options...
kenrbnsn Posted June 13, 2010 Share Posted June 13, 2010 How do you use the returned string? Ken Quote Link to comment https://forums.phpfreaks.com/topic/204602-embed-youtube-links/#findComment-1071355 Share on other sites More sharing options...
SpacePyro Posted June 13, 2010 Author Share Posted June 13, 2010 The returned string just gets sent to another variable, $embed_code. So basically I have it set up as this: $embed_code = determine_video_host($videoType, $link); Quote Link to comment https://forums.phpfreaks.com/topic/204602-embed-youtube-links/#findComment-1071359 Share on other sites More sharing options...
kenrbnsn Posted June 13, 2010 Share Posted June 13, 2010 What do you do with the variable $embed_code? Ken Quote Link to comment https://forums.phpfreaks.com/topic/204602-embed-youtube-links/#findComment-1071361 Share on other sites More sharing options...
fivestringsurf Posted June 13, 2010 Share Posted June 13, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/204602-embed-youtube-links/#findComment-1071405 Share on other sites More sharing options...
SpacePyro Posted June 13, 2010 Author Share Posted June 13, 2010 Ah, I can't believe I didn't see that. This entire time I've been missing out on the whole "watch?" parameter. I feel pretty stupid now. :-\ Thanks again though, I'm sure this fix will work. Quote Link to comment https://forums.phpfreaks.com/topic/204602-embed-youtube-links/#findComment-1071440 Share on other sites More sharing options...
fivestringsurf Posted June 13, 2010 Share Posted June 13, 2010 we all do it....if it all works don't forget to click solved to end this post. Quote Link to comment https://forums.phpfreaks.com/topic/204602-embed-youtube-links/#findComment-1071493 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.