-
Notifications
You must be signed in to change notification settings - Fork 2
Usage
Add your asset packs to your application descriptor
<android>
<assetPacks>
<assetPack id="my_asset_pack1" delivery="on-demand" folder="assetpack1"/>
</assetPacks>
</android>
The contents of the folder
will then be packaged into the asset pack rather than included in the main part of the App Bundle.
com.harman.extension.PlayAssetDelivery
Needs to be created and then initialized with initAssetDelivery()
(returns true
on successful initialization)
var assets:PlayAssetDelivery = new PlayAssetDelivery();
if (assets.initAssetDelivery())
{
// PlayAssetDelivery initialised
}
For an install-time asset, use openInstallTimeAsset
with the filename (including path) - you don't need to pass in the asset pack name. The return value is an instance of com.harman.extension.AssetFile
, or null
if the resource is not found.
This provides a way to access the contents of a file provided in an install-time asset pack (we need to check whether you can actually also just open it via a File/FileStream object...). AssetFile derives from IDataInput so you can get all the normal access for reading a file stream such as bytesAvailable, readBytes(), readUTFBytes(), readUnsignedInt() etc. The only functions not supported are "readObject()" and "readMultiByte()", please let us know if these would be useful.
Once you have finished with the AssetFile, please call "close()" to release the underlying reference to the asset file from Java.
var asset:AssetFile = _assets.openInstallTimeAsset( "path/example.txt" );
if (asset != null)
{
// Load some text content from the asset
var content:String = asset.readUTFBytes( asset.bytesAvailable );
asset.close();
}
For a fast-follow or on-demand asset pack, use fetchAssetPack
with the asset pack name, and getAssetPackStatus
to get the status of this (whether it's installed/ready or not). Status values are in com.harman.extension.PlayAssetStatus
.
When an asset pack download is completed (or failed) an event is dispatched from the PlayAssetDelivery instance, using PlayAssetDeliveryEvent.PLAY_ASSET_UPDATE
which provides the asset pack name and the status value being one of the enumeration values from PlayAssetStatus
.
To open an asset file from one of these asset packs, you can get the path of the asset pack (once it's installed) via getAssetPackLocation
and then resolve this using the File
object, or you can use getAssetAbsolutePath
which does the same thing. Access can then proceed with FileStream
in read-only mode.
Status codes are defined in the com.harman.extension.PlayAssetStatus
class.
public static const UNKNOWN:int = 0;
public static const PENDING:int = 1;
public static const DOWNLOADING:int = 2;
public static const TRANSFERRING:int = 3;
public static const COMPLETED:int = 4;
public static const FAILED:int = 5;
public static const CANCELED:int = 6;
public static const WAITING_FOR_WIFI:int = 7;
public static const NOT_INSTALLED:int = 8;
var asset:AssetFile = _assets.openInstallTimeAsset( "path/example.txt" );
assets.addEventListener( PlayAssetDeliveryEvent.PLAY_ASSET_UPDATE, playAssetDelivery_statusHandler );
// Init / fetch etc
function playAssetDelivery_statusHandler( event:PlayAssetDeliveryEvent ):void
{
trace( "asset pack name: " + event.assetPackName );
trace( "status: " + PlayAssetStatus.getStatus(event.status) ); // Value from PlayAssetStatus
switch (event.status)
{
case PlayAssetStatus.COMPLETED:
{
// An asset pack fetch was completed
break;
}
}
}