The Video Boardcast Platform

in #utopian-io6 years ago (edited)

https://github.com/php/php-src
my github profile https://github.com/rakamlarustune
project github https://github.com/rakamlarustune/The-Video-Boardcast-Plaform

What Will I Learn?

This lesson:

  • html5 video streaming how making
  • Video tag stages of use
  • php mp4 video stream -backend struct-
  • php generaly request managing (server-side)

to after all lessons:

  • Video feature upload and play system.
  • Tools code To avoid theft
  • does not permit off-site access
  • Learning platform, where users can watch videos.
  • For example, stop the seconds based videos and show the question.
  • Tools To avoid downloading videos.
  • Collect view count and duration.
  • Add ads to the Before video
  • Add a paid Membership system
  • Then channel to paid members
  • Commenting on videos (post comments)
  • Feature scoring system
  • Add a logo to the video corner

Here you will be an Youtube as you begin with the first simple, then as you progress

Requirement:

Difficulty

Intermediate

Tutorial Contents

As a result of all the lessons:
Php video boardcast (training platform -dynamic question-based video)
You can find examples of video playback on many Google searches.
However, it is unlikely to find more . In this project we will demonstrate the base of developing a product.
Most of the time it will be the steps of doing a Project. But this may seem simple at first time. The general definition of extremely complex functions will be. Understand how to add some of the samples you find. More: How to make modifications? How people are building and constructing complex modern applications?

In the first lesson we will examine the usual in video products. However, after the first lesson, we will make updates to the other different patterns. It will be upgraded with continuous innovations. Your knowledge level and information tank may need to be a significant level. Future point in this project; to be like a YouTube. Your confidence needs to evolve. A successful person always has to be patient to solve complex things , in my opinion. That's why it's going to be serious once you've got through the first steps.

please review and follow the codes below

Step:1

Laragon software install and unpack. Run and click “StartAll” button. It will be a free and effortless choice. After this create index.php file. You must type the following things in.

my file tree
│ index.php
│ readme.txt

└───data
├───lib
│ jquery-1.9.1.min.js
│ normalizer.css
│ reset.css
│ w3.css

└───play
│ video.php

└───vid
demo.mp4

index.php

<?php

define('APP', 'MyApplication');
$file='demo.mp4';
//first video by demo.mp4

?>

Data variable $file play video file name of require
first line code for security. continue to add under.
In need of regulation in subsequent lessons have.
Will be to good after later.
Describe: The basic html structure. A basic thing you can find anywhere

<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="description" content="video">
<title> Protyped Version Beta</title>

(html comment removed: -  some css and js library -)
<link rel="stylesheet" href="data/lib/reset.css">
<link rel="stylesheet" href="data/lib/normalizer.css">
<link rel="stylesheet" href="data/lib/w3.css">
<script type='text/javascript' src="data/lib/jquery.js"></script>

<style>
body{
    background:rgb(220,220,220);
}
</style>

</head>
<body>
</body>
</html>

detail of code:
That utf-8 html meta code value. Because it must be compatible in all world languages. Special letters and characters are compatible. Special character corrections

<meta charset="UTF-8">

General content description summary

<meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>

Browser title text in here
Title tag:

<title>Unschool Protyped Version Beta</title>

Browser content description tag:
description tag:

<meta name="description" content="video">

Mostly mobile browsers compatibility code, scale option.
Viewport tag:

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

include files:

    reset.css  // The reset styles given here are intentionally very generic
    normalizer.css // compatibility all browser css
    w3.css      //simple usefull css class w3-inline w3-padding w3-red
    jquery.js   // Jquery tools : $().click $().append()

background:rgb(220,220,220);
all page color of Back side. r(red),g(green),b(blue) technique

Step:2

Over the index.php file, there will be additions over time. Add them into the “body section” and try it.

<center>
<h3 class="w3-grey w3-block" >video file play</h3>
<video width="auto" controls autoplay style='display:block;width:75%;'>
<source src="data/play/video.php?v=<?php print($file); ?>.mp4" type="video/mp4" />
Your browser does not support HTML5 video.
</video>
</center>

detail of code:

<video width="auto" controls style='display:block;width:75%;'>

The video tag "controls" element puts a nice play/pause control with the video. Very cool, a lot of functionality from one little tag.

autoPlay:

type:

If the type attribute isn't specified, the media's type is retrieved from the server and checked to see if the user agent can handle it; if it can't be rendered, the next source is checked.

Including the controls attribute in the video tag (unfortunately) enables the browser's own user interface for controlling playback. Luckily, it is not needed for video functionality. The video video format browser support differs from browser to browser (no kidding), so a web page may provide a video in multiple formats.


generally all inside items of center. Align:center feature provide and support.

<h3 class="w3-grey w3-block" >video file play</h3>
thats just video title like looks.
•   w3-grey // color code of w3.css  (w3-red, w3-orange...)   
•   w3-block // block width full setting up (sometime need)


<source src="data/play/video.php?v=<?php print($file); ?>.mp4" type="video/mp4" />

The URL of the video to embed. This is optional; you may instead use the source element within the video block to specify the video to embed. In advancing steps; video.php will be created and used. Direct URL is not used because
They can simply access your video file. A system that manages advanced video files is required. Advanced users generally do this. “video.php?v=file.mp4” or “go.php?f=filename.jpg”
The reason is that it can hold all control in its own hands. So measures and authority controls against other people's activities can be done.

if finishing thats. looks like this.

