B4i Library [Class] XALAssets - an improved ALAssets wrapper for photo library management

JackKirk

Well-Known Member
Licensed User
Hi,

I'm in the middle of a major port B4A=>B4i that needs additional functionality to that supplied by Narek Adonts ALAssets wrapper:
https://www.b4x.com/android/forum/threads/alassets-wraps-the-native-alassets-framework-photos.65231/
- namely ability to enumerate photos in a specific album.

I have shamelessly taken Narek's code as the basis for what follows.

As usual I couldn't resist the temptation to do a major rationalization, tidy up, and documentation on it at the same time.

Photo library structure

From playing around with this it would appear that iPhone photo library is structured as follows (at least on my iPhone 5 running 10.3.3):
  • All actual physical photos (e.g. as suppled via MyALAssets.SaveBitmapToAlbum) reside in an album called [Camera Roll], regardless of what you define in Album_handle parameter of MyALAssets.SaveBitmapToAlbum.
  • If you give an Album_handle parameter to MyALAssets.SaveBitmapToAlbum that was created by MyALAssets.CreateAlbum (or manually?) then that album merely holds a pointer to the actual physical photo stored in [Camera Roll].
  • So you can have a photo in multiple albums but only have one physical copy.
Shortcomings
  • Firstly note that the ALAssets framework was deprecated some time ago in favour of PHAsset - someone with some real Objective C skills should put together a PHAsset replacement of this effort.
  • When enumerating photos all you get are photo "handles" which you can plug into various methods:
    • there is no mechanism supplied here to tie these handles back to a photos origin info - this might be possible via the metadata stuff but that is way beyond my pay grade.
    • so for any bitmaps you put into photo library you will have to maintain your own "origin info" vs "photo handle" correction "photo URL" table - possibly in a Dir...
  • For some idiot reason it seems that MyALAssets.CreateAlbum can not recreate an album with a name that has been previously used and subsequently deleted - but you can do this manually in Photo app.
I hope this is of value to someone and sincerely hope it is rapidly superceded by a PHAsset replacement.

Happy coding...

MAJOR EDIT - please read...

On implementing this in my own project I discovered that you can not in fact save "photo handles" with the B4i file system.

XALAssets2.Zip has some new features that circumvent this problem:
  • Added GetPhotoURL to create a URL from a photo "handle" (these URL are just strings and therefor can be saved/retrieved by B4i file system).
  • Added GetPhotoFromURL to recreate a photo "handle" from its URL so photo can be accessed by its "handle".
MAJOR UPDATE...

I have added XALAssets3.zip that handles videos as well as photos.

SUPERSEDED BY A PHASSETS CLASS - AT LAST!!!...

See:

https://www.b4x.com/android/forum/threads/class-photo-management-library-based-on-phasset.110812/
 

Attachments

Last edited:

wl

Well-Known Member
Licensed User
Hi,

I'm looking for an option to upload photo's AND videos from my iOS device. It seems ALAsset does support movies as well, but all code I found wraps this data in an image so I would guess I won't be able to obtain and upload videos in this way.

Do you have any idea?

Thanks
 

JackKirk

Well-Known Member
Licensed User
I've been slack - up to my eyeballs in other stuff.

I did contents of XALAssets3.zip (now in post #1) about 6 months ago but didn't take the time to wrap it and upload.

It has the video stuff I think you probably want.

The wrapping is pretty rushed (as in: I did it in last couple of minutes in response to your post) - you might like to test it and comment on any corrections you feel are necessary.

Happy coding...
 
Last edited:

wl

Well-Known Member
Licensed User
UPDATE: although the file sizes do not seem correct the files do seem correct (tried showing them with an imageviewer and a videoplyer on the iOS device), so all OK.

I have tried it, but it seems I have an issue.

- I get an object referring to a movie (item from the assets list retrieved in GetAssets)
- I use GetVideo on this asset to save it in the temp location
- I get the filesize of this file in the temp ;ocation

it seems the filesize is less than half the size of the original video.

Unfortunately I have not yet found an easy way to transfer this file to my PC to inspect it.

Tx
 
Last edited:

moster67

Expert
Licensed User

JackKirk

Well-Known Member
Licensed User
but it seems I have an issue
I have been using the XALAssets class in XALAssets3.zip for at least 6 months without problems.

it seems the filesize is less than half the size of the original video.
How do you know what the original video size is?

Unfortunately I have not yet found an easy way to transfer this file to my PC to inspect it.
Its a long time ago but I seem to recall you can do it via the Windows iTunes app.


Also, you might like to consider waiting a while, over here:

https://www.b4x.com/android/forum/t...-library-based-on-phasset.100463/#post-649789

Narek is suggesting a PHAsset based class may be imminent - fingers crossed:)

Regards...
 
Last edited:

ilan

Expert
Licensed User
hi jack, thank you very much for this class.
i try to figure out how i can select photos from album and import to a list.
but its to complicated. can you give me any advice, please?

i also dont understand why the photos are already selected if i try to load the picker? and after i select them once the picker is no more showing. is there an UNSELECT ALL method and show picker again?

i just need to load multiple images from the photo album. i use now the imedia library to do that but it can only load 1 image at once and i need to load multiple images. thank you in advance, ilan :)

btw what should i use? XAlAssets or PHAssets?
 

JackKirk

Well-Known Member
Licensed User
Last edited:

ilan

Expert
Licensed User
Suggest you analyse the simple wrapper example in the above thread to answer your remaining questions.
i really tried but there is no line that returns a bitmap or a list.
i saw the getbitmap method but how to use it is unclear for me and also how i can show each time i click a button an unselected image picker where i can select images and import them.
 
Top