htmlfirefoxyoutubeembed

youtube video doesn't play on mozilla firefox : html embed


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??


Solution

  • 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.