![1.png](

This example plays a video when activated, giving the user the browser's default video controls. Until the video starts playing, the image given is displayed in its place. If the browser doesn't support video playback, fallback text is displayed. It doesn't work right now because it's supposed to be like this. Be patient and check out the next steps.

Step:3

Create of video.php file and write this code

video.php

<?php
//video.php method v= filename
//sample video.php?v=filename1.mp4 return file stream
// Processing will be done here

?>

Processing will be done here.continue.

that code, video streaming of calculate Class a series of actions or steps taken in order to achieve a particular end.

class VideoStream
{
    private $path = "";
    private $stream = "";
    private $buffer = 102400;
    private $start  = -1;
    private $end    = -1;
    private $size   = 0;
 
    function __construct($filePath) 
    {
        $this->path = $filePath;
    }
     
    /**
     * Open stream
     */
    private function open()
    {
        if (!($this->stream = fopen($this->path, 'rb'))) {
            die('Could not open stream for reading');
        }
         
    }
     
    /**
     * Set proper header to serve the video content
     */
    private function setHeader()
    {
        ob_get_clean();
        header("Content-Type: video/mp4");
        header("Cache-Control: max-age=2592000, public");
        header("Expires: ".gmdate('D, d M Y H:i:s', time()+2592000) . ' GMT');
        header("Last-Modified: ".gmdate('D, d M Y H:i:s', @filemtime($this->path)) . ' GMT' );
        $this->start = 0;
        $this->size  = filesize($this->path);
        $this->end   = $this->size - 1;
        header("Accept-Ranges: 0-".$this->end);
         
        if (isset($_SERVER['HTTP_RANGE'])) {
  
            $c_start = $this->start;
            $c_end = $this->end;
 
            list(, $range) = explode('=', $_SERVER['HTTP_RANGE'], 2);
            if (strpos($range, ',') !== false) {
                header('HTTP/1.1 416 Requested Range Not Satisfiable');
                header("Content-Range: bytes $this->start-$this->end/$this->size");
                exit;
            }
            if ($range == '-') {
                $c_start = $this->size - substr($range, 1);
            }else{
                $range = explode('-', $range);
                $c_start = $range[0];
                 
                $c_end = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $c_end;
            }
            $c_end = ($c_end > $this->end) ? $this->end : $c_end;
            if ($c_start > $c_end || $c_start > $this->size - 1 || $c_end >= $this->size) {
                header('HTTP/1.1 416 Requested Range Not Satisfiable');
                header("Content-Range: bytes $this->start-$this->end/$this->size");
                exit;
            }
            $this->start = $c_start;
            $this->end = $c_end;
            $length = $this->end - $this->start + 1;
            fseek($this->stream, $this->start);
            header('HTTP/1.1 206 Partial Content');
            header("Content-Length: ".$length);
            header("Content-Range: bytes $this->start-$this->end/".$this->size);
        }
        else
        {
            header("Content-Length: ".$this->size);
        }  
         
    }
    
    /**
     * close curretly opened stream
     */
    private function end()
    {
        fclose($this->stream);
        exit;
    }
     
    /**
     * perform the streaming of calculated range
     */
    private function stream()
    {
        $i = $this->start;
        set_time_limit(0);
        while(!feof($this->stream) && $i <= $this->end) {
            $bytesToRead = $this->buffer;
            if(($i+$bytesToRead) > $this->end) {
                $bytesToRead = $this->end - $i + 1;
            }
            $data = fread($this->stream, $bytesToRead);
            echo $data;
            flush();
            $i += $bytesToRead;
        }
    }
     
    /**
     * Start streaming video content
     */
    function start()
    {
        $this->open();
        $this->setHeader();
        $this->stream();
        $this->end();
    }
}

A ready-made class in which the annotation is available. The reason for these codes is to work properly.
It contains some basic solutions. It is working properly.

  • Finding the type of video
  • Transferring video length from file
  • Caching control Processing
  • Avoiding any integrated errors
  • Byte to read system with controlled loading cycles
  • Setting up set_time_limit

Let's just go under.Let me continue.

if( !defined('APP') && !isset($_SERVER['HTTP_REFERER']) ){
die("No direct access is allowed.");
}

$file1='vid/'.$_GET['v'];

$stream1 = new VideoStream($file1);
$stream1->start();
exit;

here is a valid transaction upon request. Blocking to some unwanted things.

Detail of code:

if( !defined('APP') && !isset($_SERVER['HTTP_REFERER']) )
Here is a general method. Prevent access from another application or from another site.
defined('APP') stipulated to be predefined. Must be pre-defined to index.php

$file1='vid/'.$_GET['v'];
I need to know the path to the video file. .$_GET using geeft method. Being a file extension is essential. Must be mp4 ext because mostly useful and compatible.
2.jpg

$stream1 = new VideoStream($file1);
here we use the existing VideoStream Class, call function  $file1 by file path.

$stream1->start();

were used start. if it is not written then it will not work to process

for now the job there video.php seem finished.
3.jpg

http://127.0.0.1/data/play/video.php?v=demo.mp4
you can try.. direct access. To avoid theft.
4.jpg

That's now Ends here. It will become more complicated with the next lessons

Sort:  

Your tutorial content is barely comprehensible, that is either due to being badly translated from another content, or you would need to seriously work on improving your communication in English to provide some bare minimum quality of a tutorial.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

thank for advice sir i am be carfuly next tutorials

Coin Marketplace

STEEM 0.28
TRX 0.13
JST 0.032
BTC 60385.11
ETH 2889.75
USDT 1.00
SBD 3.65