Audio Module

steveparks

Joined: 2005-08-29
Posts: 25
Posted: Tue, 2005-09-06 23:24

Hi

I'm brand new to Gallery, but have decided to throw myself in at the deep end and have a go at an Audio Module.

Phase 1 of the module will simply:
1. register to take control of audio MIME types
2. Upload audio files
3. Provide an inline audio player for the 3 common audio types: MP3, WMA and RM

I had a head start in that I could base the module on the Movie module in core - but being a newb I've hit a few problems, which are probably to do with my understanding of how things work in G2.

Would someone with more experience mind taking a look please, and giving me some guidance on how to get this working?

Here's where I'm at:

1. I've attached the module files to this post so you can see the code.

2. I upload them to my gallery modules folder in their audio folder.

3. If I go to gallery admin, I can see the module, install it, and activate it, with no problems.

4. Then I go to upload an audio file and I get these errors

Quote:
Warning: main(/home/httpd/vhosts/xxxxx.co.uk/httpdocs/mediastore/modules/audio/classes/interfaces/GalleryAudioItem.inc): failed to open stream: No such file or directory in /home/httpd/vhosts/xxxxx.co.uk/httpdocs/mediastore/modules/audio/classes/GalleryAudioItem.class on line 239

Warning: main(/home/httpd/vhosts/redstudios.co.uk/httpdocs/mediastore/modules/audio/classes/interfaces/GalleryAudioItem.inc): failed to open stream: No such file or directory in /home/httpd/vhosts/xxxxxx.co.uk/httpdocs/mediastore/modules/audio/classes/GalleryAudioItem.class on line 239

Warning: main(): Failed opening '/home/httpd/vhosts/xxxxxx.co.uk/httpdocs/mediastore/modules/audio/classes/interfaces/GalleryAudioItem.inc' for inclusion (include_path='.:/usr/share/pear') in /home/httpd/vhosts/xxxxxxxs.co.uk/httpdocs/mediastore/modules/audio/classes/GalleryAudioItem.class on line 239

Fatal error: Call to undefined function: setduration() in /home/httpd/vhosts/xxxxxxx.co.uk/httpdocs/mediastore/modules/audio/classes/GalleryAudioItem.class on line 125

At least this means my module has succeeded in registering itself to handle the MIME types!! But what else is wrong here?

5. I then found out about gmake (something that is new to me) so went to my modules/audio/classes directory and typed 'gmake'. This is the output:

Quote:
cd interfaces && gmake -
gmake[1]: Entering directory `/home/httpd/vhosts/xxxxx.co.uk/httpdocs/mediastore/modules/audio/classes/interfaces'
mkdir tmp
perl ../../../../lib/tools/bin/extractClassXml.pl \
--dtd=../../../../../lib/tools/dtd/GalleryClass2.0.dtd \
--stub-ok \
--out tmp/GalleryAudioItem.xml \
../GalleryAudioItem.class
if [ -f tmp/GalleryAudioItem.xml ]; then rxp -s -V tmp/GalleryAudioItem.xml; fi
/bin/sh: line 1: rxp: command not found
gmake[1]: *** [tmp/GalleryAudioItem.xml] Error 127
gmake[1]: Leaving directory `/home/httpd/vhosts/xxxx.co.uk/httpdocs/mediastore/modules/audio/classes/interfaces'
gmake: *** [all] Error 2

I'd really appreciate any help that you could give me to learn how to make this work.

Thanks
Steve

AttachmentSize
audio.zip10.25 KB
 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-09-07 00:01

@gmake:

see http://gallery.menalto.com/modules.php?op=modload&name=GalleryDocs&file=index&page=gallery2-devguide.patterns.php
you need rxp, saxon and gmake. and you need to properly set up the env variable for the saxon_jar path etc. etc.

@warning:

