CPP


22
Oct 13

HypVideo

HypVideo is a new native extensions for OpenFL which allow to do video playback on Android & iOS.
For now it allow only to play remote video.

Setup:

HypMedias is on HaxeLib, you can install it by using:

1
haxelib install HypMedias

The project is on github too : https://github.com/hyperfiction/HypMedias

HypMedias use a dependency called “inthebox-macros”, you must install it too:

1
haxelib install inthebox-macros

Android:

On iOS there is nothing to do, but on android you need to add the following activity to your AndroidManifest:

1
2
3
4
5
6
7
<!-- HypMedias -->
<activity
   android:name="fr.hyperfiction.hypmedias.HypVideoActivity"
   android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
   android:label="HypMedias"
   android:screenOrientation="landscape"
/>

Usage:

This is really easy to use :

1
2
3
4
5
6
7
8
9
10
11
12
import fr.hyperfiction.hypmedias.HypVideo;
import fr.hyperfiction.hypmedias.HypVideo.HypVideoEvent;

var v = HypVideo.getInstance( );
v.addEventListener( HypVideoEvent.PLAYBACK_COMPLETE , _onHypVideo_event );
v.addEventListener( HypVideoEvent.PLAYBACK_ERROR , _onHypVideo_event );
v.addEventListener( HypVideoEvent.PLAYBACK_INFO , _onHypVideo_event );
v.addEventListener( HypVideoEvent.PLAYBACK_PAUSE , _onHypVideo_event );
v.addEventListener( HypVideoEvent.PLAYBACK_PLAY , _onHypVideo_event );
v.addEventListener( HypVideoEvent.PLAYBACK_SEEK , _onHypVideo_event );
v.addEventListener( HypVideoEvent.PLAYBACK_STOP , _onHypVideo_event );
v.playRemote("VIDEOURL");

5
Apr 13

HypFacebook : Facebook native extension for Haxe NME

Haxe NME goes social.

You can by now use Facebook in your Haxe NME project ( for iOS & Android targets only ).

Grab it at : https://github.com/shoebox/HypFacebook

The twitter extension ( for iOS / Android / CPP ) will be soon available too.


20
Jan 13

NativeMirror : Easier way to make JNI/CPP calls from haxe

It’s still useful to know how to make native calls from haxe manually ( for debugging by example ) but there is a quicker and easier way.
It’s stricly type, flexible and simple.
It use a simple macro you can find here : here.

All you have to do is to add it on build of yours haxe class.

1
2
3
package org.shoebox.test;
@:build(org.shoebox.utils.JNIMirror.build( )) class Test{
}

Then all you need to do is to create mirrors for the native methods.
 

Mirrors for JNI Methods

Basic example:

In the following case the JNI class name and method name are not defined.
So the macro use the same classpath classname and function name than on the haxe side.

1
2
@JNI
static public function test( s : String , i : Int ) : String {}
If the haxe method name or package is not the same on the java side:

You can customize both by adding argments to the JNI meta:

1
2
@JNI("org.shoebox.Test","TestFunc")
static public function test( s : String , i : Int ) : String {}
For non native types:

It works too for non-native type if the class exists on both side ( with the same package and class name ).
By example we are trying to get the instance of the java class Test inside haxe, the method is defined this way:

1
2
3
@JNI
static public function getInstance( ):Test{
}

 

For CPP Methods

It works the same way, but the first meta argument ( library_name ) must be always defined ( for now ).
The second meta argument ( method_name ) is optional.

1
2
@CPP("library_name","method_name")
public function test_cpp( instance : Dynamic , sTest : String , i : Int , b : Bool ) : Void {}

Hope it helps.


18
Jan 13

NME Native Extension Part 2 : Calling CPP methods from haxe

Much more easier than JNI methods, all you have to do is using the “cpp.Lib” class ( “neko.Lib” for neko ).

1
Lib.load( libName , primitiveName , argsCount );

LibName:
It’s the cpp library name ( without path and extension ).

PrimitiveName:
The name of the primitive defined in the ExternalInterface class.
In the next article of the tutorial we will take a look at how to define the primitive in the ExternalInterface class, which is the backbone of the native extension.

ArgsCount:
Obviously it’s the argument count used by the primitive.

This will return like for JNI, a function which can be call with the correct number of arguments.