I am glad to inform you that again I am starting the article series for Record and Play the video using Viddler API.
Today in this first series of article, i will explain basics about viddler and how to record the video using Viddler API.Viddler provides the api to record and play video.
What Viddler API do?
Viddler give us to record the things and then save video on them server and that video we can fetch to show in our site as Play that video.
Viddle API is not free. Its paid version and here explained below things are trial version
and I have made trial demo.
You can download php class and examples of PHP viddler from here [ https://github.com/viddler/phpviddler ]. You can download ,record and play through webpage.
To Record Video
Step 1:
create one php file into folder examples which is in the demo you have download. Here I am going to create file record_video.php
.
Step 2:
Include phpviddler.php
file into file and create object of it.
1 2 3 4 | include '../phpviddler.php'; $v = new Viddler_V2('<Your_Api_key>', TRUE); //<Your_Api_key> is API key |
Step 3:
Next, Add authentication details of it.
1 2 3 4 5 6 7 8 9 | $auth = $v->viddler_users_auth( array( 'user'=> '<username>', 'password'=> '<password>', 'get_record_token'=> 1 ) ); |
Step 4:
Now, create session and display errors or authentication response using following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | // Get your session id $session_id = (isset($auth['auth']['sessionid'])) ? $auth['auth']['sessionid'] : ''; // If no session id, print errors if (!empty($session_id)) { $info = $v->viddler_users_getProfile(array( 'sessionid'=> $session_id )); // If any errors print them out // This should NOT be done in a production application // An exception should be used instead // For example purposes only { print_r($info); exit; } } // In a live example you SHOULD NOT show errors, rather write an exception else { print_r($auth); exit; } |
Step 5:
Flash code for recording a video:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="449" height="545" id="viddler_recorder" align="middle"> <param name="allowScriptAccess" value="always" /> <param name="allowNetworking" value="all" /> <param name="quality" value="high" /> <param name="scale" value="noScale"> <param name="bgcolor" value="#000000" /> <param name="flashvars" value="fake=1&enableCallbacks=1&recordToken=<?php echo $auth['auth']['record_token'];?>" /> <embed src="http://cdn-static.viddler.com/flash/recorder.swf" quality="high" scale="noScale" bgcolor="#000000" allowScriptAccess="always" allowNetworking="all" width="449" height="545" name="viddler_recorder" flashvars="fake=1&enableCallbacks=1;&recordToken=<?php echo $auth['auth']['record_token'];?>" align="middle" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /> </object> |
Step 6:
Calling javascript function which will alert video_id of recorded video
1 2 3 4 5 6 | function recordDone(username,user_video_number,video_id) { var record_id =video_id; alert(video_id); // To handle recorded data } |
After Adding above codes into record_video.php file,click on start recording. After recording finish, Press on the save button so it will get option to store that video on them server.
After saving that video, I have alert the video_id
which is necessary so on the basis of it we can get uploaded video to play on our server.
Technical Notes
1. For saving recorded video I have to set get_record_token=> 1
in Request URL so it will return record token which passed.
2. For Fetching Video_ID we need to pass enableCallbacks=> 1
in flashvars attribute.
Trial version of Viddler account gives only 3 video access. So, You can upload 3 videos only after that its give you permission denied and security token error.For the solution of this, you need to remove uploaded video from viddler.com
How to remove uploaded video?
1. Go to the http://www.viddler.com/videos. Here, You get the uploaded video list.
2. Now, You just need to click on edit and then in left panel you will get the Delete option. Here you can delete those uploaded videos and again you can start to record the videos.
Conclusion
so to conclude, It’s very easy to record your videos using Viddler, isn’t? I have completed the first article here. we checked how to record video using viddler API.In Next article , I will show you how to play recorded video in PHP.
Recommended Read:
To convert PHP array into Javascript array
To grab content from nested tags in PHP
If you have any query or question,tell us in the comment section :). Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.