in module.inc
change
[/core]foreach ($regs as $entry) {
$ret = GalleryCoreApi::registerFactoryImplementation(
$entry[0], $entry[1], $entry[1],
$entry[2] == 'class' ?
sprintf('modules/audio/classes/%s.class', $entry[1]) :
sprintf('modules/audio/%s.inc', $entry[1]),
'core', $entry[3], isset($entry[4]) ? $entry[4] : 4);[/core]

to
[core]foreach ($regs as $entry) {
$ret = GalleryCoreApi::registerFactoryImplementation(
$entry[0], $entry[1], $entry[1],
$entry[2] == 'class' ?
sprintf('modules/audio/classes/%s.class', $entry[1]) :
sprintf('modules/audio/%s.inc', $entry[1]),
'audio', $entry[3], isset($entry[4]) ? $entry[4] : 4);[/core]
(changed core to audio)

 
steveparks

Joined: 2005-08-29
Posts: 25
Posted: Wed, 2005-09-07 00:12

Thanks Valiant

Is there a guide anywhere on how to obtain and install rxp, saxon and gmake please?

Also is there a way to check which of those I have already, as I seem to have gmake because gmake --help seemed to work fine.

Cheers
steve

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-09-07 00:30

yep, you already have gmake.
saxon / rxp, i don't think so.

there's no installation guide i fear.
what linux distribution are you using?

 
steveparks

Joined: 2005-08-29
Posts: 25
Posted: Wed, 2005-09-07 09:02

I'm using Red Hat Enterprise Linux 3, running under Plesk 7.5.3

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-09-07 09:42

so in redhat, you should be able to install saxon and rxp with some .rpm packages.
just a matter of finding a saxon package of saxon 6.5 (i guess we absolutely need this version, not newer) etc.

 
steveparks

Joined: 2005-08-29
Posts: 25
Posted: Wed, 2005-09-07 22:44

Hi

Thanks for all help so far.

I've installed saxon 6.5.4 and rxp.

Now I'm getting this error message when I run gmake in the classes directory of my audio module:

cd interfaces && gmake -
gmake[1]: Entering directory `/home/httpd/vhosts/xxxxxxx.co.uk/httpdocs/mediastore/modules/audio/classes/interfaces'
gmake[1]: Nothing to be done for `inc'.
gmake[1]: Leaving directory `/home/httpd/vhosts/xxxxxxxx.co.uk/httpdocs/mediastore/modules/audio/classes/interfaces'
cd GalleryStorage/DatabaseStorage/schema && gmake -
gmake[1]: Entering directory `/home/httpd/vhosts/xxxxxxxx.co.uk/httpdocs/mediastore/modules/audio/classes/GalleryStorage/DatabaseStorage/schema'
cd xml-src && gmake -w xml
gmake[2]: Entering directory `/home/httpd/vhosts/xxxxxx.co.uk/httpdocs/mediastore/modules/audio/classes/GalleryStorage/DatabaseStorage/schema/xml-src'
gmake[2]: *** No rule to make target `xml'.  Stop.
gmake[2]: Leaving directory `/home/httpd/vhosts/xxxxxxx.co.uk/httpdocs/mediastore/modules/audio/classes/GalleryStorage/DatabaseStorage/schema/xml-src'
gmake[1]: *** [all] Error 2
gmake[1]: Leaving directory `/home/httpd/vhosts/xxxxxx.co.uk/httpdocs/mediastore/modules/audio/classes/GalleryStorage/DatabaseStorage/schema'
gmake: *** [all] Error 2

 
steveparks

Joined: 2005-08-29
Posts: 25
Posted: Wed, 2005-09-07 23:26

Also is it possible perhaps for someone to run the make files on my very early stage alpha module and send them back to me? Would this work?

Then I can at least get started with uploading media and having it categorised as audio items. After this time I can then improve the module to add in more features - and learn how to use gmake properly!!

If this would work, and someone would be happy to do it, I'd be very grateful.

Thankyou for all help and advice. I'm learning slowly, but I'll get there!

cheers
steve

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-09-08 00:30

you forgot the GNUMakefile in the xml-src directory, that's why you got this error during gmake. copy it from any other module, e.g. from comments

here's your module after running gmake successfully, didn't fix anything else:
http://dev.nei.ch/audio.tar.gz

 
steveparks

Joined: 2005-08-29
Posts: 25
Posted: Thu, 2005-09-08 10:08

Hi Valiant

What a simple mistake!! Sorry.

Thanks for finding it - and thanks for the module after gmake file. I really appreciate your time in helping me learn.

My next challenge with the module is how to get it to write a metafile for each piece of audio, so that they can be streamed.
This would be written to an xml file, with the same filename as the audio items filename, but with the extension:
wax if the audio is wma
ram if the audio is rm
m3u if the audio is mp3

There would be one template for each file, and all gallery needs to do is stick the audio file's filename in at the right point in this template, then save it to disk.

So, for example. Here is the template for a simple wax metafile

<ASX version="3.0" BANNERBAR="FIXED">
<ENTRY>
<REF HREF="track.wma" />
</ENTRY>
</ASX> 

all gallery needs to do is insert the filename where it says track.wma, and then save this to disk as track.wax

It has already checked for duplicate filenames when uploading the audio file in the first pleace, so this should be straightforward.

But I don't know how to get gallery to do this - yet.

Any suggestions please?

Thanks
steve

How can I achieve this please?

 
steveparks

Joined: 2005-08-29
Posts: 25
Posted: Thu, 2005-09-08 16:30

Hi

Thanks for all your help.

I've now got gmake working, and have already made a few corrections to my module to fix a few mistakes, but there is one error I just can't trace!!!

I can now upload audio using my module, but when I come to try to view a gallery with an AudioItem in it, or view an AudioItem page, I get this error:


Warning: assert(): Assertion failed in /home/httpd/vhosts/xxxxxx.co.uk/httpdocs/mediastore/modules/core/classes/GalleryEntity.class on line 536

I've attached the module, can anyone guide me in how to fix this error please?

Thanks a lot
steve

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Fri, 2005-09-09 00:15

look at the phpdoc just above that line.. entity classes must override that method. see GalleryPhotoItem, etc for examples.

 
steveparks

Joined: 2005-08-29
Posts: 25
Posted: Fri, 2005-09-09 09:43

Hi mindless

thanks

i have this code in my 'galleryaudioitem.class' file:

    /**
     * @see GalleryEntity::itemTypeName
     */
    function itemTypeName($localized = true) {
	global $gallery;
	if ($localized) {
	    list ($ret, $core) = GalleryCoreApi::loadPlugin('module', 'core');
	    if (! $ret->isError()) {
		return array($core->translate('Audio'), $core->translate('audio'));
	    }
	}
	return array('Audio', 'audio');
    }

i thought this would cover it, but i can't find the error. Can you spot what i've done wrong please?

Thanks
Steve

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Fri, 2005-09-09 10:21

apart from the other error, which i don't look into now, you have to replace 'core' with 'audio' here. this is the second occurrence where you missed that, just want to remind you of the concept behind it:

g2 has a built in facility for translation.
each module is responsible for the translation (strings) of all strings that are used in this module.
so when you call somewhere $moduleName->translate() you always have to load your own module, 'audio', and not 'core'. also, as variable name, i wouldn't use '$core' :)

 
steveparks

Joined: 2005-08-29
Posts: 25
Posted: Fri, 2005-09-09 11:35

Ok thanks valiant

Part of my challenge here is that all the other Item modules are only in core, so i can't compare with a non-core module to learn the code.
For much of the code I'm simply adapting the Movie module, and haven't been quite sure about whether to change all references to core, or whether some are necessary because they reference a required part of the core for any Item.

Thanks for the pointer about how the translation works.

I'm learning slowly, but I'll get there in the end!!

 
steveparks

Joined: 2005-08-29
Posts: 25
Posted: Fri, 2005-09-09 18:30

Hmmmm. I just can't get this to work.

I've been looking at other modules, trying to see how they override this but it just doesn't work for me. I get the following error when i try to view the audio item, or an album with the audio item in:

Warning: assert(): Assertion failed in /home/httpd/vhosts/xxxxxx.co.uk/httpdocs/mediastore/modules/core/classes/GalleryEntity.class on line 536 

I know i've probably made a really simple mistake, but I can't work it out!

Can anyone help me out please? I'm really close to getting this audio module working!

Thanks very much
steve

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Fri, 2005-09-09 20:47

i don't have the g2 source code at hand, but generally, it's like that:
the assert(false); statements are added in functions of G2 which are meant to be overridden by classes that extend of the class where the function is defined in.

in your case, you created a GalleryAudioItem class which extend the GalleryDataItem, which extends .... which extend the GalleryEntity class.

GalleryEntity has a few functions which must be implemented / overridden by your GalleryAudioItemClass.

take a look at
modules/core/classes/GalleryEntity.class on line 536
because the assert is on that line. a few lines above 536 is the function line which tells you which function you need to define / implemente in your GalleryAudioItem class.

 
steveparks

Joined: 2005-08-29
Posts: 25
Posted: Sat, 2005-09-10 00:56

Hi Valiant

This is what it says in GalleryEntity.class

    /**
     * Return the name of this type of item.
     *
     * Subclasses must override this to provide their own type names.
     *
     * @param boolean if the name is to be translated using the current language
     * @return array string to be used by itself ("Photo")
     *               string to be used in context ("photo")
     */
    function itemTypeName($localized = true) {
	assert(false);
}

The code I've copied from GalleryMovieItemClass would seem to cover that (to my untrained eye). I've also checked GalleryAnimationItemClass and GalleryPhotoItemClass just to be sure.

I've even tried this really simple soultion as a test:

   /**
     * @see GalleryEntity::itemTypeName
     */
    /**
     * @see GalleryEntity::itemTypeName
     */
    function itemTypeName($localized = true) {
	return array('Audio', 'audio');
    }

But that doesn't work either.

Do you have any suggestions please?

Thanks for your continuing help

Steve

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Sat, 2005-09-10 01:29

yep, looks fine.
i can't believe your php doesn't work correctly.
what's your exact php version? (see /lib/supporty/phpinfo.php).

so the problem must be somewhere else.

 
steveparks

Joined: 2005-08-29
Posts: 25
Posted: Sat, 2005-09-10 02:13

I'm running PHP 4.3.11 on RHEL3 with Plesk 7.5.3, Apache2, MYSQL4

steve

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Sat, 2005-09-10 02:39

yep, should be fine. then the problem must be somewhere else in your code...

 
steveparks

Joined: 2005-08-29
Posts: 25
Posted: Sun, 2005-09-11 01:26

hmmm. I'm really struggling to find what else could be causing this error.

I know it will probably be glaringly obvious to someone with more Gallery experience, so would someone mind downloading the module from my earlier post and having a wuick look please?

I've spent hours trying different changes, but with no success.

steve

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Mon, 2005-09-12 05:32

see these 2 lines at the bottom of GalleryAudioItem.class?
}
}

