Sunday, June 8, 2014

HTML5

Audio Play

In HTML5, audio (and video as well) can easily be played even with the player using audio/video elements.

If you add multiple audio/video elements to HTML, they'll start playing at once. And to play them one after the other, the next clip should be started after the end of the previous using ended event.

This JavaScript example shows how to play an array of audio clips one after the other:

function playAll(playList, current) {
  current = current || 0;

  playList[current].volume = 0.75;
  playList[current].play();

  if (playList[1 + current]) {
    playList[current].addEventListener('ended', function () {
      playAll(playList, 1 + current)
    });
  }
}

var playList = [
  new Audio('1.mp3'),
  new Audio('2.mp3'),
  new Audio('3.mp3'),
  new Audio('4.mp3'),
  new Audio('5.mp3')
];

playAll(playList);

Wednesday, February 26, 2014

Yii and non-Yii

Blending Yii and non-Yii applications together

If you want to link Yii application with non-Yii application, the best option is to re-write the existing application in Yii.

Definitely you can initiate HTTP requests to invoke Yii actions, but it creates TCP/IP connections which are costly. If both applications reside in the same web server, you can use below method.


Create a bootstrap (this code segment can be placed inside anywhere in current non-Yii application):
<?php
// change the following paths if necessary
$yii='yii/framework/yii.php';
$config=dirname(__FILE__).'/protected/config/application.php';

// remove the following lines when in production mode
//defined('YII_DEBUG') or define('YII_DEBUG',true);
// specify how many levels of call stack should be shown in each log message
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);

require_once($yii);

// `Application.php` must exist in the same level of THIS php file
$yiiapp = Yii::createApplication('Application', $config);

// Call methods inside `Application.php`
$yiiapp->doAction1();
$yiiapp->doAction2();

Create the wrapper `Application.php` in the same dir-level as the above bootstrap code segment is (any name can be used; but need to alter Yii::createApplication(...) above)
<?php
/**
 * NOTE:
 *   - `Yii::app()` is available from here.
 */
class Application extends CApplication
{
  public function init()
  {
  }

  /**
   * Yii::createApplication(...)->run() executes this method
   */
  public function processRequest()
  {
  }


  public function doAction1()
  {
  }

  public function doAction2()
  {
  }
}

Friday, January 3, 2014

Yii and Oracle

Getting Table Structure

This is how to get name, type and size of all the columns of table, owner_name.mytable.
// dbOracle must have been defined in configurations
$remote_db = Yii::app()->dbOracle;

$stru = $remote_db->createCommand()
  ->from('ALL_TAB_COLS')
  ->where("TABLE_NAME = 'mytable' AND OWNER = 'owner_name'")
  ->queryAll();

$col_info = array();

foreach ($stru as $_col_meta)
{
  $_info = new stdClass();

  $_info->name = $_col_meta['column_name'];
  $_info->type = $_col_meta['data_type'];
  $_info->size = $_col_meta['data_length'];

  $col_info[] = $_info;
}

print_r($col_info);