Home » Features, Flash Lite, Programming

Testing KuneriLite plugins: Take, play and send video from Flash Lite to server

By Pasi Manninen 9 September 2008 No Comment

Pasi Manninen keeps testing KunerLite plugins and report to the community. Kuneri have done 11 nice plugins to extend Flash Lite applications and Pasi went out to test some of them. This article he covers the taking, playing and sending video to a remote server.


In my earlier article I’ve tested KuneriLite Camera plugin to take picture (klMode=picture). This time I’ve tested it’s video support (klMode=video) to record video and store it to mobile phone. I’ve modified my code a little and it worked very nicely on the Nokia N95. This test application sends videos to my server http://ptm.fi/temp/videos folder, so make sure you’ve uploaded videos from there.

PTM Video pic 1 PTM Video pic 2 PTM Video pic 3

> Setting up system

This time I’ve tested KuneriLite wizard in Microsoft Vista. I’ve installed Active Perl and Symbian S60 3rd edition SDK Maintenance Release as I did earlier in my Camera and Upload plugins -article. I had to make small modifications to get KuneriLite Wizard working on vista. You can find these modifications on the KuneriLite Wiki: Microsoft Vista Support.

> Flash Lite Application

The idea of this application is take video, play it to the user and send it to a remote server (if the user wants to send it). All the code is written to the first frame of the timeline. I’ll describe here only the needed lines to understand how to take, show and send a video file to the remote server. Please, see the source code for more information.

> Initialize Application

There is one major bug in my previous example with taking pictures, have you noticed it? I haven’t thought on the situation where a user start to take a picture and then press back when Kuneri Lite Camera plugin is active. The application is trying to make a thumbnail picture, which fails if there is no picture taken. In this video example this situation is handled with Camera plugin Status operation (klStatus).

A few variables are defined to handle video filename and KuneriLite plugin gateway errors.

var vidName:String = "";          // video name
var klError:Number = -99;         // klError number
var klStatus:String = "";         // klStatus string
var process:Number = 0;           // process number
var intervalId:Number;            // interval number
var path:String = "\\Data\\Others\\Trusted\\PTMVideo\\";

> Preparing Camera

KuneriLite offers optional prepare command which prepares the camera resource and checks the presence of a camera device. I’ll check this first and then let the user take a video.

// check camera condition
process = 1;
intervalId = setInterval(checkProcess,1000);
status_txt.text = "status: preparing camera...";
loadVariables("http://127.0.0.1:1001/Basic/camera?
               klCommand=prepare&klIndex=0","");

> Taking video

This stage is very similar to the sending picture example from the previous article. The only visible modification is with Video instance. I’ve added one video symbol to the library and dragged it to the timeline (instance name is video). When a user presses the device’s number one key, KuneriLite uses loadVariables()-function to call Camera plugin in order to take video. Here I just take a full size video with main camera.

//Take video
function takeVideo(){
  // videoname
  vidName = giveDateAndTimeString();
  var command:String = "";
  command += "http://127.0.0.1:1001/Basic/camera?klCommand=start";
  command += "&klMode=video";
  command += "&klPath="+path+vidName+".3gp";
  command += "&klSize=full";
  command += "&klIndex=0";
  status_txt.text = "status: taking video...";
  process = 2;
  klError = -99;
  intervalId = setInterval(checkProcess,1000);
  loadVariables(command,"");
}

> Did The User Take Video Or Not

As I wrote earlier, I didn’t check if the user had taken a picture in my previous example. Here I will do it after the video screen is closed in KuneriLite plugin. I have one function which checks processes to see what had happened in my application. When Kuneri Lite Camera plugin is closed, I’ll start to check if there’s a video file taken or not.

// .. part of my prosess function
// check if video is taken
case 2:
  if (klError == -99) return;
  clearInterval(intervalId);
  if (klError == 0) {
    status_txt.text += "done!";
    intervalId = setInterval(checkVideo,2000);
  }
  process = 0;
  break;
//check is video taken
function checkVideo() {
  clearInterval(intervalId);
  var command:String = "http://127.0.0.1:1001/Basic/camera?klCommand=status";
  status_txt.text = "status: checking video...";
  process = 3;
  klError = -99;
  klStatus = "";
  intervalId = setInterval(checkProcess,1000);
  loadVariables(command,"");
}

If video is available, just start to play it.

// .. part of my process function
// is videofile available
case 3:
  if (klError == -99) return;
  clearInterval(intervalId);
  if (klError == 0) {
    status_txt.text += "done!";
    if (klStatus == "complete") {
      intervalId = setInterval(playVideo,2000);
    } else if (klStatus == "exit") {
      status_txt.text = "status: No video!";
    }
  } else {
    status_txt.text = "status: klError = "+klError;
  }
  process = 0;
  break;

> Play video

After video is taken, it will be showed to user with a video instance.

// Load and play video
function playVideo(){
  clearInterval(intervalId);
  status_txt.text = "status: playing video...";
  video.play(vidName+".3gp");
}

video.onStatus = function(info){
  if (info.code=="completed") status_txt.text += "done!";
}

> Sending video file to remote server

Sending is handled the same way I used in my photo example. I added upload status checking to this example. First video will be sent to server and uploading is checked with own made checking function

function checkUploading() {
  clearInterval(intervalId);
  var command:String = "http://127.0.0.1:1001/Basic/uldl?klCommand=status";
  command += "&klTrId=1234";
  process = 5;
  klError = -99;
  klStatus = "";
  intervalId = setInterval(checkProcess,1000);
  loadVariables(command,"");
}

and process function is checking what is going on with uploading. KuneriLite sends a few different status, I used only two of them: complete if uploading is successfully completed or failed if there where some problems.

case 5:
  if (klError == -99) return;
    clearInterval(intervalId);
    if (klError == 0) {
      status_txt.text = "status:" +klStatus;
      if (klStatus == "complete" || klStatus == "failed") {
        process = 0;
      } else {
        intervalId = setInterval(checkUploading,1000);
      }
    } else {
      status_txt.text = "status(5): klError = "+klError;
      process = 0;
    }
  break;

> Source and SIS files

This application is designed to run on 240×320 screens and for testing purposes only. It uses KuneriLite’s default generated SIS package, so if you have my other examples installed you have to remove these first.

Sources: PTMVideo.zip (Flash Lite 2.0 Application)
SIS: PTMVideo_3rd_edition_signed.sis (install it to memory card!)

Feel free to try this example and send video greetings to me with Flash Lite!

Note! I think I have about 3-4MB upload limit per file with PHP at my server, so don’t take too long videos!

[This article was first posted on Pasi's Blog.]

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.