I need to stream selected video files on the web server to clients. I am using a PHP script to stream these files as requested, but I am running into an issue where if I am on a local net, it works fine, but if I am remote, it stutters. eg. it appears to load the stream, stop, load more, stop, etc. until enough media is available to play. I am new to this stuff, so I need some advise on how to overcome this issue. The bandwidth should not be a problem, so I am not sure what is going on. I have tried several php streamers, but all act pretty much the same. I am using videojs to display it within the client.
<?php
use vendor\videojswidget\VideoJsWidget;
$url = Yii::$app->urlManager->createUrl('/site/putvideo');
$currentVideo = '';
$script1 = "function playAnotherVideo(){
var source = document.getElementById('fileSelector');
var path = source.value;
$.ajax({
type: 'post',
data: {file: path},
url: '" .$url. "',
success: function(result){
var video = document.getElementById('videoPlayer');
video.src = result;
alert(result);
video.load();
},
error: function(){
alert('error');
}
});
}";
$this->registerJs($script1, yii\web\View::POS_END, 'my-options');
/* @var $this yii\web\View */
$this->title = 'View Vault Lecture Capture System';
?>
<div class="site-index" style="background-color: black; color: yellow;">
<div style="background-color: black;">
</br></br></br></br>
<h1 align="center">Welcome to the TEKVOX Lecture Capture System</h1>
</br></br></br></br>
</div>
<div class="body-content">
<div style="width: 100%; overflow: hidden;">
<div style="width: 50px; float: left;">
</br></br>
<label for="fileselector" style="margin-left: 4em; width: 10em;
font-weight: bold; color: #FFFF00;">Video_Files</label>
<select id="fileSelector" onchange="playAnotherVideo()" size="10em"
style="margin-left: 0em; color: #FFFF00; background-color: #000000;
border-color: #FFFFFF">
<?php
if ($handle = opendir('c:/users/admin/videos/')) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != ".." &&
strtolower(substr($entry, strrpos($entry, '.') + 1)) ==
'mp4' ){
echo "<option value='$entry'>" .$entry. "</option>";
}
}
closedir($handle);
}
?>
</select>
</div>
<span id="divplayer" style="margin-left: 20em;">
<?php
echo VideoJsWidget::widget([
'options' => [
'class' => '',
'id' => 'videoPlayer',
'poster' => "GreenX.png",
'controls' => true,
'preload' => 'none',
'width' => '800',
'height' => '450',
],
'tags' => [
'source' => [
['src' => '', 'type' => 'video/mp4'],
],
'track' => [
['kind' => 'captions', 'src' =>
'http://vjs.zencdn.net/vtt/captions.vtt', 'srclang' => 'en', 'label' =>
'English']
]
]
]);
?>
</span>
</div>
</div>
</br>
The getVideo.php code:
<?php
include_once "videoStream.php";
$filename = $_GET['filename'];
if($filename == '')
return;
$file = "c:\\users\\admin\\videos\\" .$filename;
$stream = new VideoStream($file);
$stream->start();
?>
The VideoStream.php class I am currently trying out is at: VideoStream
What is also strange is that the bar at the bottom of the player seems to indicate that the video is buffered, yet the player still stutters. Not sure what that means.