wonder why you added a 2nd one there? to compensate for a missing } somewhere else... function itemTypeName is not in your class, it is inside some other function. scan up from itemTypeName to find it.

 
nospamisgoodspam

Joined: 2005-08-31
Posts: 40
Posted: Wed, 2005-09-21 02:39

steveparks, how are you going with your module??

 
steveparks

Joined: 2005-08-29
Posts: 25
Posted: Thu, 2005-09-22 07:34

I haven't had much time to work on it for a week or two - been tied up with other projects.

Here's how far I've got:

1. The audio uploads, and my module claims control of it instead of Unknown Items
2. The audio is saved to the filesystem, and the database tables are updated to include it
3. I have created a render function with instances of media players for popular file types (which work on a normal html page), but I just can't seem to get these to display in G2.

So my next challenge is to figure out how to get the players to display properly.

I can't seem to find how to attach a file in this new gallery forum, otherwise i'd attach a copy of the latest version of the module.

cheers
steve

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-09-22 09:29

you can only attach files to the first post of a topic. that's a limitation of this forum software. yep it sucks.
you can also just link to your file on your webserver.

 
steveparks

Joined: 2005-08-29
Posts: 25
Posted: Thu, 2005-09-22 22:42

hmmm...just tried editing the first post in this thread to add the latest version of the module, and it says 'invalid extension'
I'm trying to upload it as a zip file called 'audio_2005-09-22.zip'
??

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Sun, 2005-09-25 02:38

