[RESOLVED]Can i load resource from .obb file directly

[RESOLVED]Can i load resource from .obb file directly
0

#1

Hi ,
i have used expansion file (.obb) in my android project, so i changed my search path like this:

 std::vector<std::string> resDirOrders;
 resDirOrders.push_back(CGameManager::Instance()->getExternalStorageDirectory()+"/Android/obb/com.example.android/main.1014001.com.example.android.obb/myassets/");
    FileUtils::getInstance()->setSearchPaths(resDirOrders);

But now i have errors :

cocos2d: SpriteFrameCache: couldn't load texture file. File not found splashscreen.pvr.ccz
: Assert failed: Invalid spriteFrameName: splashscreen.png

So i would like to know if i can load resource from .obb file directly ?

Thanks


Cocos2dx 3 and OBB on android
#2

You can’t.

There might be two options.

  1. Use non-encrypted obb file and mount it.
  2. Unzip obb file to memory at runtime if use encrypted obb.

#3

i used non-encrypted obb, but i didn’t mount it , should i mount it ?


#4

Yes.

You should mount obb if you use directly with FileUtils.
But mounted obb path is not the same as obb path.
You should obtain mounted path.

http://developer.android.com/reference/android/os/storage/StorageManager.html


#5

Thanks @hzlov, i have mounted the obb file and i got a path like this /mnt/obb/880f5ef6a6885d1b8937f9625be73850;
but how to get the final path to my assets ( myAssets folder in the .obb file)? i read that we should ignore subfolder?


#6

i have this message:

SUCCESSFULLY QUEUED
/mnt/obb/880f5ef6a6885d1b8937f9625be73850-->MOUNTED

But when i browse to this directory i find it empty !

Please help me .


#7

You may access by /mnt/obb/880f5ef6a6885d1b8937f9625be73850/myAssets/...

But mounting obb would needs some time to be mounted successfully.


#8

Thanks, but why when i browse to this directory i find it empty


#9

Did you add a permission to manifest.xml?

<manifest ...>
    ....
    <!-- Required to read and write the expansion files on shared storage -->
    <uses-permission
        android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>

#10

Did you mean browsing by another file app?

I’m not sure but it may be because of permission not to allow read by another app.


#11

Yes, i did


#12

thanks @hzlov, I used another activity which extends from android.app.Activity for checking the availability of the expansion file, if the file exist, it will mount it and call the Appactivity which extends Cocos2dxActivity, what do you think about that ?


#13

I think that is formal approach.


#14

Yes, you’re right


#15

hzlov i use non-encryped obb file and mount it …
main obb file create mac -r0 option
but OnObbStateChangeListener() call state ERR0R_INTERNAL
Obb file problem? or some different problem?


#16

I have that error too, in android 4.4.4, did you fixed it ? plz share with me