LAZIOMATICA – Guida allo Sviluppo Software

La nuova forma del software su misura…

 

Developing Adobe AIR / Flex – Simple Youtube player with “AirYouTube” library

In previous example I have implemented a simple player with tubeloc library, but when i use it for multiple youtube player application it doesn’t work as aspected! infact this library has problems with multiple istances of the component, so only one istance can be used and the “destroy” method doen’t free the istance…so i try to find something else.
For this purpose i found aroun the web “AirYouTube”, another good component library and i post here another simple application with a main player and a button tha open simultanusly another istance of player in a pop up window.
The library and example can be founded at blog.derhess.de

and this is my basic snippet of code:

main application:

<?xml version=”1.0″ encoding=”utf-8″?>

<mx:WindowedApplication xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”absolute

xmlns:youtube=”de.derhess.video.youtube.*

width=”599” height=”600>

<mx:Script>

<![CDATA[

import mx.managers.PopUpManager;

import de.derhess.video.youtube.AirYouTube;

import de.derhess.video.youtube.YouTubeAS3;

import flash.utils.getDefinitionByName;

import de.derhess.video.youtube.YouTubeError;

import de.derhess.video.youtube.YouTubePlayingState;

import mx.controls.Alert;

import mx.collections.ArrayCollection;

import de.derhess.video.youtube.YouTubeVideoQuality;

import de.derhess.video.youtube.YouTubeEvent;

private function handlePlayerLoaded(event:YouTubeEvent):void

{

youTubePlayer.cueVideoById("paste_here_your_youtube_videoID_here",0,YouTubeVideoQuality.DEFAULT);

}

public function apriPop():void{

var myPop:pop = new pop();

PopUpManager.addPopUp(myPop,this,true);

}

]]>

</mx:Script>

<mx:Button x=”387” y=”393” label=”Carica Video in Popup” click=”apriPop();”/>

<youtube:FlexYouTube id=”youTubePlayer

x=”330” y=”0

width=”320” height=”240

volume=”100

youtubePlayerLoaded=”{handlePlayerLoaded(event);}”

/>

</mx:WindowedApplication>

pop.mxml component:

<?xml version=”1.0″ encoding=”utf-8″?>

<mx:Canvas xmlns:mx=”http://www.adobe.com/2006/mxml” width=”400” height=”300” xmlns:youtube=”de.derhess.video.youtube.*>

<mx:Script>

<![CDATA[

import de.derhess.video.youtube.AirYouTube;

import de.derhess.video.youtube.YouTubeAS3;

import flash.utils.getDefinitionByName;

import de.derhess.video.youtube.YouTubeError;

import de.derhess.video.youtube.YouTubePlayingState;

import mx.controls.Alert;

import mx.collections.ArrayCollection;

import de.derhess.video.youtube.YouTubeVideoQuality;

import de.derhess.video.youtube.YouTubeEvent;

private function handlePlayerLoaded2(event:YouTubeEvent):void

{

youTubePlayer2.cueVideoById("paste_here_your_youtube_videoID_here",0,YouTubeVideoQuality.DEFAULT);

}

]]>

</mx:Script>

<youtube:FlexYouTube id=”youTubePlayer2

x=”59” y=”234

width=”320” height=”240

volume=”100

youtubePlayerLoaded=”{handlePlayerLoaded2(event);}”

/>

</mx:Canvas>


Filed under : Actionscript 3,AIR,Flash CS5,Flex,Flexbuilder,RIA
By admin
On 27 settembre 2010
At 08:27
Comments :Commenti disabilitati
 
 

Programmazione Adobe AIR / Flex – Simple Youtube player with tubeloc library

In questo articolo tratteremo l’integrazione all’interno delle nostre applicazioni AIR di video provenienti dal noto portale YOUTUBE. Per fare ciò sfrutteremo la libreria AS3 disponibile al progetto http://code.google.com/p/tubeloc/ e doniminata “tubeloc”. L’integrazione di per se è molto semplice, basterà copiare il folder “com/enefekt/tubeloc” all’interno del nostro folder “src” e referenziandolo con uno spazio nomi del tipo tubeloc
Per aggiungere il player a questo punto sarà semplicissimo, infatti basterà aggiungere al file mxml il seguente codice:
prestando attenzione che il file as2_tubeloc.swf sia presente nella root file mxml dell’applicazione principale.
La chiamata difatti al filmato viene effettuata dal tag videoID il quale una volta impostato elabora la chiamata per effettuare l’embedded del filmato.
la libreria in esame presenta numerevoli proprietà e metodi che possono essere esaminati dalla documentazione ufficiale, ma in questo caso si voleva semplicemente esaminarne il modo più semplice per poter presentare video YouTube all’interno delle vostre WindowedApplication AIR.
Questo è quanto. Di seguito un piccolo snippet di interfaccia di test che ho utilizzato per il mio esempio, in cui nell’attesa che il player youtube si presenti alla vostra applicazione sfrutta un semplice animazione flash che viene scaricata nel momento che viene invocata la funzione “onPlayerReady” del file movie.as presente nella libreria.


