Code play random video dintr-un folder

AlexH

Merg pe strada catre Mine...
Membru personal
Administrative
Freelancer
SEO Expert
Am cerut Bot Ai sa imi faca un code pentru un player care sa ruleze video random dintr-un folder.
Discutii despre BOT Ai aici Chat GPT - ce părere aveți si daca ati folosit

Acesta este codul:

Cod:
<?php
$myVideoDir = 'media';
$extension = 'mp4';
$videoFile = false;
$pseudoDir = scandir($myVideoDir);
$myitems = array();
$mycounter = 0;
foreach($pseudoDir as $item) {
    if ( $item != '..' && $item != '.' && !is_dir($item) ) {
        $ext = preg_replace('#^.*\.([a-zA-Z0-9]+)$#', '$1', $item);
        if ( $ext == $extension )
            $videoFile = $item;
            if ( $videoFile <> "" ) {
                $myitems[] = $videoFile;
                $mycounter = $mycounter + 1;
            }               
    }
}

$myrandom = rand(0,$mycounter-1);
if ( !!$videoFile ) {

    echo '<video id="dep" class="center" width="400" autoplay controls>       
            <source src="'.$myVideoDir.'/'.$myitems[$myrandom].'" type="video/mp4">
        </video>
    ';
}
?>

Se poate customiza daca se doreste si stiti cum.


Codul de mai jos are optiunea de a adauga VAST ads si are un buton de refresh.

Cod:
<?php
$myVideoDir = 'media';
$extension = 'mp4';
$videoFile = false;
$pseudoDir = scandir($myVideoDir);
$myitems = array();
$mycounter = 0;
foreach($pseudoDir as $item) {
    if ( $item != '..' && $item != '.' && !is_dir($item) ) {
        $ext = preg_replace('#^.*\.([a-zA-Z0-9]+)$#', '$1', $item);
        if ( $ext == $extension )
            $videoFile = $item;
            if ( $videoFile <> "" ) {
                $myitems[] = $videoFile;
                $mycounter = $mycounter + 1;
            }               
    }
}

$myrandom = rand(0,$mycounter-1);
if ( !!$videoFile ) {

    echo '<video id="dep" class="center" width="400" autoplay controls>       
            <source src="'.$myVideoDir.'/'.$myitems[$myrandom].'" type="video/mp4">
        </video>';

    // Add a button to display vast ads
    echo '<button id="display-vast-ads" onclick="displayVastAds()">Display VAST Ads</button>';

    // Add a refresh button
    echo '<button id="refresh-button" onclick="refreshVideo()">Refresh</button>';
}
?>

<script>
  function displayVastAds() {
    // Add your code here to display the vast ads
  }

  function refreshVideo() {
    // Reload the page to refresh the video
    window.location.reload();
  }
</script>


Sper sa va fie de folos.


Daca doriti sa blocati accesul la direct link adaugati codul acesta in fisierul htacces.
Cod:
RewriteEngine on
RewriteRule ^upload/videos/.*\.(mp4|m4a|mp3|ogg|webm|flac|aac)$ - [NC,F,L]
 
Loading...
Back
Sus