A library which adds native video support for OpenFL and HaxeFlixel.
Using libVLC, hxCodec allows to play hundreds of video codecs.
Original repository
Click here to check the roadmap
- Install the Haxelib You can install it through haxelib:
haxelib install hxCodec
You can also install it through Git for the latest updates:
haxelib git hxCodec https://github.com/polybiusproxy/hxCodec
- Add this code in
Project.xml
<haxelib name="hxCodec" if="desktop || android" />OPTIONAL: If you want debug traces in your console, add this code:
<!-- Show debug traces for hxCodec -->
<haxedef name="HXC_DEBUG_TRACE" if="debug" />-
Create a folder called
videosin yourassets/preloadfolder. -
Add this code in
Paths.hx:
inline static public function video(key:String)
{
return 'assets/videos/$key';
}- Put your video in the videos folder.
Note: hxCodec supports all the video formats VLC can play!
- Add somewhere in PlayState:
function playCutscene(name:String, atEndOfSong:Bool = false)
{
inCutscene = true;
FlxG.sound.music.stop();
var video:VideoHandler = new VideoHandler();
video.finishCallback = function()
{
if (atEndOfSong)
{
if (storyPlaylist.length <= 0)
FlxG.switchState(new StoryMenuState());
else
{
SONG = Song.loadFromJson(storyPlaylist[0].toLowerCase());
FlxG.switchState(new PlayState());
}
}
else
startCountdown();
}
video.playVideo(Paths.video(name));
}At the PlayState "create()" function:
switch (curSong.toLowerCase())
{
case 'song1':
playCutscene('song1scene.asf');
case 'song2':
playCutscene('song2scene.avi');
default:
startCountdown();
}At the PlayState "endSong()" function:
if (SONG.song.toLowerCase() == 'song1')
playCutscene('song1scene.mjpeg', true);At the PlayState "create()" function:
generateSong(SONG.songId);
switch (curSong.toLowerCase())
{
case 'song1':
playCutscene('song1scene.mp4');
default:
startCountdown();
}
At the PlayState "endSong()" function:
PlayState.SONG = Song.loadFromJson(PlayState.storyPlaylist[0], diff);
FlxG.sound.music.stop();
switch (curSong.toLowerCase())
{
case 'song1':
playCutscene('song1scene.ogg', true);
case 'song2':
playCutscene('song2scene.wav', true);
}You don't need any special instructions in order to build for Windows or MacOS.
Just pull the lime build windows / lime build mac command and the library will be building with your game.
In order to make your game work with the library, you have to install libvlc-dev and libvlccore-dev from your distro's package manager.
Example with APT:
sudo apt-get install libvlc-dev
sudo apt-get install libvlccore-dev
sudo apt-get install vlc-bin
Currently, hxCodec can load videos only from internal / external storage (not on the application storage).
In order this method for hxCodec to work on Android, you will need a library called extension-androidtools.
To install it, enter the following in a terminal:
haxelib git extension-androidtools https://github.com/MAJigsaw77/extension-androidtools.git
Next, add this into Project.xml
<haxelib name="extension-androidtools" if="android" />You can can choose whether you want to use after you inport this in your code.
import android.content.Context;-
From internal storage,
Context.getFilesDir()orContext.getCacheDir() -
From external storage,
Context.getExternalFilesDir()orContext.getExternalCacheDir().
You will also have to put the location manually in the paths and to copy that video to the respective path.
- PolybiusProxy - Creator of hxCodec.
- Jigsaw - Programmer and Android support.
- datee - Creator of HaxeVLC.
- Erizur - Linux support.
- BushTrain460615 - macOS Support.
- The contributors.