private function onPlayerReady(event_p:PlayerReadyEvent):void {
Application.application.ready(true);
playerReady = true;
setMovieSize(width, height);
if(videoId && chromeless) {
youtubeMovie.loadVideoById(videoId);
}

MXML:

<?xml version=”1.0″ encoding=”utf-8″?>

<mx:WindowedApplication xmlns:mx=”http://www.adobe.com/2006/mxml” xmlns:tubeloc=”com.enefekt.tubeloc.*” width=”400” height=”600” verticalScrollPolicy=”off” horizontalScrollPolicy=”off>

<mx:Script>

<![CDATA[

import com.enefekt.tubeloc.event.PlayerReadyEvent;

public function ready(b:Boolean=true):void{

if (b)

animation.source="";

else animation.source="loading.swf";

}

]]>

</mx:Script>

<mx:VBox width=”100%” height=”100%” verticalScrollPolicy=”off” horizontalScrollPolicy=”off>

<mx:Panel width=”350” height=”280” layout=”absolute“  title=”Player” backgroundColor=”#000000” verticalScrollPolicy=”off” horizontalScrollPolicy=”off>

<tubeloc:Movie id=”tubelocMovie” width=”320” height=”240” videoId=”GJ1sZBTnbuE” chromeless=”false” x=”4” y=”0/>

<mx:SWFLoader y=”113” source=”loading.swf” width=”330” height=”204” horizontalCenter=”30” id=”animation/>

</mx:Panel>

<mx:Panel height=”250” width=”353” layout=”absolute” verticalScrollPolicy=”off” horizontalScrollPolicy=”off>

<mx:Button label=”LoadVideo” click=”if(ytID.text!=) {tubelocMovie.videoId=ytID.text; ready(false);}” x=”30” y=”34/>

<mx:TextInput id=”ytID” x=”140” y=”34/>

<mx:Image x=”213” y=”124” source=”images.jpg” width=”115” height=”86” scaleContent=”true/>

</mx:Panel>

</mx:VBox>

</mx:WindowedApplication>

<?xml version=”1.0″ encoding=”utf-8″?>
<mx:WindowedApplication xmlns:mx=”http://www.adobe.com/2006/mxml” xmlns:tubeloc=”com.enefekt.tubeloc.*” width=”400″ height=”600″ verticalScrollPolicy=”off” horizontalScrollPolicy=”off”>
<mx:Script>
<![CDATA[
import com.enefekt.tubeloc.event.PlayerReadyEvent;
public function ready(b:Boolean=true):void{
if (b)
animation.source="";
else animation.source="loading.swf";
}
]]>
</mx:Script>
<mx:VBox width=”100%” height=”100%” verticalScrollPolicy=”off” horizontalScrollPolicy=”off”>
<mx:Panel width=”350″ height=”280″ layout=”absolute”  title=”Player” backgroundColor=”#000000″ verticalScrollPolicy=”off” horizontalScrollPolicy=”off”>
<tubeloc:Movie id=”tubelocMovie” width=”320″ height=”240″ videoId=”GJ1sZBTnbuE” chromeless=”false” x=”4″ y=”0″/>
<mx:SWFLoader y=”113″ source=”loading.swf” width=”330″ height=”204″ horizontalCenter=”30″ id=”animation”/>
</mx:Panel>
<mx:Panel height=”250″ width=”353″ layout=”absolute” verticalScrollPolicy=”off” horizontalScrollPolicy=”off”>
<mx:Button label=”LoadVideo” click=”if(ytID.text!=”) {tubelocMovie.videoId=ytID.text; ready(false);}” x=”30″ y=”34″/>
<mx:TextInput id=”ytID” x=”140″ y=”34″/>
<mx:Image x=”213″ y=”124″ source=”images.jpg” width=”115″ height=”86″ scaleContent=”true”/>
</mx:Panel>
</mx:VBox>
</mx:WindowedApplication>
<?xml version=”1.0″ encoding=”utf-8″?>
<mx:WindowedApplication xmlns:mx=”http://www.adobe.com/2006/mxml” xmlns:tubeloc=”com.enefekt.tubeloc.*” width=”400″ height=”600″ verticalScrollPolicy=”off” horizontalScrollPolicy=”off”>
<mx:Script>
<![CDATA[
import com.enefekt.tubeloc.event.PlayerReadyEvent;
public function ready(b:Boolean=true):void{
if (b)
animation.source="";
else animation.source="loading.swf";
}
]]>
</mx:Script>
<mx:VBox width=”100%” height=”100%” verticalScrollPolicy=”off” horizontalScrollPolicy=”off”>
<mx:Panel width=”350″ height=”280″ layout=”absolute”  title=”Player” backgroundColor=”#000000″ verticalScrollPolicy=”off” horizontalScrollPolicy=”off”>
<tubeloc:Movie id=”tubelocMovie” width=”320″ height=”240″ videoId=”GJ1sZBTnbuE” chromeless=”false” x=”4″ y=”0″/>
<mx:SWFLoader y=”113″ source=”loading.swf” width=”330″ height=”204″ horizontalCenter=”30″ id=”animation”/>
</mx:Panel>
<mx:Panel height=”250″ width=”353″ layout=”absolute” verticalScrollPolicy=”off” horizontalScrollPolicy=”off”>
<mx:Button label=”LoadVideo” click=”if(ytID.text!=”) {tubelocMovie.videoId=ytID.text; ready(false);}” x=”30″ y=”34″/>
<mx:TextInput id=”ytID” x=”140″ y=”34″/>
<mx:Image x=”213″ y=”124″ source=”images.jpg” width=”115″ height=”86″ scaleContent=”true”/>
</mx:Panel>
</mx:VBox>
</mx:WindowedApplication>
Filed under : Actionscript 3,AIR,Flex,Flexbuilder,RIA
By admin
On 20 settembre 2010
At 15:28
Comments :Commenti disabilitati
 
 

Developing for iPad/iPhone – Add iTunes artwork for ad hoc distribution

When deploying an application using the ad hoc distribution “style”, the developer has to supply the image shown in the installed applications tab of iTunes. This file has to be a 512 by 512 PNG or JPEG image called iTunesArtwork that has to be extension-less. You have to manually delete the extension and check that the file type is no set to jpg or png for it to work and show up in iTunes, this step is vital and isn’t documented. Without the iTunesArtwork, iTunes will show a generic image for your application.
To check and change file type i used “FileType” freeware software

Filed under : Apple,MAC OSX,Sviluppo iPad/iPhone
By admin
On 11 settembre 2010
At 13:50
Comments :Commenti disabilitati
 
 

Guida alla compilazione e all’uso di OpenCV per iPhone

Vi segnalo questo link  a www.computer-vision-software.com per la compilazione di OpenCV, nota libreria per la ricognizione facciale:  guide to openCV compile on Iphone

inoltre qui potrete trovare un interessante articolo al suo utilizzo: realtime-face-detection-on-the-iphone

Filed under : Senza categoria
By admin
On 6 settembre 2010
At 11:44
Comments : 0
 
 

Programmazione iPad / iPhone – Utilizzare SQLite sui dispositivi Apple

In questo articolo vedremo come muovere i primi passi nell’utilizzo del noto motore db SQLite all’interno delle nostre applicazioni iPad / iPhone.

Nota.Per iniziare sarà necessario importare la libreria nativa “libsqlite3.dylib” al nostro progetto, e per farlo basta posizionarsi, in XCode, sul folder “Framework” e aggiungere il framework esistente denominato libsqlite3.dylib, che non è nient’altro che un link alla versione più recente della libreria SQLite presente sul vostro dispositivo.

Nell’header file del controller (partiamo sempre dal View – Based template di XCode) imortiuamo l’headerfile di  di sqlite e definiamo una variabile riferita al nostro database SQLite  e un metodo che ci restituisca il percorso del nostro db (ci riferiamo sempre alla cartella Documenti) come segue:

#import <UIKit/UIKit.h>

#import “sqlite3.h”

@interface databasesViewController : UIViewController {

sqlite3 *db;

}

-(NSString *) filePath;

@end

Nel file implementazione del controller avremo scriveremo i seguenti metodi per accedere al db:

// Recupera il percorso del file all’interno della cartella documenti

-(NSString *) filePath {

NSArray *paths = NSSearchPathForDirectoriesInDomains(

NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDir = [paths objectAtIndex:0];

return [documentsDir stringByAppendingPathComponent:@"database.sql"];

}

-(void) openDB {

//—creiamo o aprimo il database—

if (sqlite3_open([[self filePath] UTF8String], &db) != SQLITE_OK ) {

sqlite3_close(db);

NSAssert(0, @”Errore apertura DB.”);

}

}

-(void) createTableNamed:(NSString *) tableName

withField1:(NSString *) field1

withField2:(NSString *) field2 {

char *err;

NSString *sql = [NSString stringWithFormat:@"CREATE TABLE IF NOT EXISTS '%@' ('%@' TEXT PRIMARY KEY, '%@' TEXT);",tableName, field1, field2];

// Se non esiste crea la tabella indicata in tableName con i campi field1 e field2 (di tipo testo)

if (sqlite3_exec(db, [sql UTF8String], NULL, NULL, &err) != SQLITE_OK) {

sqlite3_close(db);

NSAssert(0, @”Errore nella creazione della tabella.”);

}

}

// procedura inserimento Record nella tabella “tableName” nei campi field1 e field2

-(void) insertRecordIntoTableNamed:(NSString *) tableName

withField1:(NSString *) field1

field1Value:(NSString *) field1Value

andField2:(NSString *) field2

field2Value:(NSString *) field2Value {

NSString *sql = [NSString stringWithFormat:

@"INSERT OR REPLACE INTO '%@' ('%@', '%@') VALUES ('%@','%@')",tableName, field1, field2, field1Value, field2Value];

char *err;

if (sqlite3_exec(db, [sql UTF8String], NULL, NULL, &err) != SQLITE_OK) {

sqlite3_close(db);

NSAssert(0, @”Errore Aggiornamento Tabella”);

}

}

// Procedura di recupero record dalla tabella “tableName”

-(void) getAllRowsFromTableNamed: (NSString *) tableName {

//—recuperiamo le nostre rows—

NSString *qsql = @”SELECT * FROM CONTACTS”;

sqlite3_stmt *statement;

if (sqlite3_prepare_v2( db, [qsql UTF8String], -1, &statement, nil) == SQLITE_OK) {

// Cicliamo nel loop per recuperare tutte le righe

while (sqlite3_step(statement) == SQLITE_ROW) {

char *field1 = (char *) sqlite3_column_text(statement, 0);

NSString *field1Str = [[NSString alloc] initWithUTF8String: field1];

char *field2 = (char *) sqlite3_column_text(statement, 1);

NSString *field2Str = [[NSString alloc] initWithUTF8String: field2];

NSString *str = [[NSString alloc] initWithFormat:@”%@ – %@”,field1Str, field2Str];

// Stampiano nella consolle la stringa formattata

NSLog(@”%@”,str);

// Liberiamo memoria

[field1Str release];

[field2Str release];

[str release];

}

//— Cancelliamo l’istruzione compilata SQLIte dalla memoria—

sqlite3_finalize(statement);

}

}

Ora per provare il tutto, nel delegate “viewDidLoad” del controller, chiamiamo in sequenza e analizziamo i messaggi mostrati da NSLog:

- (void)viewDidLoad {

// Apre il DB o lo crea

[self openDB];

// Crea la Tabella se non esiste

[self createTableNamed:@"Contacts" withField1:@"email" withField2:@"name"];

//effettua inserimento di 2 record

for (int i=0; i<=2; i++) {

NSString *email = [[NSString alloc] initWithFormat:@”user%d@laziomatica.com”,i];

NSString *name = [[NSString alloc] initWithFormat: @”user %d”,i];

[self insertRecordIntoTableNamed:@"Contacts" withField1:@"email" field1Value:email andField2:@"name" field2Value:name];

[email release];

[name release];

}

// Effettua il recupero dei record

[self getAllRowsFromTableNamed:@"Contacts" ];

sqlite3_close(db);

[super viewDidLoad];

}

Al fine di monitorare il comportamento delle istruzioni eseguite dalla libreria SQLite, di seguito sono riportate le codifiche dei “Result Code” definite nell’interfaccia C della libreria SQLite come riportato sul sito ufficiale http://www.sqlite.org/c3ref/c_abort.html

#define SQLITE_OK 0 /* Successful result */

#define SQLITE_ERROR 1 /* SQL error or missing database */

#define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */

#define SQLITE_PERM 3 /* Access permission denied */

#define SQLITE_ABORT 4 /* Callback routine requested an abort */

#define SQLITE_BUSY 5 /* The database file is locked */

#define SQLITE_LOCKED 6 /* A table in the database is locked */

#define SQLITE_NOMEM 7 /* A malloc() failed */

#define SQLITE_READONLY 8 /* Attempt to write a readonly database */

#define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/

#define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */

#define SQLITE_CORRUPT 11 /* The database disk image is malformed */

#define SQLITE_NOTFOUND 12 /* NOT USED. Table or record not found */

#define SQLITE_FULL 13 /* Insertion failed because database is full */

#define SQLITE_CANTOPEN 14 /* Unable to open the database file */

#define SQLITE_PROTOCOL 15 /* NOT USED. Database lock protocol error */

#define SQLITE_EMPTY 16 /* Database is empty */

#define SQLITE_SCHEMA 17 /* The database schema changed */

#define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */

#define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */

#define SQLITE_MISMATCH 20 /* Data type mismatch */

#define SQLITE_MISUSE 21 /* Library used incorrectly */

#define SQLITE_NOLFS 22 /* Uses OS features not supported on host */

#define SQLITE_AUTH 23 /* Authorization denied */

#define SQLITE_FORMAT 24 /* Auxiliary database format error */

#define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */

#define SQLITE_NOTADB 26 /* File opened that is not a database file */

#define SQLITE_ROW 100 /* sqlite3_step() has another row ready */

#define SQLITE_DONE 101 /* sqlite3_step() has finished executing */

Al prossimo articolo…..

Filed under : Senza categoria
By admin
On
At 11:11
Comments : 0
 
 

Programmazione iPad / iPhone – Copiare al primo avvio dell’app un file dall’Applicationbundle alla directory documenti del dispositivo

In molte applicazioni capita spesso di dover copiare al primo avvio dell’app un file di partenza, ad esempio un DB di partenza che successivamente verrà consultato e/o modificato, dal pacchetto dell’applicazione alla directory documenti dove l’utenti ha i privilegi necessari per utilizzarlo.
In questo snippet di codice vedremo proprio come fare:

Definiamo nell’application delegate un metodo “copiaFileDalBundleAiDocumenti”

- (void) copiaFileDalBundleAiDocumenti:(NSString *) fileName estensione:(NSString *) ext {

//— Recuperiamo il percorso della cartella Documenti—

NSArray *paths = NSSearchPathForDirectoriesInDomains(

NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

//—percorso del file che vogliamo trasferire —

NSString *filePath = [documentsDirectory stringByAppendingPathComponent:

[NSString stringWithString:fileName]];

filePath = [filePath stringByAppendingString:@"."];

filePath = [filePath stringByAppendingString:ext];

[filePath retain];

//—controlliamo se il file già esiste,

// Solo se non esiste lo copiamo NSFileManager *fileManger = [NSFileManager defaultManager];

if (![fileManger fileExistsAtPath:filePath]) {

//—percorso del file relativo al bundle—

NSString *pathToFileInBundle = [[NSBundle mainBundle] pathForResource:fileName ofType:ext];

//—copy the file in the bundle to the Documents folder—

NSError *error = nil;

//—proviamo ad effettuare la copia

bool success = [fileManger copyItemAtPath:pathToFileInBundle toPath:filePath error:&error];

if (success) {

NSLog(@”File copiato”);

}

else {

NSLog([error localizedDescription]);

}

}

}

A questo punto in fase di avvio dell’applicazione chiamiamo il nostro metodo nel delegate “applicationdidFinishLaunchingWithOptions” in questo modo:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

//—copiamo un db di partenza miodb.sql nella cartella documenti

[self copiaFileDalBundleAiDocumenti:@"miodb" estensione:@"sql"];


// Override point for customization after app launch.

[window addSubview:viewController.view];

[window makeKeyAndVisible];

return YES;

}

Filed under : Senza categoria
By admin
On 4 settembre 2010
At 13:51
Comments : 0