i added support for attachments in comments/replies yesterday.
i'll check now to make sure zip is an allowed extension.

 
steveparks

Joined: 2005-08-29
Posts: 25
Posted: Wed, 2005-09-28 22:31

Thanks Mindless - Drupal is great as a CMS isn't it? Very adapt-able.

Here's the audio module in its latest form. I still haven't had much time to do more work on it, so am still stuck on the rendering of the inline players. Upload seems to work fine now.

Thanks to you and the others for the help

Steve

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Tue, 2005-10-11 16:17

Even though this is work-in-progress I've added an entry at
http://codex.gallery2.org/index.php/Gallery2:User_Contributions#Modules

 
steveparks

Joined: 2005-08-29
Posts: 25
Posted: Fri, 2005-10-21 18:52

Wow! I better spend some more time getting thos to work then!

I've got to finish my next book before the end of the month though, so won't be able to get to this before early Nov.

If anyone wants to help out I'd be very grateful.

So far the upload works, the audio module takes control of audio files, and the code for inline streaming players is there but doesn't work yet.

The latest code is still the version I uploaded above.

I'll be back to working on this in Nov, but will check the forums occaisionally before that.
cheers
steve

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Fri, 2005-10-21 22:55

what kind of books do you write?
and i'd very much like to see this feature in g2. i want it to manage any kind of media files in a powerful way.
i don't have time to write the module, but feel free to ask questions.

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Sat, 2005-11-19 00:04

Well Steve,
You've taken this module a long way.
And I for one would like to see it finished - it would be a great addition to G2.
I only wish I had the experience to help you, and expedite the completion.
Happy coding :)

 
jmizz

Joined: 2005-11-17
Posts: 8
Posted: Wed, 2005-11-23 23:52

Cracking idea!!. I play have a ton of personal samples I could publish...

well done.. cant wait to see it!!! :)

 
steveparks

Joined: 2005-08-29
Posts: 25
Posted: Wed, 2005-11-30 21:59

