This question is answered.


Permlink Replies: 4 - Pages: 1 - Last Post: 20 Jul 23, 21:06 Last Post By: AndreWolff Threads: [ Previous | Next ]
AndreWolff

Posts: 1,116
Registered: 14-Dec-2007
How to get the number of audioClips?
Posted: 18 Jul 23, 19:47
 
  Click to reply to this thread Reply
My skin used a file slidePage.js in the output folder.
That file did contain a lot of Lightbox code, so I removed that and put the code in a new module initGallery.js in the res directory.

In file slidePage.js I used code to calculate the number of audioClips in the album. This number is required in my new module initGallery.js , but if the template file of this module is processed, the template file of slidePage.js is not yet processes, so the number of audioClips is not available while slidePage.htt is processed.

So my question is:

How can I get the number of audioClips in the current album for use in module initGallery.htt, which can not use the iteration function I use in slidePage.htt

Is there a function like
totalClips= JAlbumUtilities.countCategories(currentFolder, false).getCount(Category.audioClip);
davidekholm

Posts: 3,968
Registered: 18-Oct-2002
Re: How to get the number of audioClips?
Posted: 19 Jul 23, 20:05   in response to: AndreWolff in response to: AndreWolff
Correct
  Click to reply to this thread Reply
Try this:

int count = rootFolder
  .getDescendants()
  .parallelStream()
  .filter(ao -> ao.getAudioClip() != null)
  .count();
  
I might add an audioClip count to countCategories too, but an attached clip is technically not another category. It's an attachment to a file of some category. If I include it, it won't probably be part of the total object count.
AndreWolff

Posts: 1,116
Registered: 14-Dec-2007
Re: How to get the number of audioClips?
Posted: 20 Jul 23, 10:43   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Yes, that works perfect and solves my problem, thanks!

Just an aditional question:

If I have an album with folders and I call this in my module initGallery.htt in the res directory, do I get in that case the sum of all audioClips in all folders?
And if I cal it in index.htt do I get then only the number of audioclips in the current folder? If not, is it possible to count in that case the number of audioclips in that folder?
davidekholm

Posts: 3,968
Registered: 18-Oct-2002
Re: How to get the number of audioClips?
Posted: 20 Jul 23, 19:19   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
That code will give you the total for the whole album, no matter where you call it. To get the count for the current folder, do like this:
int count = currentFolder
  .getChildren()
  .parallelStream()
  .filter(ao -> ao.getAudioClip() != null)
  .count();

To get the count for the current folder, and its sub folders, do:
int count = currentFolder
  .getDescendants()
  .parallelStream()
  .filter(ao -> ao.getAudioClip() != null)
  .count();
AndreWolff

Posts: 1,116
Registered: 14-Dec-2007
Re: How to get the number of audioClips?
Posted: 20 Jul 23, 21:06   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Very nice, thanks!
Legend
Forum admins
Helpful Answer
Correct Answer

Point your RSS reader here for a feed of the latest messages in all forums