0

I have this code:

echo '<embed src="'.$data['band_video_1'].'" height="300" width="453">';

to display a Youtube video.. It works fine in Google Chrome but not in Mozilla Firefox.. What is wrong here? Should I use another html element here? How to check what browser the user is using also??

Leah
  • 225
  • 2
  • 10
  • 24
  • A question similar to this has already been answered. try looking into this (http://stackoverflow.com/questions/412467/how-to-embed-youtube-videos-in-php) – Christine Austin Nov 29 '12 at 03:47
  • i quite have an idea about that but the main problem is checking the type of browser – Leah Nov 29 '12 at 04:45

2 Answers2

0

If your looking to check the browser, you could try some java script like so

<script type="text/javascript">'.
   var canPlay = false;
   var v = document.createElement('video');
   if(v.canPlayType && v.canPlayType('video/mp4').replace(/no/, '')) {
       canPlay = true;
   }

   alert(canPlay);

</script>
0

It looks like you're trying to directly embed a Flash object. The embed tag is an outdated one, which is mostly deprecated. (Explained here.) If you want a more reliable way to embed a Flash object, look into SWFObject.

However, an even better solution is to embed the video as an iframe. This way, YouTube will figure out the best way to embed the player, and you don't have to worry about browser detection. It will even use HTML5 video when necessary so it will work on iPads and other systems that don't have Flash.

The end result will look like this:

<iframe width="420" height="315" src="http://www.youtube.com/embed/U0x9HtYgVqA" frameborder="0" allowfullscreen></iframe>

So your server-side code will look more like this:

echo '<iframe width="420" height="315" src="http://www.youtube.com/embed/' . $data['band_video_1'] . '" frameborder="0" allowfullscreen></iframe>';

Just make sure band_video_1 is the YouTube video ID and not the full URL.

Community
  • 1
  • 1
brianchirls
  • 7,661
  • 1
  • 32
  • 32