Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript HTML PHP Ajax MySQL , +
I am creating a Video List dynamically. Here, I have added javascript onclick event dynamically; But, I have to call a javascript function which get parameter from php.
here is my php code:
while (($file = readdir($dh)) !== false) {
 
                    if ($file == ".") {
                        echo '..<br>';
                    } elseif ($file == "..") {
                        echo '..<br>';
                    } else {
                        echo ''. $file . '<br>';
                        echo '<br><video id="button_' . $i . '" autobuffer preload="auto" style="width:200px;height:300px"  src="videos/' . $file . '"  önclick=' . $ch . 'add(this.src)' . $ch . '></video>';
                        //echo '<br><input type="button" id="button_' . $i . '" class="mybuttons" value="Play" name="videos/' . $file . '" onclick=' . $ch . 'add(this.name)' . $ch . '/>';
                        $i = $i + 1;
                    }
                }
 
And my javascript function is:
 function playVideo2() {
                var starttime = 2;  // start at 2 seconds
                var endtime = 6;    // stop at 4 seconds
                var b = <?php echo 'button_3'; ?>;
                var c = "'" + b + "'";
                var video = document.getElementById(c);
                video.play();
                setTimeout(function() {
                    video.pause();
                }, 125);
                //handler should be bound first
            }
 
And :
function playVideo() {
                var starttime = 2;  // start at 2 seconds
                var endtime = 6;    // stop at 4 seconds

                var video = document.getElementById('v0');
                video.play();
                setTimeout(function() {
                    video.pause();
                }, 125);
                //handler should be bound first
            }
 
In function playVideo2(), I have tried PHP there. This is not working while I have call this function from html. My html code:
<body  önload="playVideo();
                playVideo2();">
        <p id="time"></p>
        <video id="v0" controls tabindex="0" autobuffer preload>
            <source type="video/webm; codecs="vp8, vorbis"" src="videos/Wildlife.webm"></source>
 
            <p>Sorry, your browser does not support the <video> element.</p>
        </video>
Posted 28-Apr-13 4:01am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hello,
 
Try changing the PHP code as shown below.
while (($file = readdir($dh)) !== false) {
    if ($file == ".") {
        echo '..
';
    } elseif ($file == "..") {
        echo '..
';
    } else {
        echo ''. $file . '
';
        echo '
<video id="button_' . $i . '" autobuffer="" preload="auto" style="width:200px;height:300px" src="videos/' . $file . '" önclick="playVideo(this);"></video>';
        $i = $i + 1;
    }
}</br></br></br></br>
Your javascript function becomes something like one shown below.
function playVideo(vid) {
    var starttime = 2;  // start at 2 seconds
    var endtime = 6;    // stop at 4 seconds

    vid.play();
    setTimeout(function() {
        stopVideo(vid);
    }, 125);
}
 
function stopVideo(vid) {
   vid.pause();
}
Regards,
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 410
1 Jochen Arndt 200
2 Richard MacCutchan 135
3 DamithSL 105
4 PIEBALDconsult 90
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,032
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,220


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 28 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100