4
4
5
5
class VideoStreamer
6
6
{
7
- private $ path = "" ;
7
+ private $ path = '' ;
8
8
9
- private $ stream = "" ;
9
+ private $ stream = '' ;
10
10
11
11
private $ buffer = 102400 ;
12
12
@@ -16,7 +16,7 @@ class VideoStreamer
16
16
17
17
private $ size = 0 ;
18
18
19
- private $ mime = "" ;
19
+ private $ mime = '' ;
20
20
21
21
public function __construct ($ filePath = '' )
22
22
{
@@ -26,8 +26,7 @@ public function __construct($filePath = '')
26
26
}
27
27
28
28
/**
29
- * Open stream
30
- *
29
+ * Open stream.
31
30
*/
32
31
private function open ()
33
32
{
@@ -37,23 +36,22 @@ private function open()
37
36
}
38
37
39
38
/**
40
- * Set proper header to serve the video content
41
- *
39
+ * Set proper header to serve the video content.
42
40
*/
43
41
private function setHeader ()
44
42
{
45
43
ob_get_clean ();
46
- header (" Content-Type: " . $ this ->mime );
47
- header (" Cache-Control: max-age=2592000, public " );
48
- header (" Expires: " . gmdate ('D, d M Y H:i:s ' , time () + 2592000 ) . ' GMT ' );
49
- header (" Last-Modified: " . gmdate ('D, d M Y H:i:s ' , @filemtime ($ this ->path )) . ' GMT ' );
44
+ header (' Content-Type: ' . $ this ->mime );
45
+ header (' Cache-Control: max-age=2592000, public ' );
46
+ header (' Expires: ' . gmdate ('D, d M Y H:i:s ' , time () + 2592000 ). ' GMT ' );
47
+ header (' Last-Modified: ' . gmdate ('D, d M Y H:i:s ' , @filemtime ($ this ->path )). ' GMT ' );
50
48
$ this ->start = 0 ;
51
49
$ this ->size = filesize ($ this ->path );
52
50
$ this ->end = $ this ->size - 1 ;
53
- header (" Accept-Ranges: 0- " . $ this ->end );
51
+ header (' Accept-Ranges: 0- ' . $ this ->end );
54
52
55
53
if (! isset ($ _SERVER ['HTTP_RANGE ' ])) {
56
- header (" Content-Length: " . $ this ->size );
54
+ header (' Content-Length: ' . $ this ->size );
57
55
58
56
return ;
59
57
}
@@ -89,13 +87,12 @@ private function setHeader()
89
87
$ length = $ this ->end - $ this ->start + 1 ;
90
88
fseek ($ this ->stream , $ this ->start );
91
89
header ('HTTP/1.1 206 Partial Content ' );
92
- header (" Content-Length: " . $ length );
93
- header ("Content-Range: bytes $ this ->start - $ this ->end / " . $ this ->size );
90
+ header (' Content-Length: ' . $ length );
91
+ header ("Content-Range: bytes $ this ->start - $ this ->end / " . $ this ->size );
94
92
}
95
93
96
94
/**
97
- * close curretly opened stream
98
- *
95
+ * close curretly opened stream.
99
96
*/
100
97
private function end ()
101
98
{
@@ -105,8 +102,7 @@ private function end()
105
102
}
106
103
107
104
/**
108
- * perform the streaming of calculated range
109
- *
105
+ * perform the streaming of calculated range.
110
106
*/
111
107
private function stream ()
112
108
{
@@ -125,8 +121,7 @@ private function stream()
125
121
}
126
122
127
123
/**
128
- * Start streaming video content
129
- *
124
+ * Start streaming video content.
130
125
*/
131
126
public function start ()
132
127
{
0 commit comments