airsdk / ANE-PlayAssetDelivery

Play Asset Delivery ANE
MIT License
2 stars 2 forks source link

Unable to pack assets in Play Asset Delivery #8

Closed idzdigital closed 2 years ago

idzdigital commented 2 years ago

I am using "install-time" method, but _assets.openInstallTimeAsset("path/example.txt") returns null. I have checked the aab file but did not any my data in it. Below is the link to aab file. <assetPack delivery="install-time" folder="LocalData" id="Swfs"/> https://drive.google.com/file/d/1GX400f_u_b-ckKEL-E9cQRrrH_vhyttQ/view?usp=sharing

idzdigital commented 2 years ago

@marchbold

marchbold commented 2 years ago

I haven't developed this extension so will leave it for Harman to answer

ajwfrost commented 2 years ago

So this looks like you're trying to add an asset pack called Swfs and then having files from a folder LocalData to be put inside this... but the files aren't included in the asset pack? So it's a packaging problem...

Did you include the files in the packaging command? So e.g. you should be calling something like:

adt -package -target aab .... application.xml Main.swf -C Resources . -C AssetPacks . -extdir ANE

on the assumption that the Resources folder contains things like 'AppSounds', 'AppSWFs' etc which are then packaged into the bundle at the same level as the SWF; and AssetPacks would need to contain a folder called LocalData and the files in that folder would then be redirected into the asset pack...

idzdigital commented 2 years ago

I had not added LocalData in Resources. It's working now. Thanks.

ajwfrost commented 2 years ago

Great thanks - yes not 100% clear perhaps, we can add a warning to check whether any assets were actually found/added to an asset pack to make this a little clearer!

idzdigital commented 2 years ago

I am able to load swf but I am not able to load .mp3 file. How do I load it? Can you send me a sample code for the same?

idzdigital commented 2 years ago

@ajwfrost

ajwfrost commented 2 years ago

Is this for an install-time asset? It should be the same i.e. you end up with a byte array containing the mp3 file contents. You can then pass this to Sound.loadCompressedDataFromByteArray()

idzdigital commented 2 years ago
var asset: AssetFile;
var m_pad: PlayAssetDelivery;
var m_sound: Sound;
var swfBytes: ByteArray = new ByteArray();

m_pad = new PlayAssetDelivery();
m_pad.initAssetDelivery();
asset = m_pad.openInstallTimeAsset("trial.mp3");
asset.readBytes(swfBytes);
asset.close();
m_sound = new Sound();
m_sound.loadCompressedDataFromByteArray(swfBytes, asset.bytesAvailable);
m_sound.addEventListener(Event.COMPLETE, onSoundLoaded);
function onSoundLoaded(evt: Event): void {
    m_sound.play();
}

This is the code I have added. But still I am getting the below error Asset file is not valid and cannot be read from

and the line is m_sound.loadCompressedDataFromByteArray(swfBytes, asset.bytesAvailable);

ajwfrost commented 2 years ago

You can't use the AssetFile after you've closed it... so you've got

asset.readBytes(swfBytes);
asset.close();

and then you do

m_sound.loadCompressedDataFromByteArray(swfBytes, asset.bytesAvailable);

but this last call should probably be:

m_sound.loadCompressedDataFromByteArray(swfBytes, swfBytes.length);

or similar..?

idzdigital commented 2 years ago

it worked thanks

idzdigital commented 2 years ago

I am not able to get Event.COMPLETE when loading sound. How do I do that? This is the code I have added

m_sound = new Sound();
m_sound.loadCompressedDataFromByteArray(swfBytes, swfBytes.length);
m_sound.addEventListener(Event.COMPLETE, onSoundLoaded);
idzdigital commented 2 years ago

@ajwfrost

ajwfrost commented 2 years ago

Would you normally get the Event.COMPLETE when loading data synchronously from a byte array? It looks from the documentation as if that event is only related to the load() method... can you just try playing the sound and see if it works?

idzdigital commented 2 years ago

If I use load() then I do get Event.COMPLETE. I am able to play sound from play asset. I want to know if the sound loading is done. How do I do it?

ajwfrost commented 2 years ago

load() is asynchronous, it goes off and does a network request for the file. But loadCompressedDataFromByteArray() is synchronous: immediately that function returns, the sound data will be available and can be played, and you can discard the byte array etc. So it should just work already...

idzdigital commented 2 years ago

it worked thanks