I have done a script that displays only an image of a the video when the user uploads one. The thing is that i want the video to start when the users clicks on the image but now when the user clicks the video appears with no autoplay.

here is the code

<div class="img_container"> <a href="#." id="video_thumb_<?php echo $id;?>" style="display:block;" 
    onClick="javascript:loadVideo(\'<?php echo $id;?>\')"> <img src='<?php echo $my_thumb;?>' class="imgpreview" /> </a> <div style="display:none;" 
        id="video_<?php echo $id;?>"?autoplay="1"></div>';




 <script>
    function loadVideo(input){
        document.getElementById("video_thumb_"+input).style.display="none";
        document.getElementById("video_"+input).style.display="block";
    }
</script> 

ok i got it...

<iframe class="new" width="'.$w.'" height="'.$h.'" src="'.$this->data["iframe"].'?autoplay=1" frameborder="0" allowfullscreen></iframe>

i thought that was it but the video starts when page refresh

$orimessage = 'https://www.youtube.com/watch?v=m5N9IHqqGcA';

if(textlink($orimessage))
{
    $link =textlink($orimessage);
    $em = new Wall_Expand($link);
    $site = $em->get_site();
    if($site != "")
    {

        $my_thumb= $em->get_thumb("medium");
       $code = $em->get_iframe();

        if($my_thumb != "")
        {
            echo '<div class="img_container"><a href="#" id="video_thumb_'.$omsg_id.'" style="display:block;" onClick="javascript:loadVideo(\''.$omsg_id.'\')"><img src='.$my_thumb.' class="imgpreview" /></a>';
            if($code != ""){
                echo '<div style="display:none;" id="video_'.$omsg_id.'"?autoplay="1">'.$code.'</div>';
            }
            echo '</div>';
        }
    }
}
?>

and the .js

    function loadVideo(input){
        document.getElementById("video_thumb_"+input).style.display="none";
        document.getElementById("video_"+input).style.display="block";
    }

when pressed the video doesnt start the autoplay you have to press twice to start the video

and this is the function

public function get_iframe($w = -1, $h = -1){
        $this->prepare_data("iframe");
        if($this->site != "" && $this->data["iframe"] != "")
        {

            if($w < 0 || $h < 0)
            {
                $w = (is_int($this->data["w"]) && $this->data["w"] > 0) ? $this->data["w"] : $this->default_size["w"];
                $h = (is_int($this->data["h"]) && $this->data["h"] > 0) ? $this->data["h"] : $this->default_size["h"];
            }
            $w=492;
            return '<iframe class="new" width="'.$w.'" height="'.$h.'" src="'.$this->data["iframe"].'?autoplay=0" frameborder="0" allowfullscreen></iframe>';
        }
        else
        {
            return "";
        }
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.