Creating a live video streaming page using HTML-5 and JavaScript
Now a day live streaming is a very popular feature in many apps like Facebook, Instagram, and Hotstar, as well as many websites, and also provides online streaming of any live ongoing event on their site. Obviously broadcasting any live event is a tedious task and required broadcasting rights of that event, which causes you to pay a good amount to the event organizer. There are a bunch of organizations available that take the all responsibilities of broadcasting live events. But as a noob when you just try to set up things for testing purposes on your local as well as the live server then there come javascript and HTML 5 using which you can implement the live streaming page on your webpage.
1. Your HTML page says index.html has the following code.
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>Home</title>
- <link rel="stylesheet" href="css/style.css">
- </head>
- <body>
- <div class="booth">
- <video id="video" width="400" height="300" autoplay></video>
- </div>
- <script type="text/javascript" src="js/script.js"></script>
- </body>
- </html>
2. Here your self invoking Javascript code linked to an HTML file
- (function(){
- var video = document.getElementById('video'),
- vendorUrl = window.URL || window.webkitURL;
- navigator.getMedia = navigator.getUserMedia ||
- navigator.webkitGetUserMedia ||
- navigator.mozGetUserMedia ||
- navigator.msGetUserMedia;
- //capture media
- navigator.getMedia({
- video:true,
- audio:true
- }, function(stream){
- video.src = vendorUrl.createObjectURL(stream);
- video.play();
- },function(error){
- //error.code
- });
- })();
Now go ahead and tries to open the index.html page in any browser it will detect your webcam and asking the permission to play video. Allow browsee to play the video and you can get a live stream of your webcam on your page.
In case you don't have a built-in webcam then you can use an external webcam or you can use your smartphone as a webcam.
I have posted a different post on "How to use your smartphone as a webcam".
Here you can download a sample source code Download
Please do follow me on Google+ for more cool I.T. stuff
Download sample source code used in tutorial from
ReplyDeletehttps://drive.google.com/open?id=1QrZT9uO0tL39rHG4oRD_mWOcMASG8zqn