Hi

Valiant: I write books to help people start and run a business:
http://www.amazon.co.uk/exec/obidos/search-handle-url/index=books-uk&field-author=Parks%2C%20Steve/202-1993820-0911016

all:
I've been diverted away from development of this for a while - but have been learning a lot more about PHP in the meantime to help me finish this.

watch this space! (but please be patient...i'm very much learning the ropes as I go!)

steve

 
trueshanti

Joined: 2005-11-16
Posts: 8
Posted: Thu, 2005-12-15 14:12

Hi

i need some assistance:

i disabled the audio-module in the site-administration , and it shows deactivated, nevertheless i get a lot errors :

Warning: assert(): Assertion failed in /var/data/www/gallery/modules/core/classes/GalleryEntity.class on line 536

when i try to upload via gallery-server

so my question:

how can i remove this modules entirely

thanks for reply

-c-

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-12-15 15:41

maybe you can successfully uninstall the module with a direct site admin link (if you can't access site admin anymore):

try the url from

http://codex.gallery2.org/index.php/Gallery2:faq#Images_don.27t_show_up_and_the_album_.2F_photo_links_don.27t_work.2C_what_can_I_do.3F

but change the module name to audio and change the operation from deactivate to uninstall

 
trueshanti

Joined: 2005-11-16
Posts: 8
Posted: Mon, 2005-12-19 22:00

this brings me to the result:

Fatal error: Call to undefined function: setduration() in /var/data/www/shanti.mojo.cc/gallery/modules/audio/classes/GalleryAudioItem.class on line 125

so after deinstallation there are still some calls to now unavailable libraries left ..

even removing the modules-folder doesn solve this

Quote:
Error Detail -
Error (ERROR_BAD_PATH) : Invalid path: modules/audio/classes/GalleryAudioItem.class

* in modules/core/classes/helpers/GalleryFactoryHelper_simple.class at line 205 (gallerystatus::error)
* in modules/core/classes/helpers/GalleryFactoryHelper_simple.class at line 156 (galleryfactoryhelper_simple::newinstance)
* in modules/core/classes/GalleryCoreApi.class at line 93 (galleryfactoryhelper_simple::newinstancebyhint)
* in modules/core/classes/helpers/GalleryItemHelper_medium.class at line 151 (gallerycoreapi::newfactoryinstancebyhint)
* in modules/core/classes/GalleryCoreApi.class at line 1456 (galleryitemhelper_medium::newitembymimetype)
* in modules/core/ItemAddFromServer.inc at line 409 (gallerycoreapi::newitembymimetype)
* in modules/core/ItemAdd.inc at line 411 (itemaddfromserver::loadtemplate)
* in modules/core/ItemAdmin.inc at line 147 (itemaddview::loadtemplate)
* in modules/core/classes/GalleryTheme.class at line 688 (itemadminview::loadtemplate)
* in modules/core/classes/GalleryView.class at line 285 (matrixtheme::loadtemplate)
* in main.php at line 287 (itemadminview::doloadtemplate)
* in main.php at line 87
* in main.php at line 80

at this point i cannot upload MEdia-Files via Gallery-Server-Option

no clue yet

 
planetgrey

Joined: 2005-11-29
Posts: 1
Posted: Sun, 2006-09-10 14:55

hi was this module ever completed

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Sun, 2006-09-10 16:30

nothing beyond the attachment above

 
titangen

Joined: 2006-09-14
Posts: 5
Posted: Fri, 2006-09-15 07:15

Hi,

no upgrade for gallery 2.1.2 ?

thanks in advance

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Fri, 2006-09-15 14:52

current svn / nightly snapshot does have a module called mp3audio which shows a flash based player for mp3 files.

 
wiremu

Joined: 2006-02-13
Posts: 2
Posted: Wed, 2006-11-22 04:56

Hi there,

Just wondered if you are going to working on an upgrade? Sounds like a brilliant project. Or anyone else keen to build such a module ?

Tim

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Wed, 2006-11-22 23:23

There is already an mp3Audio module in 2.2, you can get it if you are willing to try a nightly build(upgrade to 2.2svn required).

-s

 
TaceN

Joined: 2007-01-27
Posts: 1
Posted: Sat, 2007-01-27 13:15
suprsidr wrote:
There is already an mp3Audio module in 2.2, you can get it if you are willing to try a nightly build(upgrade to 2.2svn required).

-s

Where can I find this upgrade, tried to down and installed the one I found in the list of modules, but it didn't work!

Sounds really good, and I really want to use it streaming my audio files!

Thanks!