2016-12-05 8 views
2

複数のビデオの現在の再生時間をデータベースから取得する必要があります。複数のビデオの現在の再生時間を取得

私は、データベース内の再生映像の時間を節約したいので、彼が入って来たとき、私は、後に、ユーザのための正しい位置を設定することができます。

私はアヤックス4秒ごとに発射するsetIntervalを使用しています。助けてください?

コード

<?php 

$tl="channel"; 
$ooa="playing"; 
$played="played"; 

$timeline = mysqli_query($con, "SELECT * FROM plays WHERE streamers_type ='$tl' AND played !='$played' GROUP BY streamers_id ORDER BY id ASC") or die(); 

while($row = mysqli_fetch_array($timeline)) { 
    $id = $row['id']; 
    $file1 = $row['file1']; 
    $video_name = $row['video_name']; 
    $video_type = $row['video_type']; 
    $about_video = $row['about_video']; 
    $streamers_type = $row['streamers_type']; 
    $streamers_id = $row['streamers_id']; 
    $time_start = $row['time_start']; 
    $time_stop = $row['time_stop']; 
    $date = $row['date']; 
    $streamers_name = $row['streamers_name']; 
    $views = $row['views']; 
    $played = $row['played']; 

      ?> 
    <li class="col-lg-4 col-sm-5 col-xs-12 spinal"> 
    <b style="border:1px solid; color:red; margin-left:3px!important;"><?php echo $streamers_name ?></b> 
    <span class="pull-right"><span id = "fhkj"><?php echo $views?></span>&nbsp; &nbsp;<i class="fa fa-eye"></i></span> 
     <a class="fg" title="<?php echo $video_name ?>"> 
     <button data-toggle="modal" data-target="#modal-1" data-backdrop="static" data-keyboard="false" class="fire" id="<?php echo $id ?>"> 

     <video class="uopi " id="<?php echo $video_name ?>" style="height:180px; width:100%!important;" autoplay muted onended="run();"><source src="plays/<?php echo $file1 ?>" type="<?php echo $video_type ?>"></video> 

     <h2 style="background-color:#fff;color:orange; line-height:30px; font-size:1.3em;"><?php echo $video_name ?></h2> 
      <span class="glyphicon glyphicon-play-circle"></span></button> 

     </a> 
    </li> 
      } 
    ?> 




      <script type='text/javascript'> //function to update time  
     var vid = $('.uopi').attr('id'); 
    var ok = vid.currentTime; 
     $(document).ready(function() { 
    setInterval(function() { 
      $.ajax({ 
      type : 'POST', 
      url : 'updatetime.php', 
      data : {ok: ok}, . 
      success : function(r) 
      { 
      alert('Yay'); //would be commented out later dont really need any success just save 

      } 
    }); 

    }, 4000); 
}) 
</script> 

答えて

1

まず第一に、あなたのSQLクエリ(How can I prevent SQL injection in PHP?)にSQLインジェクションの脆弱性を修正:あなたの問題へのP

私の回答は、あなたが 'beforeunload' イベントを使用することができることです。ユーザーがリンクをクリックするか、実際のタブ/ウィンドウを閉じると、コードが実行されます。次のようなコードを使用できます:

window.addEventListener("beforeunload", function(e){ 
    var vid = $('.uopi').attr('id'); 
    var ok = vid.currentTime; 
    $.ajax({ 
     type : 'POST', 
     url : 'updatetime.php', 
     data : {ok: ok}, 
     success : function(r) 
     { 
      console.log('Yay'); 
     } 
    }); 
}, false); 

編集:「一時停止」のようなビデオイベントを使用して、現在の時刻を更新することもできます。

関連する問題