jquery - retrieving video from database using php -


i trying figure out how retrieve video_link database after users select video using html form. 2 videos uploaded database, original video , compressed video, depending on user connection. appropriate video embed in html 5 video tag in viewvideo.php because ajax expecting response in $( "#speed" ).val( html ); dun think can embed video in viewvideo.php

so question should now? should retrieve video_link , embed video?

this coding now.

i have html form retrieve user connection speed , video_id user wish watch , using ajax post form data

html form

<form action="viewvideo.php" method="post" >                 <br/>                 please select video                 <br/>                  <select name="video_id">                     <?php                         while($row = mysqli_fetch_array($result))                         {                     ?>                                              <option value="<?php echo $row['video_id']?>">                     <?php echo $row['videoname']?>                                       </option>                              <?php                         }                     ?>                 </select>                  <br />                   <input type="text" id="speed" name="speed" value="">                 <input type="submit" id="submit" value="submit" />                 </form> 

ajax

  $.ajax({       method: "post",       url: "viewvideo.php",       data: {speedmbps: speedmbps,       video_id: $('[name="video_id"').val()},       cache: false     }).done(function( html ) {         $( "#speed" ).val( html ); }); 

viewvideo.php

  if(isset($_post['video_id']) && isset($_post['speedmbps'] )){                         $id = trim($_post['video_id']);                         $speed = $_post['speedmbps'];                         echo $id;                          $result = mysqli_query($dbc , "select `video_id`, `video_link` `video480p` `video_id`='".$id."'");                         $count = mysqli_num_rows($result);                          if (($speed < 100) && ($count>0)) {     //if user speed less 100 retrieve 480p quailtiy video                                 //does exist?                             //if($count>0){                                 //exists, fetch in associative array                                 $video_480p = mysqli_fetch_assoc($result);                                 //this way can use column names call out values.                                  //if want link video embed it;                                 echo $video_480p['video_link'];                                                      }                              else{                                 //does not exist                             }          ?>                          <video id="video" width="640" height="480" controls autoplay>                         <source src="<?php echo $video_480p['video_link']; ?>" type="video/mp4">                         browser not support video tag.                         </video>                         <br />                          <?php                          $result2 = mysqli_query($dbc , "select `video_id`, `video_link` `viewvideo` `video_id`='".$video_id."'");                         $count2 = mysqli_num_rows($result2);                          // retrieve original video                          if (($speed >= 100) && ($count2 >0)) {                                  //does exist?                                     //if($count2>0){                                         //exists, fetch in associative array                                         $video_arr = mysqli_fetch_assoc($result2);                                         //this way can use column names call out values.                                          //if want link video embed it;                                         echo $video_arr['video_link'];                                                               }     else{                                     //does not exist                                  }         ?>                          <video id="video" width="640" height="480" controls autoplay>                         <source src="<?php echo $video_arr['video_link']; ?>" type="video/mp4">                         browser not support video tag.                         </video>                         <br />          <?php                      mysqli_close($dbc);         ?> 

if want video accessible user, must put actual video (mp4) files in public directory browser can download them. video_link must contains actual url accessible user. if videos not in public directory, user cannot access them directly or can embed video binary data in url data: protocol

 data:[<mime-type>][;charset=<encoding>][;base64],<video data> 

for example

<?php     function getvideourlstring($file, $type) {           return 'data:video/' . $type . ';base64,' .                 base64_encode(file_get_contents($file));      } ?> 

then in html

<video ...>              <source type="video/mp4" src="<?php echo getvideourlstring($filename, "mp4");">  </video> 

embedding video data in url has drawback may takes long time load html.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -